Hi,
I´m completely new to a physics engine.
I took the ConstraintTest example and deleted all but the bridge.
Three questions came up while experimenting:
1. I would like to fix/pin the bridge on the loose side too, so that it behaves like a real bridge. How can i do that?
2.(different case) Can i have the constraints behaviour without any fix point, so that it falls down?
3. How can i change the ball from my example to not fall down? Like setting it to get no gravity.
package {
import away3d.containers.View3D;
import away3d.debug.AwayStats;
import away3d.entities.Mesh;
import away3d.events.MouseEvent3D;
import away3d.lights.PointLight;
import away3d.materials.ColorMaterial;
import away3d.primitives.Cube;
import away3d.primitives.Plane;
import away3d.primitives.Sphere;
import awayphysics.collision.shapes.AWPBoxShape;
import awayphysics.collision.shapes.AWPSphereShape;
import awayphysics.collision.shapes.AWPStaticPlaneShape;
import awayphysics.dynamics.AWPDynamicsWorld;
import awayphysics.dynamics.AWPRigidBody;
import awayphysics.dynamics.constraintsolver.AWPHingeConstraint;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix3D;
import flash.geom.Vector3D;
[SWF(backgroundColor="#000000", frameRate="60", width="1024", height="768")]
public class FabsBridge extends Sprite {
private var _view : View3D;
private var _light : PointLight;
private var physicsWorld : AWPDynamicsWorld;
private var timeStep : Number = 1.0 / 60;
public function FabsBridge() {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e : Event = null) : void {
removeEventListener(Event.ADDED_TO_STAGE, init);
_view = new View3D();
this.addChild(_view);
this.addChild(new AwayStats(_view));
_light = new PointLight();
_light.y = 2500;
_light.z = -3000;
_view.scene.addChild(_light);
_view.camera.lens.far = 10000;
_view.camera.y = _light.y;
_view.camera.z = _light.z;
_view.camera.rotationX = 25;
// init the physics world
physicsWorld = AWPDynamicsWorld.getInstance();
physicsWorld.initWithDbvtBroadphase();
// create rigidbody shapes
var sphereShape:AWPSphereShape = new AWPSphereShape(100);
var boxShape:AWPBoxShape = new AWPBoxShape(400, 80, 300);
// create material
var material:ColorMaterial = new ColorMaterial(0xfc6a11);
material.lights = [_light];
// create fix ball shape and rigidbody
var ball:Sphere = new Sphere(material, 100);
var ballRigidbody : AWPRigidBody = new AWPRigidBody(sphereShape, ball, 2);
//ballRigidbody.gravity = new Vector3D(0,0,0);
ballRigidbody.position = new Vector3D( -500, 4500, -200);
physicsWorld.addRigidBody(ballRigidbody);
_view.scene.addChild(ball);
var mesh : Mesh;
var currBody : AWPRigidBody = null;
var prevBody : AWPRigidBody = null;
// create a bridge with AWPHingeConstraint and box shape
var hinge : AWPHingeConstraint;
for (var i:int = 0; i < 10; i++ ) {
mesh = new Cube(material, 400, 80, 300);
_view.scene.addChild(mesh);
prevBody = currBody;
currBody = new AWPRigidBody(boxShape, mesh, 10);
currBody.position = new Vector3D( -500, 1000, (310 * i));
physicsWorld.addRigidBody(currBody);
if (i == 0) {
hinge = new AWPHingeConstraint(currBody, new Vector3D(0, 0, -155), new Vector3D(1, 0, 0));
physicsWorld.addConstraint(hinge);
} else {
hinge = new AWPHingeConstraint(prevBody, new Vector3D(0, 0, 155), new Vector3D(1, 0, 0), currBody, new Vector3D(0, 0, -155), new Vector3D(1, 0, 0));
physicsWorld.addConstraint(hinge);
}
}
stage.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
private function handleEnterFrame(e : Event) : void {
physicsWorld.step(timeStep);
_view.render();
}
}
}