Game Development Reference
In-Depth Information
If you notice, the physics update loop is completely decoupled from the render
update. The physics simulation update method modifies all rigid body properties.
It detects and responds to collision, like the sphere's properties in our case, such as
position, orientation, and velocity, are updated after every system.integrate()
function call. In our render call, we update our geometries' location and orientation
using the rigid bodies' properties.
Implementing forces, impulse, and
collision detection
JigLibJS offers functions to add force and apply impulse to a rigid body. Let's walk
through the list of available functions and how they work:
addBodyForce=function(f, p)
f: [x,y,z] magnitude of force along three axes.
p:[x,y,z] position of force
addWorldForce=function(f, p)
f: [x,y,z] magnitude of force along three axes.
p:[x,y,z] position of force
addWorldTorque=function(t)
t: [x,y,z] magnitude of torque along three axes.
addBodyTorque=function(t)
t: [x,y,z] magnitude of torque along three axes.
applyWorldImpulse=function(impulse, pos)
impulse: [x,y,z] magnitude of impulse(mass*velocity) along three
axes.
pos:[x,y,z] position of force
applyBodyWorldImpulse=function(impulse, delta)
impulse: [x,y,z] magnitude of impulse(mass*velocity) along three
axes.
pos:[x,y,z] position of force
We can apply "body force", "world force", "body torque", and "world torque" in
JigLibJS. The only difference between applying the addBodyForce and addWorldForce
functions is the coordinate system used for the force direction. The addBodyForce
function applies the force based on the body's coordinates. So, if we apply a force in
the forward direction, the force is directly forward from the orientation that the body
is currently facing. If you want absolute coordinates, you should apply the force using
the addWorldForce function. The force only affects the body that you apply it to but
the coordinate system is that of the world. The direction of the force is independent of
the direction in which the body is facing. The same is true for torques.
 
Search WWH ::




Custom Search