glMultMatrix in 0.8 question.

Started by Optus, November 06, 2003, 21:26:43

Previous topic - Next topic

Optus

Hi, this was briefly covered in another thread, but I'm still not able to get it right.  I'm working with a quake3 format MD3 loader/renderer and the way it works is you have seperate models for legs, torso, and head. Then you have tags that contain data on how they attach, and you multiply the model matrix in order to draw one after the other. So I have working 0.6 code, but can't quite get it to work in 0.8.  Here is the 0.6 code:
               // Get a pointer to the start of the 3x3 rotation matrix for the current frame
                float[] pMatrix = Math3D.t2DArray21DArray(pModel.tags[pModel.currentFrame * pModel.numOfTags + i].rotation);

                // Get a pointer to the start of the 3x3 rotation matrix for the next frame
                float[] pNextMatrix = Math3D.t2DArray21DArray(pModel.tags[pModel.nextFrame * pModel.numOfTags + i].rotation);

                // Now that we have 2 1D arrays that store the matrices, let's interpolate them

                // Convert the current and next key frame 3x3 matrix into a quaternion
                qQuat = JQuaternion.CreateFromMatrix(pMatrix);
                qNextQuat = JQuaternion.CreateFromMatrix(pNextMatrix);

                // Using spherical linear interpolation, we find the interpolated quaternion

                qInterpolatedQuat = JQuaternion.SLERP(qQuat, qNextQuat, pModel.t);


                // Here we convert the interpolated quaternion into a 4x4 matrix
                finalMatrix = JQuaternion.CreateMatrix(qInterpolatedQuat);

                // To cut out the need for 2 matrix calls, we can just slip the translation
                // into the same matrix that holds the rotation.  That is what index 12-14 holds.

                finalMatrix[12] = vPosition.X; //x
                finalMatrix[13] = vPosition.Z; //z
                finalMatrix[14] = vPosition.Y; // y

                AppContext.gl.pushMatrix();
                AppContext.gl.multMatrixf(Sys.getDirectBufferAddress(ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asFloatBuffer().put(finalMatrix)));

                DrawLink(pLink);
                AppContext.gl.popMatrix();


So far i've come up with this for 0.8, however when recursively drawing the next link, REALLY unexpected things happen like fuzzy distortion all over the window ( I cut out some of the matrix generation code for clarity, I know this is the erroneous portion):

               FloatBuffer scratch = ByteBuffer.allocateDirect(16*4).asFloatBuffer();
                scratch.put(finalMatrix);
                scratch.rewind();
                scratch.flip();
                GL.glPushMatrix();
                GL.glMultMatrixf(scratch);
                DrawLink(pLink);
                GL.glPopMatrix();

cfmdobbie

Try removing the flip().

After loading your buffer, the call to rewind sets the position to zero, then the call to flip sets the limit to the current position (zero) and the position to zero again.  So you end up with a buffer with a position and limit of zero, which can't be a good thing.

I don't know whether this is your problem, but fix it and see.  If it isn't we can try something else!
ellomynameis Charlie Dobbie.

Optus

Thanks so much for your quick reply :)  The call to flip was actually only added as a remedy, it is what I picked up as a possible solution from the other thread.  Removing the call doesn't seem to change anything :(

Optus

Ahhhh I feel very foolish now, for posting.  It's just very annoying to have code that worked perfect and have it break :)  Although, posting this thread is what brought the problem to light.  I didn't set the order of the buffer.
              FloatBuffer scratch = ByteBuffer.allocateDirect(16*4).asFloatBuffer();

went to
              FloatBuffer scratch = ByteBuffer.allocateDirect(16*4).order(ByteOrder.nativeOrder()).asFloatBuffer();


Thanks anyway  

P.S. Now all my textures are upside down! :)

kramer

If your textures are upside down you might be viewing from behind.... this has got me before, particularly with GL_FRONT_AND_BACK on

princec

It's most likely the fact that textures are loaded from memory with 0,0 being the bottom left, which automatically makes them upsidedown compared to the art program from whence they were saved.

Rectify by inverting the Y texture coordinates. Or flipping the image on the fly. Inverting the texture coordinates is of course far, far easier and cheaper.

Cas :)