Sprite maths?

BlitzMax Forums/OpenGL Module/Sprite maths?

bytecode77(Posted 2006) [#1]
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 :)


ImaginaryHuman(Posted 2006) [#2]
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.


bytecode77(Posted 2006) [#3]
what do you mean by that?

how would the code look like?


ImaginaryHuman(Posted 2006) [#4]
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.


bytecode77(Posted 2006) [#5]
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 :(


ImaginaryHuman(Posted 2006) [#6]
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.


bytecode77(Posted 2006) [#7]
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 ;(