The EngineManager is modified to create a new WOWEngine object, and to call its step function during the render loop to update the physics simulation. [code]
The Wow objects that are used to calculate the physics are separate from the Sandy-HX objects that display a 3D model on the screen. The PhysicsObject class is used to synchronize these two objects, so the physics calculations done by the Wow engine are reflected in the 3D scene through the positioning of the Sandy-HX objects.
The new function takes a WParticle (the base class for all physical objects) and adds it to the WOWEngine created in the EngineManager. It then constructs the underlying MeshObject class with the supplied Shape3D. [code]
The enterFrame function has been overridden to synchronize the position of the Wow physics object with the position of the Sandy-HX 3D model. You will note that the y axis is reversed in the Wow physics engine, and so the negative is supplied to the Sandy-HX model. [code]
The PlanePhysicsObject extends the PhysicsObject class to create a fixed horizontal plane that will serve as the ground for our demo. The fixed property on the WOWPlane object is set to true, which means that it will not move as a result of gravity or any collision.
Like the PlanePhysicsObject, the SpherePhysicsObject also extends the PhysicsObject class. The SpherePhysicsObject creates a sphere with a random position in a defined area. This sphere is not fixed, and so will fall with gravity and collide with other objects. After 10 seconds the SpherePhysicsObjects all reset themselves to a new random position.
The ApplicationManager creates one PlanePhysicsObject, to represent the ground, and a number of SpherePhysicsObjects to fall down and bounce around.
Check out the online demo here, and download the source code here.