问题描述
我在 x3d 中创建了一个弹跳球动画.我只是很好奇如何让球在其高度达到顶峰时放慢速度,使其看起来更逼真.提前致谢.
I have created a bouncing ball animation in x3d. I am just curious how I could make the ball slow down at the peak of its height to make it look more realistic. Thank you in advance.
<X3D profile="interactive">
<Scene>
<Background skyColor='0.5 0.5 1'/>
<Transform DEF="Ball" translation="0 1 0" >
<TouchSensor DEF="Touch"/>
<Shape>
<Appearance>
<Material diffuseColor="1 0 0 "/>
</Appearance>
<Sphere radius='1'/>
</Shape>
</Transform>
<TimeTrigger DEF="Trigger"/>
<TimeSensor DEF="Clock" loop="false" cycleInterval="5" />
<PositionInterpolator DEF="Position" key="0.0 0.5 1.0" keyValue="0 1 0 0 5 0 0 1 0"/>
<ROUTE fromNode="Clock" fromField="fraction_changed" toNode="Position" toField="set_fraction"/>
<ROUTE fromNode="Position" fromField="value_changed" toNode="Ball" toField="set_translation"/>
<ROUTE fromNode="Touch" fromField="isActive" toNode="Trigger" toField="set_boolean"/>
<ROUTE fromNode="Trigger" fromField="triggerTime" toNode="Clock" toField="startTime"/>
</Scene>
推荐答案
为此使用真实"物理.
球有参数
- 加速度
a(ax,ay,az)
[m/s^2]...这是所有推动球的力的总和除以它的质量 - velocity
v(vx,vy,vz)
[m/s]...实际速度=加速度的积分v += a * dt
- position
p(x,y,z)
[m]... 实际位置=速度积分p += v * dt
- 半径
r
[m] - 质量
m
[kg] dt
[s] ... 迭代步长(更新时间)
- acceleration
a(ax,ay,az)
[m/s^2]... this is sum of all forces driving ball divided by its mass - velocity
v(vx,vy,vz)
[m/s]... actual speed = integration of accelerationv += a * dt
- position
p(x,y,z)
[m]... actual position = integration of velocityp += v * dt
- radius
r
[m] - mass
m
[kg] dt
[s] ... iteration step (update time)
init start a,v
值到 (0,0,0)
和 p
到起始位置
init start a,v
values to (0,0,0)
and p
to start position
应用重力、摩擦、碰撞
- 重力例如
g(gx=0,gy=-9.81,gz=0)
- friction
f2 = -(|v|^2)*c2 * (v/|v|)
... in gas - 摩擦
f3 = -(|v|^3)*c3 * (v/|v|)
... 在液体中
- gravity for example
g(gx=0,gy=-9.81,gz=0)
- friction
f2 = -(|v|^2)*c2 * (v/|v|)
... in gas - friction
f3 = -(|v|^3)*c3 * (v/|v|)
... in liquid
如果交叉碰撞边界前后的位置反映速度 * 碰撞系数 <=1 碰撞法线,如果无法跨越边界,您也可以反映位置.
if position before and after cross collision border reflect velocity * collision coef <=1 by impact normal also you can reflect position if crossing border is not possible.
将它们全部放在一些带有 dt
间隔的定时器/更新代码中
put it all together in some timer / updating code with dt
interval
a =g+(f2+f3+(driving force))/m
v+=a*dt
p+=v*dt
test_collisions()
redraw()
用于手动更改位置
只需设置p(x,y,z)
到新的位置,也可以设置v=(0,0,0)
来停止球
just set p(x,y,z)
to new position and also can set v=(0,0,0)
to stop the ball
这篇关于弹跳球.让它在高度高峰时减速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!