Sprite maths?
BlitzMax Forums/OpenGL Module/Sprite maths?
| ||
hello! i am currently making my own ogl engine. in blitz3d, but using openGL :) my question is: how to rotate sprites? [they shouldn't face to the camera. they should be parallel to the near/far clip plane] thats what i use for the camera: glLoadIdentity glScalef cam\zoom#, cam\zoom#, 1 glRotatef cament\rx#, 1, 0, 0 glRotatef 180 - cament\ry#, 0, 1, 0 glRotatef cament\rz#, 0, 0, 1 glTranslatef cament\x#, -cament\y#, -cament\z# thats what i use for meshes glPushMatrix glTranslatef -e\x#, e\y#, e\z# glScalef e\sx#, e\sy#, e\sz# glRotatef e\rx#, 1, 0, 0 glRotatef e\ry#, 0, 1, 0 glRotatef e\rz#, 0, 0, 1 ...... glpopmatrix thank you for any help :) |
| ||
I don't know what the problem is. I do a translate to offset from the top left corner to the center of the object (or to a handle) then do a rotate. |
| ||
what do you mean by that? how would the code look like? |
| ||
For each sprite I do a glIdentity(), then a glTranslatef() with the handle of the sprite, then a glRotatef() to rotate each of the X,Y and Z directions, and that's it. |
| ||
me too, but how do i calculate the sprite rotations? sorry that i'm bothering you with this. but i just didn't get it :( |
| ||
You don't have to calculate anything Just make sure you do glMatrixMode GL_MODELVIEW (or whatever it is - might be glMatrix()) to select the modelview matrix, then do the glloadidentity() and the translates/rotates. It affects everything drawn after that point, so after you'd done the sprite, either do another sprite or reset the modelview matrix to the identity matrix with loadidentity() again. This is basic stuff - go read the OpenGL red book and blue book online. |
| ||
i know, but how do i get the angles of the sprite? rotating the sprite with [cam\pitch,cam\yaw,spr\rotation] does only work when the camera is in front. otherwise the pitch axis is flipped ;( |