### Author Topic: Max Camera Matrix to JPCT  (Read 6335 times)

#### AGP

• Posts: 1609
##### Re: Max Camera Matrix to JPCT
« Reply #30 on: September 28, 2010, 10:58:00 pm »
Quote
Which version are you using?

I had already updated it to 1.21 today to use the transformToGL() method, but I guess it was a Firefox caching thing. I see it now.

Quote
Is camera at 0,0,0?  If not, you'll need to subtract it from the converted vectors.  Also try reversing the sign of x, z, or both.

Cool, I'll try and be right back, thanks.

#### AGP

• Posts: 1609
##### Re: Max Camera Matrix to JPCT
« Reply #31 on: September 28, 2010, 11:21:56 pm »
OK, I tested all 12 possibilities for up vectors with setOrientation (12 because I tried flipping x and z as well). Nothing showed me anything. What I didn't try is flipping the x and z of setPosition, but that shouldn't be the difference between me seeing SOMETHING and nothing, right?

#### paulscode

• double
• Posts: 863
##### Re: Max Camera Matrix to JPCT
« Reply #32 on: September 29, 2010, 12:05:54 am »
That is very strange.  I can't imagine a scenario where you can see something then flipping the x and z coordinates in camera space of that thing plus the x and z values of the camera's look direction in camera space and no longer being able to see the thing - seems like that should always result in the equivalent of rotating the thing 90 degrees around its y-axis.  Obviously such a scenario exists in your case, so I guess it is just a limitation of my imagination..

#### paulscode

• double
• Posts: 863
##### Re: Max Camera Matrix to JPCT
« Reply #33 on: September 29, 2010, 01:43:59 pm »
Ok, give this a try (to see if my logic about flipping x and z in camera space to rotate the scene properly is incorrect).  Set up your scene as you did earlier where you can see the characters from looking sideways at the scene (i.e. comment out matrix thing, FOV to 45, position of camera -y/z flipped and camera.lookAt to the position of Max's camera's target).  Then call the following method:

Code: [Select]
`    public void rotateScene90( Object3D[] sceneObjects, SimpleVector lookTarget, Camera camera )    {        SimpleVector sourcePosition, targetPosition, translation;        for( int x = 0; x < sceneObjects.length; x++ )        {            // convert object's position into camera space:            sourcePosition = new SimpleVector( sceneObjects[x].getTransformedCenter() );            sourcePosition = sourcePosition.calcSub( camera.getPosition() );            sourcePosition.matMul( camera.getBack() );            // determine the new position (in camera space):            targetPosition = new SimpleVector(sourcePosition.z, sourcePosition.y, sourcePosition.x );            // convert new position into world space:            targetPosition.matMul( camera.getBack().invert3x3() );            targetPosition.add( camera.getPosition() );            // translate to the new position:            sceneObjects[x].translate( targetPosition.calcSub( sceneObjects[x].getTransformedCenter() ) );        }        // convert the look-target into camera space:        sourcePosition = new SimpleVector( lookTarget );        sourcePosition = sourcePosition.calcSub( camera.getPosition() );        sourcePosition.matMul( camera.getBack() );        // determine the new look-target (in camera space):        targetPosition = new SimpleVector(sourcePosition.z, sourcePosition.y, sourcePosition.x );        // convert the new look-target into world space:        targetPosition.matMul( camera.getBack().invert3x3() );        targetPosition.add( camera.getPosition() );        // look toward the new look-target:        SimpleVector look = targetPosition.calcSub( camera.getPosition() ).normalize();        SimpleVector up = camera.getYAxis();        up.scalarMul( -1 );  // Bug fix, shouldn't be necessary?  Try removing if scene is upside-down        camera.setOrientation( look, up );    }`
Notice the bug fix for the setOrientation issue.  Depending on the scene, the call to up.scalarMul( -1 ) may or may not be necessary (remove it if the scene winds up upside-down).