www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: paulscode on September 29, 2010, 03:45:41 am

Title: Camera space to world space?
Post by: paulscode on September 29, 2010, 03:45:41 am
What is the correct method for converting from camera space into world space?  I thought it was this:
Code: [Select]
vector.matMul( camera.getBack().invert3x3() );
vector.add( camera.getPosition() );

I am getting an unexpected result with this.  In the case where I set the camera position and orientation as:
Code: [Select]
        camera.setPosition( 0, 50, 0 );
        camera.setOrientation( new SimpleVector( 0, -1, 0 ), new SimpleVector( 0, 0, -1 ) );

Then try to convert the following vector:
Code: [Select]
SimpleVector vector = new SimpleVector( 50, 0, 0 );
vector.matMul( camera.getBack().invert3x3() );
vector.add( camera.getPosition() );

I get a resulting vector of (-50.0, 50.0, 0.0).  But shouldn't it be (50.0, 50.0, 0.0)?  Am I incorrect about what the result should be, or am I doing the conversion incorrectly?

To visualize the problem, this is the result I am expecting to see:
(http://www.paulscode.com/images/cameraSpaceProblem.gif)
Title: Re: Camera space to world space?
Post by: EgonOlsen on September 29, 2010, 08:27:45 am
Seems to be flaw in setOrientation() to me. Right now, i'm highly confused about all the coordinate system and space conversions taking place, but...actually i would expect this to be a null operation:
   
   
Code: [Select]
    camera.setOrientation( new SimpleVector( 0, 0, 1 ), new SimpleVector( 0, -1, 0 ));
   
   
 ...but the actual null operation is
   
   
Code: [Select]
    camera.setOrientation( new SimpleVector( 0, 0, 1 ), new SimpleVector( 0, 1, 0 ).normalize() );
   
   
which is correct when viewed from the rotation matrix' point of view but it's not what you would expect given jPCT's coordinate system.
   
Also, getUpVector() should return the same value that you've given the setOrientation()-method, but actually it doesn't. I'll fix this. For now, simply doing a skalarMul with -1 with the up vector should do the trick.