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>
Use 'real' physics for that.
ball have parameters
a(ax,ay,az)
[m/s^2]... this is sum of all forces driving ball divided by its massv(vx,vy,vz)
[m/s]... actual speed = integration of accelerationv += a * dt
p(x,y,z)
[m]... actual position = integration of velocityp += v * dt
r
[m]m
[kg]dt
[s] ... iteration step (update time)init start
a,v
values to(0,0,0)
andp
to start positionapply gravity, friction, collision
g(gx=0,gy=-9.81,gz=0)
f2 = -(|v|^2)*c2 * (v/|v|)
... in gasf3 = -(|v|^3)*c3 * (v/|v|)
... in liquidif 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.
put it all together in some timer / updating code with
dt
intervalfor manual change of position
just set
p(x,y,z)
to new position and also can setv=(0,0,0)
to stop the ball