Jump to content
  • Advertisement

Archived

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

SimDemon

Firework Physics?

This topic is 5929 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

Well, I am in 8th grade. I saw something in my math book for fireworks. It said if a rocet traveled at 40 m./sec. then the height will be at d feet at t seconds. I think it said: d = 40t - 4.9t(squared) And it said it''s a quadratic function(We are learning them already). How would I use this formula to make my own "fireworks" in OpenGL? What I mean is, how would I use it to create a firework and increment its Y-Axis position and explode at the height of d?(distance comes from elapsed seconds, using the formula) I think this is a Math/Physics question. Maybe like this: float d=0.0; float time=0.0; time = elapsedTime(); d = (float)(40 * time - (4.9 * (time * time))); if(d >= 3.0) explode(); Also, how would I get the elapsed time, then reset it at an explosion. I hope you can help! If thispost = 0 Then GoBack() Else Read() End If

Share this post


Link to post
Share on other sites
Advertisement
What your gonna do is have an array of "particles" which are the fireworks. Then in your loop you are gonna run though this array and calculate the new X and Y cords with this formula:

X = InitalVelocity * Cos(Angle in Radians) * Time Interval + Inital Position
Y = InitalVelocity * Sin(Angle in Radians) * Time Interval + (0.5 * Gravity) * Time Interval ^ 2 + Inital Position

This is the basic projectile motion formula, Earth gravity is about 9.8. The time interval needs to be added to in every loop. Do something like:

Time Interval = Time Interval + 0.05

The Inital Velocity is pixels per second. So set it to something like 30. And your Angle in radians is a number between 0 and 6.28. To convert degrees to radians use:

Radians = Degrees * (3.14 / 180)

Make sure that you set the angle to a value for every particle before the loop. You can just set it to something random, like this:

Angle = Rnd * 6.28

That should cover it all. All of this is basicly a particle engine. If you don''t get any of this, then just e-mail me at Dildan2004@hotmail.com. I also have MSN - Dildan2004

Good luck!

I sure hope this world isn''t one big joke, because I don''t get it.

Share this post


Link to post
Share on other sites
quote:
Original post by VisualB4BigD
...calculate the new X and Y cords with this formula:

X = InitalVelocity * Cos(Angle in Radians) * Time Interval + Inital Position
Y = InitalVelocity * Sin(Angle in Radians) * Time Interval + (0.5 * Gravity) * Time Interval ^ 2 + Inital Position

This is the basic projectile motion formula, Earth gravity is about 9.8.


-9.8

Share this post


Link to post
Share on other sites
True but that''s on earth, if you use the formula I gave, it works correctly. I had a physics professor provide that, why don''t you try it before you tell me somethings not right, Just a suggestion.

Yeah.

I sure hope this world isn''t one big joke, because I don''t get it.

Share this post


Link to post
Share on other sites
Each firework spawns many particles when it explodes. Each particle begins with a random velocity. You can determine this random velocity like this:


particle.velocity.x = sin(RANDOM_ANGLE) * RANDOM_SPEED;
particle.velocity.y = cos(RANDOM_ANGLE) * RANDOM_SPEED;


Then, each frame, simply do the following:


particle.position.y += particle.velocity.y;
particle.position.x += particle.velocity.x;

particle.velocity.y -= G * deltaT;

G is a constant representing the acceleration due to gravity.

[edited by - TerranFury on April 21, 2002 3:34:16 PM]

Share this post


Link to post
Share on other sites
9.82 or -9.82 depends of which direction you say is positive for velocitiy.

Share this post


Link to post
Share on other sites
quote:
Original post by E-we
9.82 or -9.82 depends of which direction you say is positive for velocity.


And gravity.



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

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!