View Full Version : Rotating in OpenGL
03-11-2006, 05:52 PM
This is a stupid question, but the only rotation I've ever done in OpenGL is with glRotate. The problem is, I represent orientation of my models with vectors (forward, left, up) as its local vectors of the same name. I don't represent the model as angles around the world vectors. Without having to convert my vectors to angles around (1,0,0), (0,1,0) and (0,0,1), how can I rotate my model with its vectors?
What I've tried is to get the model view matrix, multiply it by my transformation matrix (position and my up, left and forward vectors) and then set the matrix. I get strange results through this as I move the camera, the model moves around. I cannot pass in my orientation vectors into glRotate either as this does not represent rotation without an angle as a parameter.
What would be the best way to do this, sample code or a link or just whatever info you can tell me would be greatly appreciated. Thanks!
03-11-2006, 06:54 PM
I assume that you are taking modelview matrix before any part of models object->world transformation is applied to it. In that case it should work. Are you sure you are multiplying you transformation matrix with the model view matrix in correct order and that there is no unwanted transposition during matrix retrieval or set?
03-12-2006, 02:05 PM
I'm sure I'm missing something or doing it in the wrong order. My problem is that I'm trying to limit certain operations from occurring too frequently due to worries about them being slow. Maybe I don't need to worry so much.
Is there a way to take my left, up and forward vectors and apply them to the glRotate function itself?
03-12-2006, 04:16 PM
I'm sure I'm missing something or doing it in the wrong order.There are three ways to attack the problem.
1) Trying different orders and transpositions for those two matrices until you find the one that works (provided all your separate matrices are correct).
2) Eliminating individual suspects by various tests. If repated get, set (of previously geted value) and get of matrix will yeld almost same values in both gets then you have ruled out one possible transposition problem on the get/set interface. If both matrices you multiplying together have translation part at the same coordinates, you have ruled out second transposition problem and incorrect order of multiplications should remain (provided all your separate matrices are correct)
3) You can use known values to calculate by hand what individual matrices and theirs correct compositions should look like and where it differs from what you set to the OGL.
Is there a way to take my left, up and forward vectors and apply them to the glRotate function itself?I am not aware of way you can do that without having to calculate some angles from your vectors.
03-14-2006, 07:03 PM
Ok cool. Thanks for the tips. I'll take a look at the transformation stuff you mentioned above. :)
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.