Computer Graphics and Animation

Cloth simulation and Physics-Engine based simulation!

INTRODUCTION
I implemented a constraint based cloth simulation on a browser. This post also describes a Physics-Engine based simulation which involved collision dynamics.

TASK 1: CONSTRAINT BASED CLOTH SIMULATION

OBJECTIVE
Create constraint based cloth and investigate its behavior.

VIDEO OF THE ANIMATION
Here it is.

TASK 2: RIGID BODY MASS COLLISION DYNAMICS SIMULATION USING jMONKEYENGINE. 

OBJECTIVE
Implement a simple rigid body mass collision dynamics simulator using jMonkeyEngine.

INSTALLATION GUIDE OF THE SOURCE CODE

Before installing, check the licensefeatures, and requirements. Then choose one of these options:

Recommended Optional Optional

You want to…

Get started with jMonkeyEngine

Use jMonkeyEngine in another IDE

Build custom engine from sources

Then download…

You receive…

SDK, binaries, javadoc, sources

Binaries, javadoc, sources

Sources

* The SDK creates Ant-based projects that any Java IDE can import. We recommend users of other IDEs to also download the jMonkeyEngine SDK and choose “File→Import Project→External Project Assets to create a codeless project for managing assets only. This way you can code in the IDE of your choice, and use the SDK to convert your models to .j3o format.

When you build an Java application project that has a main class, the IDE automatically copies all of the JAR files on the projects classpath to your projects dist/lib folder. The IDE also adds each of the JAR files to the Class-Path element in the application JAR files manifest file (MANIFEST.MF). To run the project from the command line, go to the dist folder and type the following:

java -jar “MyGame.jar”

To distribute this project, zip up the dist folder (including the lib folder) and distribute the ZIP file.

Notes:

* If two JAR files on the project classpath have the same name, only the first JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders) are not copied.
* If a library on the projects classpath also has a Class-Path element specified in the manifest,the content of the Class-Path element has to be on the projects runtime path.
* To set a main class in a standard Java project, right-click the project node in the Projects window and choose Properties. Then click Run and enter the class name in the Main Class field. Alternatively, you can manually type the class name in the manifest Main-Class element.

VIDEO OF THE ANIMATION
Here it is.

TECHNIQUES USED/SUMMARY OF IMPLEMENTATION
I started with a standard com.jme3.app.SimpleApplication. To activate physics, I created a com.jme3.bullet.BulletAppState, and and attached it to the SimpleApplication’s AppState manager.

public class HelloPhysics extends SimpleApplication {
  private BulletAppState bulletAppState;

  public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    ...
  }
  ...
}

The BulletAppState gives the game access to a PhysicsSpace. The PhysicsSpace lets you use com.jme3.bullet.control.PhysicsControls that add physical properties to Nodes.
I used Geometries such as cannon balls and bricks. Geometries contain meshes, such as Shapes. I wanted to create brick Geometries from those boxes. For each Geometry with physical properties, I created a RigidBodyControl.

  private RigidBodyControl brick_phy;

The custom makeBrick(loc) methods creates individual bricks at the location loc. A brick has the following properties:

  • It has a visible Geometry brick_geo (Box Shape Geometry).
  • It has physical properties brick_phy (RigidBodyControl)
  public void makeBrick(Vector3f loc) {
    /** Create a brick geometry and attach to scene graph. */
    Geometry brick_geo = new Geometry("brick", box);
    brick_geo.setMaterial(wall_mat);
    rootNode.attachChild(brick_geo);
    /** Position the brick geometry  */
    brick_geo.setLocalTranslation(loc);
    /** Make brick physical with a mass > 0.0f. */
    brick_phy = new RigidBodyControl(2f);
    /** Add physical brick to physics space. */
    brick_geo.addControl(brick_phy);
    bulletAppState.getPhysicsSpace().add(brick_phy);
  }

I created a brick Geometry brick_geo. A Geometry describes the shape and look of an object.

    • brick_geo has a box shape
    • brick_geo has a brick-colored material.I attached brick_geo to the rootNode
      I positioned brick_geo at loc.
      I created a RigidBodyControl brick_phy for brick_geo.
    • brick_phy has a mass of 2f.
    • I added brick_phy to brick_geo.
    • I registered brick_phy to the PhysicsSpace.
      initMaterial() – This method initializes all the materials we use in this demo.initWall() – A double loop that generates a wall by positioning brick objects: 15 rows high with 6 bricks per row. It’s important to space the physical bricks so they do not overlap.initCrossHairs() – This method simply displays a plus sign that you use as crosshairs for aiming. Note that screen elements such as crosshairs are attached to the guiNode, not the rootNode!initInputs() – This method sets up the click-to-shoot action.

In the moment the cannonball appears in the scene, it flies off with the velocity (and in the direction) that you specified using setLinearVelocity() inside makeCannonBall(). The newly created cannon ball flies off, hits the wall, and exerts a physical force that impacts individual bricks.

The location of the dynamic Spatial is controlled by its RigidBodyControl. Move the RigidBodyControl to move the Spatial. If it’s a dynamic PhysicsControl, you can use setLinearVelocity() and apply forces and torques to it. Other RigidBodyControl’led objects can push the dynamic Spatial around (like pool/billiard balls).

 

Leave a comment