0
\$\begingroup\$

So, I have a rigid body class, containing a list of vertices and a 4x4 transformation matrix. At the moment, I'm applying the transformation matrix to each vertex individually, and am unable to revert the translation after rendering(multiplying the vertices by the inverse causes massive model distortion), so it just keeps stacking up, and eventually the model just violently wobbles back and forth. I understand mathematically how to accomplish the transformation, I'm just not sure where to actually DO the transformation without distorting the model. I'm using Java and LWJGL, and porting the Cyclone physics engine to Java.

\$\endgroup\$
  • 1
    \$\begingroup\$ Could you clarify, are you actually mutating the vertex data over and over instead of transforming into a copy of the vertex data? \$\endgroup\$ – Lars Viklund Jul 17 '14 at 7:48
  • \$\begingroup\$ The usual means for performing vertex transformation is through the world-view-projection matrix configuration. Ignoring view/projection in this situation, your world (sometimes called model) matrix should be used to perform transformations within the vertex shader. The original vertex data is never modified, instead each vertex is transformed(usually) as it leaves the vertex stage of the shader pipeline. \$\endgroup\$ – Evan Jul 17 '14 at 15:54
  • \$\begingroup\$ @LarsViklund At the moment, yes. Vertex data is mutated per physics step, though I think Evan solved my problem. I'll put the transform matrix in the shader. \$\endgroup\$ – stephanstross Jul 23 '14 at 4:50
0
\$\begingroup\$

Seeing as you want to keep the state of the matrix before the translation, I'd suggest using a matrixstack, this openGL tutorial explains it quite well: http://www.arcsynthesis.org/gltut/Positioning/Tut06%20Fun%20with%20Matrices.html

However, for this method I assume you perform your matrix multiplication with the vertices in GLSL. If that's not the case then you'd have to keep an original of the vertex list as well, unaltered by any translation you'd want to perform. This double management of vertices may be an issue depending on your situation, if so then instead I guess you'd have to create some sort of system that creates "undo-matrices" with each translation.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks! I'm actually following the Arcsynthesis tutorials now. The only real stumbling block is porting the C++/FreeGLUT code to java. Thankfully, someone else has uploaded the tutorials already :P \$\endgroup\$ – stephanstross Aug 4 '14 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.