LWJGLCamera - onFrameChange problem (and proposed fix)

I needed to be able to rotate the camera up or down from it's current position. To do so, I retrieve camera.getModelViewMatrix() into my own rotational matrix, then I apply the desired rotation to that matrix and then I apply that transformation to (0,0,-1) to obtain the new lookAt vector. This will work, but requires the following change to onFrameChange:





//current state

public void onFrameChange() {

        super.onFrameChange();

        frameDirty = true;

}





// the fix I think is needed:

public void onFrameChange() {

        super.onFrameChange();

        frameDirty = true;

       

        if (!isDataOnly()) {

            // set view matrix

            RendererRecord matRecord = (RendererRecord) DisplaySystem.getDisplaySystem().getCurrentContext().getRendererRecord();

            matRecord.switchMode(GL11.GL_MODELVIEW);

            GL11.glLoadIdentity();

            GLU.gluLookAt(

                location.x,

                location.y,

                location.z,

                location.x + direction.x,

                location.y + direction.y,

                location.z + direction.z,

                up.x,

                up.y,

                up.z);

   

            if ( modelView != null )

            {

                tmp_FloatBuffer.rewind();

                GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, tmp_FloatBuffer);

                tmp_FloatBuffer.rewind();

                modelView.readFloatBuffer( tmp_FloatBuffer );

            }

        }

       

}



With these changes, the camera modelView matrix is kept current, even when FOV is changed.



Stefan


Have you tried using Quaternions? If you are having trouble using quaternions directly with the camera object, you can wrap it into CameraNode.

You are right.  I can obtain the camera rotational matrix as matrix having  camera left, up and direction vectors as columns (that is actually the rotational matrix). In that case I don't really need to get the current modelView matrix from Open GL



Anyhow, I leave the issue in my first message open so please consider if that fix is needed. My point is that modelView matrix needs to be updated in onFrameChange in LWJGLCamera or it get's out of sync.



Thanks,

SStefan

My guess is you are used to manipulate OpenGL directly and having a hard time trusting jme code to do the right thing. Have faith! :wink:



onFrameChange() in LWJGLCamera sets the boolean variable frameDirty, and during apply() method having that variable true causes a call to doFrameChange() which updates the model view matrix.



apply() method is called in Renderer.draw(Spatial) method, triggering that chain of events. This happens every time you render a rootNode with your scene attached to it.

If you are not using the scenegraph and draw meshes directly, you are free to call Camera.apply() manually when needed.

Thanks for the explanation. I see now multiple ways to handle my initial task with no changes to jME. Looks this is not a bug after all.



Stefan