I am looking for a way to move my scene so that when I translate forward/back/left right it moves directly up/down/left/right on the screen. Currently it does do that until I rotate (by anything other than 360...). After rotation the up/down/left/right moves in the direction of the rotation. I need it to move directly up/down/left/right on screen. I've been racking my brains trying all kinds of different matrix rotations and multiplication but I can't get it. MOST IMPORTANTLY - I need it to maintain a single rotation axis of 0,0,0 so the centre of rotation is always near the middle of the screen regardless of how far I scroll. I can easily rotate on the centre of the scene itself and have it translate how I want (translate to co-ord, rotate, translate back, go to position) but I need that axis to remain fixed. Otherwise the centre of rotation could be somewhere way off-screen.

Fig 1. Shows the starting position of the model(scene). Fig 2. The modelview is rotated 45deg. Fig 3. Decrementing the z-value causes the model to move out along z - which I do not want. Fig 4 I need the model to move straight back (between z and x).

I have tried using sin / cos rule in an attempt to translate the vertices back along the arc between the undesired position (Fig 3) and the desired one (Fig 4) but the math is off and the process is messy. I just know there has to be a clean/simple solution out there. I am coding this in Java (JOGL) and passing modelview and projection matrices to a vertex shader. Also, I am not using deprecated functions (no begin/end/glRotate etc).

Does anyone know of a matrix multiplication that will accomplish this?

To illustrate

  • \$\begingroup\$ The gist of it will be multiplying your movement either on the left or on the right of the current matrix... \$\endgroup\$ – david van brink Oct 3 '14 at 6:51
  • \$\begingroup\$ I figured out the problem. When I was translating the model i was moving on either the z plane keeping x static or vice versa. The key is to translate to both x and z vertices at the same time. Use the sin/cos function * the angle of rotation in radians. Works like a charm. \$\endgroup\$ – eric_the_animal Oct 9 '14 at 19:11

Your Answer

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

Browse other questions tagged or ask your own question.