3d question

BlitzMax Forums/OpenGL Module/3d question

*(Posted 2012) [#1]
One thing that has always eluded me when doing these things is how to get the position of an entity after its rotated and moved, if some math guru here could explain it, it would be greatly appreciated.

Things like MoveEntity elude me as I would like to get the end position of the entity after its moved for use in another thing.

basically I want to get the end position after glTranslatef to put back into the X, Y, and Z positions of the entity

Thanks in advance :)

Last edited 2012


jkrankie(Posted 2012) [#2]
you can get the matrix from GL and use the translation bits of the array it returns to know where it is, along with rotation/scale etc.. Presumably though, you're storing your own matrices for what you're drawing? right?

Cheers
Charlie


*(Posted 2012) [#3]
Im storing the positions and rotations I just wanted to know how to get them back from OpenGL after you call glTranslatef, I havent a clue as I have never done trig or anything like that.


jkrankie(Posted 2012) [#4]
glgetfloatv(modelview_matrix, a_float[16]_array) i think. Either way, i think glGet is what you're after.

Cheers
Charlie


*(Posted 2012) [#5]
Ah thanks will look at it, anyone have any code examples ;)


col(Posted 2012) [#6]
Hey EdzUp,

I believe this should help :-

SetGraphicsDriver GLGraphicsDriver()
Graphics 800,600

' Do all model rotating and translation code here :-
glMatrixMode(GL_MODEL_VIEW)
glLoadIdentity()
glRotatef( 45.0, 0.0, 1.0, 0.0 )
glTranslatef( 1.0, 0.0, 0.0 )

Local Matrix#[16]
glGetFloatv(GL_MODELVIEW_MATRIX,Matrix)

' Final translation will be:-
' X : Matrix[12]
' Y : Matrix[13]
' Z : Matrix[14]


'Display the model matrix contents
For Local i = 0 Until 16
	Print Matrix[i]
Next


Matrix elements [12,13,14] are the X,Y,Z for your Translation that you want.

Last edited 2012


*(Posted 2012) [#7]
Thanks col thats a great help :)