www.jpct.net
jPCT - a 3d engine for Java => Support => Topic started by: stormp on July 18, 2007, 12:32:13 am
-
Hi,
I'm trying to draw a line that is 25 pixels away based on a position in my 3D scene but reporject2D3D seems to be not working for me.
vertex1 = new SimpleVector(centerX, topY, minZ);
// Get the point in 3D space and convert to 2D screen space.
point1 = Interact2D.project3D2D(theWorld.getCamera(), fb, vertex1);
if(point1 != null)
{
// Add 25 to the screen X and convert back to 3D world space.
vertex2 = Interact2D.reproject2D3D(theWorld.getCamera(), fb, (int)point1.x+25, (int)point1.y, minZ);
vertex2 gives me back odd results.
Am I using this right?
Thanks for all the help thus far.
S.
-
Odd in which way? The coordinates are in camera space, not in world space. Maybe this causes the confusion? Anyway, i should document this better...
-
Odd in which way? The coordinates are in camera space, not in world space. Maybe this causes the confusion? Anyway, i should document this better...
odd as in the X and Y are in the 10000's in world space and reproject2D3D returns x=51 and y=27.
When you say camera space, does that mean distance from the cameras origin? Would I just need to add the cameras position to that then to get the world space?
Thanks so much.
S.
-
You have to apply the inverted camera matrix to the resulting vector and then apply the camera's translation (i.e. what getPosition() returns). That should transform the vector into world space.
-
thanks for your help! will give it a try.