This might be useful!
Hi.
I’d like to give a little something back to the OpenGL community that was so helpful to me so here my little discovery for the day. Apologies if ye already knew this, however if ye did then why didn’t ye answer my question when I posted it a while back?
Basically its regarding particle engines and a slight problem that I ran into. NeHe code works great for 2d particles engines but when you want to position the particle in 3d space the quad doesn’t always end up facing the camera if you have used rotations, gluLookAt, etc. So here is a quick method to ensure it looks straight at the camera, note this works great for sprites as well.
(I would have posted actual source but I don’t program in c so the following step by step is more translatable, in fact I prefer the following method of posting code ass its easier to follow)
Push the Matrix
glPushMatrix
Get the Matrix
glGetFloatv(GL_MODELVIEW_MATRIX, *params )
*params should point to enough memory to hold 16 single precision values
these are stored in the form
[ 0] [ 4] [ 8] [12]
[ 1] [ 5] [ 9] [13]
[ 2] [ 6] [10] [14]
[ 3] [ 7] [11] [15]
Then simply load 1 into positions 0, 5, 10
And 0 into position 1, 2, 4, 6, 8, 9
This resets the axis for this matrix
Load the matrix with glLoadMatrixf
The draw your bitmapped Quad using x and y vertices for the corners, keep z the same
Then finally pop the original matrix and everything is ready to continue as normal.
glPopMatrix
I hope I made no mistakes above but I’m sure you’ll point them out quickly enough if I did. Good Luck. And Thanks Jeff for all your great work.
um, why not just load the idenity matrix, then modify the locals? (3,7,11)? That is the same thing, and allot faster.
Then you say to keep 11 the same, so you only modify 3 &7.
I think Nate did something like this..err one of the Nates.![](smile.gif)
Then you say to keep 11 the same, so you only modify 3 &7.
I think Nate did something like this..err one of the Nates.
![](smile.gif)
Thanks Elixer for your comments, I would have replied sooner but I felt I should first test my origional idea to see if it works (I know I should have done that before ever posting but I''m better on theory than implementation, any way it does work). So regarding your post:
First let me say I have no idea if Nate did this or not, if he had I wish it came up in one of my searches but anyway...
Second. Just loading the identity matrix won''t work, that ould screw up the placing of the particles in relation to everything else. Basically if you want to position the particle in 3d space you must first preform translations then reset the axis. This means the particle will be where it should relative to everything else but will always face the camera so that the bitmap isn''t obscured, this works for all sprites.
Zadkiel
First let me say I have no idea if Nate did this or not, if he had I wish it came up in one of my searches but anyway...
Second. Just loading the identity matrix won''t work, that ould screw up the placing of the particles in relation to everything else. Basically if you want to position the particle in 3d space you must first preform translations then reset the axis. This means the particle will be where it should relative to everything else but will always face the camera so that the bitmap isn''t obscured, this works for all sprites.
Zadkiel
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement