# rotating space ship

This topic is 1426 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am not trying to troll anyone!

##### Share on other sites
To sum it up, take the position and translate by minus of it, that will send the object back to origin, then perform the rotation, and finally add the new translation to the previous position and you should be ok.

Rotation is done around the origin so if you don't translate back to it you are rotating around which a 45 degrees will get you 1/4 of the screen up.

It is like if every object would rotate at the end of a stick that is joint at the origin, if there is no stick, you are at origin you rotate on yourself.

##### Share on other sites

Hi phil. At it again?

##### Share on other sites

well if anyone cares I am reading a book on linear algebra.

##### Share on other sites

Let's not bring Quaternions into this. Even less any kind of manual vertex transformation. In almost half a year, despite several posts saying to do so, he apparently never switched the order of rotation and translation.

Unless the matrix stack is already screwed up, there is also absolutely no point in moving anything back and forth before/after rotating. Nothing but the view transformation should have been done yet. The model transformation is apparently NOT in addition to any previous model transformations. Why trying to "undo" a translation that isn't even part of the transformation matrix yet? Translating by the negative position, rotating and translating by the positive position would result in exactly the effect one wants to prevent:

glTranslate(-position) // Now we are in the opposite position we want to be

glRotate()                   // Now our orientation is correct, but we're still in the wrong place AND all our axes have just been rotated, affecting all future translations

glTranslate(position)  // Now we are... somewhere, because this was NOT the opposite of the first translation (axes are different)

Just embrace OpenGL's "localness", stop thinking in "map origins", "north" and "west" and only worry about your objects current position, "forward" and "right". Suddenly OpenGL will be absolutely and completely straight forward. Translate, rotate, done.

##### Share on other sites

If hackin' around the same piece of code never gives the expected result, it's probably time to look somewhere else. Even correct code will output crap if the input is crap.