to Main Page

Tutorial

Create an object and add it to Simulation

To create a dynamic physical object, use the org.MARS.dynamics.element.body.RigidBody class. Its constructor's signature is as follows:

RigidBody(x:Number, y:Number, shape:Shape, mass:Number = 100, vx:Number = 0, vy:Number = 0, friction:Number = 0.2, elasticity:Number = 0.25, q:Number = 0, av:Number = 0)

x and y are the coordinates of the center of the body in pixels

Refer to the API Documentation for more information

To create the Rigid Body's shape, select the appropriate subclass of org.MARS.view.shape.Shape:

  • org.MARS.view.shape.Circle for circular objects
  • org.MARS.view.shape.Rectangle for rectangular objects
  • org.MARS.view.shape.SymmetricPolygon for symmetric polygons
  • org.MARS.view.shape.Polygon for generic polygons (this class is not recommended since MARS can only process convex polygons)

Refer to the API Documentation for more information about each class

If you are unsure which value to use for mass, refer to org.MARS.dynamics.enum.Simplification class.

Example:
var lightCircularObject:RigidBody = new RigidBody(100, 100, new Circle(0, 0, 10), Simplification.SMALL_MASS);
var heavyPoligonalObject:RigidBody = new RigidBody(400, 200, new SymmetricPolygon(0, 0, 6, 50), Simplification.LARGE_MASS);

Creates one circular object with radius of 10 pixels, center at 100, 100 and a small mass. The second object is a 6-sided polygon of size 50, center at 400, 200 and a large mass.

To make the objects a part of simulation, you must add them to the simulation as follows:

Environment.getInstance().addDynamicObject(lightCircularObject, true);
Environment.getInstance().addDynamicObject(heavyPoligonalObject, true);

NOTE: the boolean value in the Environment.addDynamicObject() method determines if the object is detectable by the robot's sensors. Set it to false for very light or low objects that don't trigger the robot's touch sensor.