Author Topic: Multiple screen size issue  (Read 1849 times)

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Multiple screen size issue
« on: January 29, 2013, 04:28:04 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Multiple screen size issue
« Reply #1 on: January 29, 2013, 10:06:34 pm »
Quote
I 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?

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Multiple screen size issue
« Reply #2 on: January 30, 2013, 05:45:42 pm »
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:

Code: [Select]
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Multiple screen size issue
« Reply #3 on: January 30, 2013, 07:58:09 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.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Multiple screen size issue
« Reply #4 on: January 31, 2013, 05:49:05 pm »
Hi thanks for the improved library... It does help alot ;) Unfortunately, I still get the same issue..

Here's the code:
Code: [Select]
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]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Multiple screen size issue
« Reply #5 on: January 31, 2013, 05:52:46 pm »
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.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Multiple screen size issue
« Reply #6 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? Sorry for all the troubles.. Still new in graphic field

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Multiple screen size issue
« Reply #7 on: January 31, 2013, 08:09:54 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.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Multiple screen size issue
« Reply #8 on: February 03, 2013, 05:15:36 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Multiple screen size issue
« Reply #9 on: February 03, 2013, 08:48:42 pm »
... do I calculate the scale factor based on screen size too?
Which scale factor?

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Multiple screen size issue
« Reply #10 on: February 05, 2013, 10:08:00 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Multiple screen size issue
« Reply #11 on: February 05, 2013, 10:32:10 am »
No, you don't have to scale. No 3d space (object/world/camera) cares about the screen resolution.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Multiple screen size issue
« Reply #12 on: February 05, 2013, 03:15:46 pm »
Ok. Thanks alot for the help. Appreciate it.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Multiple screen size issue
« Reply #13 on: February 06, 2013, 01:23:50 pm »
Attachments only~

[attachment deleted by admin]