3D Fireworks Effect in C/C++ using sine or cosine function

前端 未结 2 2068
天命终不由人
天命终不由人 2021-01-25 05:49

I am trying to implement fireworks effect in C. I have a cube with dimensions 10x10x10. A rocket starts from the ground, and when it reaches 8th floor it explodes. Here\'s the p

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-25 06:20

    It's better to do this using an upside down parabola instead of sin/cos. At the point of explosion give each particle a random horizontal speed. This speed is constant till the particle hits the ground. You also need to give each particle a random vertical speed. this time, however, you'll add to this speed an amount proportional to -0.5*g*dt^2 (strictly speaking, this is numerically wrong, but you won't notice unless you're doing scientific analysis). Here, g is the acceleration due to gravitation and dt is the time step. That's all.

提交回复
热议问题