c++ - Rotate Over Own Axis -
I am trying to build a car and I am starting with a polygon. The physics of the car is done very much, but when the car is steering, it is not facing the right position.
Then I glRotated (_angle, 0, 0, 1) using GLRatated; Where _angle degree is the car's angle, but it does not rotate with its axis.
How can I fix this?
The code is here:
zero car :: draw () {vector 2D minutes = _position - _size / 2.0; Vector 2D max = _position + _size / 2.0; GlColor3d (0.8, 0, 0); GlLoadIdentity (); Glotched (_gal, 0, 0, 1); GlLineWidth (1.5); GlBegin (GL_POLYGON); GlVertex3d (min [0], min [1], 0); GlVertex3d (maximum [0], min [1], 0); GlVertex3d (maximum [0], max [1], 0); GlVertex3d (minimum [0], maximum [1], 0); GlEnd (); GlPopMatrix (); } Thanks.
glRotate * Rotate around the origin You can translate back to original, rotate and then You can translate from but you probably do not want to add _position to yourself: zero car :: draw () {Vector2d min = - _size / 2.0.0; Vector 2d max = + _size / 2.0; GlColor3d (0.8, 0, 0); GlLoadIdentity (); GlTranslated (_position [0], _position [1], 0); Glotched (_gal, 0, 0, 1); GlLineWidth (1.5); GlBegin (GL_POLYGON); GlVertex3d (min [0], min [1], 0); GlVertex3d (maximum [0], min [1], 0); GlVertex3d (maximum [0], max [1], 0); GlVertex3d (minimum [0], maximum [1], 0); GlEnd (); GlPopMatrix (); } It is only in the form of a translation of the original, originally translated primarily with the beginning of the object, except that also do not forget that OpenGL, every graphic Like the library, the matrix prepares you so that you can do the most local work at the last, even if you describe the total transformation in the abstract.
Comments
Post a Comment