Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

PapaJosh

Objects and Particles Systems (yes...again)

This topic is 6278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know questions pertaining to particle systems are pretty common in this forum, but I have yet to find and answer to my particular situation. Here''s what''s happening: My rendering consists of drawing 2 ''objects'', a rocket and a particle system (as the engine effect). Currently, this is how I animate the rocket and draw the particle system... glTranslatef (nXValue, nYValue, nZValue); glRotatef ((GLfloat) nAngle2, 0.0f, 1.0f, 0.0f); glRotatef ((GLfloat) nAngle, 0.0f, 0.0f, 1.0f); glTranslatef (0.0f, 1.0f, 0.0f); glRotatef ((GLfloat) 90, 0.0f, 0.0f, 1.0f); glRotatef ((GLfloat) nAngle2, 0.0f, 1.0f, 0.0f); (this causes the rocket to "fly" around the screen) ... Render Rocket ... glTranslatef (0.0f, -0.55f, 0.0f); glRotatef ((GLfloat) -nAngle2, 0.0f, 1.0f, 0.0f); glRotatef ((GLfloat) -90, 0.0f, 0.0f, 1.0f); glRotatef ((GLfloat) -nAngle, 0.0f, 0.0f, 1.0f); glRotatef ((GLfloat) -nAngle2, 0.0f, 1.0f, 0.0f); (this renders the particle engine at the bottom of the rocket, and keeps the 2D textures facing the camera) ... Generate particle system ... This works well except for one small problem...All of the particles are being translated along with the rocket (instead of just flying off on their own). I thought the easiest way to prevent the particle system from being rotated along with the rocket would be to simply convert the rotations and translations into one set of XYZ coordinates and render the particle system there using one glTranslatef (actually, just render any NEW particles at the location of the rocket engine). Unfortunately, I have no idea how to accomplish this. I''m sure this has been done by other people, so if anyone has suggestions, or links to tutorials that might help me figure this out, I''d greatly appreciate it! "It''''s better to be thought of as insane than to eat your next door neighboors and remove all doubt".

Share this post


Link to post
Share on other sites
Advertisement
Hi

do you want the particles to remain in a fixed position, while the rocket moves away? Or do you want the particles to move in the opposite direction to the rocket - which would give the impression of thrust.

if you only want them to remain in a constant position, then try the following ...

1. assume you want 100 particles to be on screen at a time
2. assume each particle has a life of one second
3. use an array of particles[100], and store XYZ in it
4. every 100th of a second draw the next particle in the array
5. when the particle has decayed, you can re-use it for a new particle!

Regards

Share this post


Link to post
Share on other sites
Your problem is how you''re conceptualizing your particles. Right now your particles are "children" of your rocket -- where ever the rocket goes or turns, so do the particles. Really, they should both be children of the world which means you need a little bit more framework to get things going in the right direction.

You should set up some sort of data structure to "create" particles in (array or linked list) and give them coordinates in true world space rather than relative to the rocket. This would mean that you need to do a little math to position them correctly at the rocket''s tail, but it shouldn''t be too hard -- a few sins/cos''s based on the rocket''s orientation (hint, you could give them each the rocket''s position at the time of birth just to get things working before you add any offsets). A little more math gives you the initial velocity of the particles (away from the rocket) -- more sin/cos. You''d draw these particles by themselves, not in the rocket''s space like your doing now.

When drawing completely independent of the rocket, you''ll run into the problem of orienting the particles to face the camera. One word: Billboarding. There was a recent question here regarding this technique that should be your answer.

It may seem like a lot of work for such a simple problem, but really it''s not that difficult and will give you a much better idea of how things ought to relate in a 3d scene -- some things should be children, but a trail of particles isn''t one.

Hope this helps.

Share this post


Link to post
Share on other sites
Thanks for the input, guys... This is exactly as I thought, and after retrieving trigonometry from the bowls of my memory, I think I can pretty easily step through the process of translating the rotations and translations into actual XYZ coordinates. I was hoping there''d be an easy way just to relate the rocket to the origin, but it looks like I have to do the math. I don''t think billboarding is going to be a problem now...

Another question, however. I''ve read a lot about using matrices to handle transforming different objects. This sounds very useful, but I have no idea how to go about doing this. Are there any good tutorials that anyone could recommend?

"It''''s better to be thought of as insane than to eat your next door neighboors and remove all doubt".

Share this post


Link to post
Share on other sites
openGL does all the matrix math for you -- you just need to realize that it''s going on and you''ll be okay. Unless you''re doing something really complicated, you should be able to discern your particle starting positions without resorting to matrix multiplications. If you absolutely HAVE to use matrices, just about all computer graphics books have chapters about them. There are 3 or 4 standard books that everybody should have at least one of if they''re doing graphics. It might not mean a whole lot to you as far as implementing the theories yourself, but if you understand the underlying principals, it will help you immensely.

In openGL you can grab the current matrix. So you could, after doing all the transformations you want on your rocket AND any additional translations to place the rocket fire, grab the current matrix and store it someplace -- don''t draw the rocket fire at this point, tho. Then simply grab the right numbers from your stored matrix and call those the start position of each particle for that frame. The "positional" portion of a 4x4 matrix from openGL happens to be the 13th, 14th and 15th (out of 16) index. So if you assign x=matrix[12], y=matrix[13], z=matrix[14] you''ll get your starting position. I think.

Share this post


Link to post
Share on other sites
Ok, barring any matrix stuff, this is what I''ve gotten so far...

y=sin(nAngle);
a=cos(nAngle);
x=a*sin(nAngle2);
z=a*cos(nAngle2);


and that gives me the XYZ coordinates for the center of the rocket. Now this is where I run into problems. The tail of the rocket (where I render the engine effect), is translated -.55 down the tail of the rocket (in relationship to the rocket, -.55 down the Y axis). I can''t, for the life of me, figure out the math to give me the coordinates of the engine...

Any recommendations?

"It''''s better to be thought of as insane than to eat your next door neighboors and remove all doubt".

Share this post


Link to post
Share on other sites
What are Angle and Angle2? X & Y rotations? if so, then your -.55 offset is a multiplier.

particle->x = rocket->x + x * -.55;
particle->y = rocket->y + y * -.55;
particle->z = rocket->z + z * -.55;

caveat: I''m not sure that the x,y,z''s you get are aligned properly for your y-axis rocket... You may need to swap some of your x,y,z''s to get things lined up right...

Also, I notice that there''s a Translate of 1 unit in the Y-Axis during the drawing phase. That might come back to haunt you. Make sure you know why you''re doing that.

Share this post


Link to post
Share on other sites
Thanks for all your help Miles, I decided to go with your previous recommendation and used the matrix to find the coordinates to create my particles at. This gives the effect that I was looking for. Are there any books that you''d recommend for learning more about what the matrix stores and how all of that matrix stuff works. This seems to really be where I should be looking. I understand how the matrix is working in my program, but I''d be interested in finding out what else can be done with the matrices...

"It''''s better to be thought of as insane than to eat your next door neighboors and remove all doubt".

Share this post


Link to post
Share on other sites
"Computer Graphics Principals and Practice" by Foley, van Dam, Feiner and Highes is good. There are a couple other classics that have really dull names, but they all cover the same stuff, generally. These books will teach you how the pieces fit together, but maybe not some of the "tricks" of how to get things done. For those, I would look for some of the Graphics Gems or Game Gems series. Lots of useful, highly specific code snipets for some of the more common programming problems.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!