Using project3D2D & reproject2D3D

Started by stormp, July 18, 2007, 12:32:13 AM

Previous topic - Next topic

stormp

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.

EgonOlsen

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...

stormp

Quote from: EgonOlsen on July 18, 2007, 08:53:34 AM
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.

EgonOlsen

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.

stormp

thanks for your help! will give it a try.