3D烟花影响C / C ++采用正弦或余弦函数 [英] 3D Fireworks Effect in C/C++ using sine or cosine function
问题描述
我想实现的焰火效果C.我有尺寸10x10x10的立方体。火箭从地面开始,当它到达八楼它爆炸。下面是我不能做点 - 爆炸。我怎样才能实现这个用正弦或余弦函数?
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 point I cannot do - the explosion. How can I implement this using sine or cosine function?
所以在点(5,0,7)//(X,Y,Z)//火箭进入空气中的
so in point(5,0,7) //(x,y,z)// a rocket goes in the air
for (j=0; j<9; j++) {
setpoint(x, y, j);
delay(100);
clean(); //clears everything
}
下面来点,使爆炸。这可怎么实现?它可以在随机位置神采奕奕了。先谢谢了。
Here comes the point to make the explosion. How this can be achieved? It can sparkle in random positions, too. Thanks in advance.
推荐答案
这是更好地做到这一点使用一个倒置的抛物线,而不是正弦/余弦。在爆炸点给每个粒子一个随机的水平速度。这个速度是恒定直到粒子撞击地面。你还需要给每个粒子随机垂直速度。这一次,但是,你的比例添加量,以这样的速度,以 -0.5 * G * DT ^ 2
(严格地说,这是错误的数字,但你赢了不会注意到除非你做科学的分析)。在这里,先按g
是加速度由于重力和 DT
的时间步长。这就是全部。
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.
这篇关于3D烟花影响C / C ++采用正弦或余弦函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!