Multiple screen size issue

Started by kkl, January 29, 2013, 04:28:04 PM

Previous topic - Next topic

kkl

Hi I tried to put 3D object in a fixed location (say the bottom of the screen), but the object's location appears to be different in different devices which has different screen size and density. I tried using reproject2D3D or reproject2D3DWS to put objects in place, but no luck for that. I guess you are using perspective view instead of frustum. Is there any way to sort it out?

EgonOlsen

QuoteI guess you are using perspective view instead of frustum.
I've no idea what you mean with that statement... ??? Anyway, what jPCT-AE does by default is to keep the horizontal fov at the value that has being set in the Camera and adjust the vertical fov accordingly to avoid distortions at any resolutions. That's why your objects' positions change related to the top and bottom border of the screen. If you really want to, you should be able to use reproject2D3DWS to compensate for this...what exactly hasn't worked out for you when trying this?

kkl

Sorry for the confusion. What I meant was that, by guessing, JPCT is using gluPerspective (uses FOV) for camera view instead of glFrustum. I have experience in using glFrustum, but I haven't tried the one with FOV before. Since the vertical FOV is adjusted automatically, perhaps that is the cause of incorrect position?

I tried reproject2D3DWS to place object at fixed location, by doing the following:


SimpleVector tempVec = Interact2D.reproject2D3DWS(camera, buffer, x, y).normalize();
float ratio = tempVec.z / 50f;
float vx = tempVec.x / ratio;
float vy = tempVec.y / ratio;
float vz = tempVec.z / ratio;
SimpleVector v3 = new SimpleVector(vx, vy, vz);
object.translate(v3.x, v3.y, 0);

The reason I divide the 50f is that I set the camera move out for 50f from origin. I use the normalized vector to find coordinates at the origin along the vector from the camera. In S2, the object is properly aligned at the bottom of the screen, but when I put it in S3 which has bigger screen, the object hanged in the middle and does not align to the bottom.

Am I doing it right or I missed anything?

EgonOlsen

Quote from: kkl on January 30, 2013, 05:45:42 PM
Am I doing it right or I missed anything?
You divide the z-component of a normalized vector by 50, divide all vector components by this value, which actually means that you multiply them by 50 and divide by z...including z...then you create the new vector from the result and do a translation that ignores the z-value. That might all be very clever, but i have no idea what it is supposed to do... ;)
I think what you actually want is a Interact2D.reproject2D3DWS(...)-method that takes an additional z-component. And this jar will provide you with that: http://jpct.de/download/beta/jpct_ae.jar

Try to use the depth of the object (50) as z-component and x/y as the 2D coordinates as before and see if that solves your problem.

kkl

Hi thanks for the improved library... It does help alot ;) Unfortunately, I still get the same issue..

Here's the code:

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50f);
cam.lookAt(new SimpleVector(0, 0, 0));

SimpleVector v3 = Interact2D.reproject2D3DWS(world.getCamera(), frame, 200, 650, 50f);
object.translate(v3.x, v3.y, 0);


[attachment deleted by admin]

EgonOlsen

Of course you do. You are still using fixed values for x and y. You have to adjust them to match the actual resolution of the device.

kkl

I thought the reproject2D3DWS handles all the screen size n resolution issue? How should I adjust the fixed x and y? Sorry for all the troubles.. Still new in graphic field

EgonOlsen

Quote from: kkl on January 31, 2013, 05:59:24 PM
I thought the reproject2D3DWS handles all the screen size n resolution issue? How should I adjust the fixed x and y?
No, it doesn't. How should it? It's supposed to be used to map a 2d coordinate from the device's screen into 3d for determining the position of a touch event and things like this. You can get the proper values for width and height from the FrameBuffer and then have to adjust your xy-values accordingly.

kkl

Okay... I got it by using ratio of the screen size~ Thanx alot... Just wondering, if I have to calculate the location of the screen by myself, do I calculate the scale factor based on screen size too?

EgonOlsen

Quote from: kkl on February 03, 2013, 05:15:36 PM
... do I calculate the scale factor based on screen size too?
Which scale factor?

kkl

Scale factor for objects... I tried different devices, it seems like it scales correctly. Just need to double confirm if I need to calculate object scale factor by different screen size.

EgonOlsen

No, you don't have to scale. No 3d space (object/world/camera) cares about the screen resolution.

kkl

Ok. Thanks alot for the help. Appreciate it.

kkl

Attachments only~

[attachment deleted by admin]