Log in or register to post comments

Drag an AR Object on different devices

November 4, 2014 - 1:42am #5

Hello there,

I'm using your article in the Dev Guide to move AR objects with my finger and it works well but I have a little doubt.

https://developer.vuforia.com/resources/dev-guide/unity-drag-ar-object-screen-your-finger

I'm testing this with 5 different devices (iPhone 4S, iPad3, iPhone 6, HTC One M7 and Samsung Galaxy S4)

Working with iOS all seems to go really good and the picked object moves softly and "follows" the finger.

The problem comes when I use the same sample on the Android devices, as the picked object moves correctly but slower than the finger.

I've been checking unity3d and this forum and I can't figure how to normalize this movement.

Is this because of the different screen resolutions? (S4 and M7 are 1920x1080, iPad is 2048x1536, iPhone 6 is 1334x750 and iPhone 4S is 960x640)

In the example I see that you get the half screen:

 float halfScreenWidth = 0.5f * Screen.width;
 float halfScreenHeight = 0.5f * Screen.height;
      
 float dx = screenDelta.x / halfScreenWidth;
 float dy = screenDelta.y / halfScreenHeight;

I figured out that if I get a 10% of the screen instead of the 50% on my android device it seems to work much softer but I haven't found a solution to fit on all the cases.

Could you please help me?

Thanks a lot.

Regards,
Bryan.

Drag an AR Object on different devices

November 5, 2014 - 7:42am #4

I don't have many Android devices, well just a Nexus 4 really, and have found the draging slower on Android too.

I got a post back saying that I need to apply + Time.DeltaTime to the calculation of movement in either the Update or FixedUpate methods to remedy it. 

Have not had a chance yet, but might help you?

 

Drag an AR Object on different devices

November 5, 2014 - 7:58am #3

Hi,

one thing you may want to try is to compute the camera FOV (field of view) by extracting it from the camera projection matrix,

i.e, instead of using 

float fovRad = Camera.main.fieldOfView * Mathf.Deg2Rad;

you could use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Matrix4x4 mat = Camera.main.projectionMatrix;
 
float a = mat[0];
float b = mat[5];
float c = mat[10];
float d = mat[14];
 
float aspect_ratio = b / a;
 
float k = (c - 1.0f) / (c + 1.0f);
float clip_min = (d * (1.0f - k)) / (2.0f * k);
float clip_max = k * clip_min;
 
float fovRad = 2.0f * (float)Math.Atan(1.0f / b);
 

Note: in order to get the math functions to work you need to add "using System;" to the start of your script.

 

Also, a more accurate version would create 2 variable "motionScale", one for horizontal fov and one using vertical fov.

 

Drag an AR Object on different devices

November 7, 2014 - 3:41am #2

Hello,

AlessandroB wrote:

you could use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Matrix4x4 mat = Camera.main.projectionMatrix;
 
float a = mat[0];
float b = mat[5];
float c = mat[10];
float d = mat[14];
 
float aspect_ratio = b / a;
 
float k = (c - 1.0f) / (c + 1.0f);
float clip_min = (d * (1.0f - k)) / (2.0f * k);
float clip_max = k * clip_min;
 
float fovRad = 2.0f * (float)Math.Atan(1.0f / b);
 

I tried this but it still move "slow" on my android devices.

I've found a good solution to normalize that works pretty well.

elpuerco63 wrote:

I got a post back saying that I need to apply + Time.DeltaTime to the calculation of movement in either the Update or FixedUpate methods to remedy it. 

As elpuerco63 says, the way to make it work is using deltaTime.

I added the following function

	public Vector2 FixTouchDelta(Touch t)
	{
		float dt = Time.deltaTime / t.deltaTime;
		if (float.IsNaN(dt) || float.IsInfinity(dt))
			dt = 1.0f;
		return t.deltaPosition * dt;
	}

and then simply replaced this line

Vector2 screenDelta = touch.deltaPosition;

to this

Vector2 screenDelta = FixTouchDelta(touch);

Hope this help.

Thanks a lot for your answers!

Drag an AR Object on different devices

November 7, 2014 - 4:16am #1

Oh, I see: so, basically you're amplyfing the touch.deltaPosition by a time scaling factor Time.deltaTime / t.deltaTime.

Interesting.

Thanks for sharing the solution !

 

Log in or register to post comments