Author Topic: How get world view size?  (Read 933 times)

Offline Eloy7

  • byte
  • *
  • Posts: 3
    • View Profile
How get world view size?
« on: October 29, 2012, 01:16:31 pm »
Hello,
    how get world view maxX,maxY.

I write menu on 3D.
Now i have different position of Object3D on different devices (which have different resolution)
I have got right maxX but wrong maxY


Here is the code, to calculate maxX and maxY:

Camera mCamera=new Camera();
mCamera.setPosition(new SimplyVector(0,0,5));
mCamera.setOrientation(new SimplyVector(0,0,-1),new SimplyVector(0,1,0));

double fov=mCamera.getFOV()/2;
double tg=(double)(Math.tan(fov)*(double)5); //5 is camera distance

double maxX=tg;
double maxY=(height/width)*maxX;


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12035
    • View Profile
    • http://www.jpct.net
Re: How get world view size?
« Reply #1 on: October 29, 2012, 02:20:21 pm »
Looks fine to me at first glance...try to cast width and height into double to ensure that the operation isn't done with integers.

Offline Eloy7

  • byte
  • *
  • Posts: 3
    • View Profile
Re: How get world view size?
« Reply #2 on: October 29, 2012, 02:57:15 pm »
Ok, I had fix that, but it incorrect too.

double maxY=((double)height/(double)width)*maxX;

Object which have size 1f x 1f, when placed on the scene in coordinate (maxX-1, maxY-1) is not attached to right-up corner on the screen.
And when I change camera distance to another value (for example 6f), the gap between this object and the screen is getting smaller and object can be out of screen.
« Last Edit: October 29, 2012, 03:07:24 pm by Eloy7 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12035
    • View Profile
    • http://www.jpct.net
Re: How get world view size?
« Reply #3 on: October 29, 2012, 07:44:50 pm »
Something is missing then and it won't work that way once the camera rotates anyway. Why don't you use the methods that the engine offers for this?:

http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Interact2D.html#reproject2D3D(com.threed.jpct.Camera, com.threed.jpct.FrameBuffer, int, int, float)