modify bridge from examples - and make a real one

Software: Away3D 4.x

Fab4ce, Jr. Member
Posted: 17 October 2011 04:55 PM   Total Posts: 44

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 (stageinit();
   else 
addEventListener(Event.ADDED_TO_STAGEinit);
  
}

  
private function init(Event null) : void {
   removeEventListener
(Event.ADDED_TO_STAGEinit);

   
_view = new View3D();
   
this.addChild(_view);
   
this.addChild(new AwayStats(_view));

   
_light = new PointLight();
   
_light.2500;
   
_light.= -3000;
   
_view.scene.addChild(_light);

   
_view.camera.lens.far 10000;
   
_view.camera._light.y;
   
_view.camera._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(40080300);
   
   
// create material
   
var material:ColorMaterial = new ColorMaterial(0xfc6a11);
   
material.lights [_light];

   
// create fix ball shape and rigidbody
   
var ball:Sphere = new Sphere(material100);
   var 
ballRigidbody AWPRigidBody = new AWPRigidBody(sphereShapeball2);
   
//ballRigidbody.gravity = new Vector3D(0,0,0);
   
ballRigidbody.position = new Vector3D( -5004500, -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 010i++ ) {
    mesh 
= new Cube(material40080300);
    
_view.scene.addChild(mesh);
    
prevBody currBody;
    
currBody = new AWPRigidBody(boxShapemesh10);
    
currBody.position = new Vector3D( -5001000, (310 i));
    
    
physicsWorld.addRigidBody(currBody);
    if (
== 0{
     hinge 
= new AWPHingeConstraint(currBody, new Vector3D(00, -155), new Vector3D(100));
     
physicsWorld.addConstraint(hinge);
    
else {
    
     hinge 
= new AWPHingeConstraint(prevBody, new Vector3D(00155), new Vector3D(100), currBody, new Vector3D(00, -155), new Vector3D(100));
     
physicsWorld.addConstraint(hinge);
    
}
   }

   stage
.addEventListener(Event.ENTER_FRAMEhandleEnterFrame);
  
}

  
private function handleEnterFrame(Event) : void {
   physicsWorld
.step(timeStep);

   
_view.render();
  
}
 }
   

Fab4ce, Jr. Member
Posted: 21 November 2011 02:48 PM   Total Posts: 44   [ # 1 ]

no answer…..hmmm…..seems more complicated than i thought?
So one question after the other:

1. I would like to fix/pin the bridge on the loose side too, so that it behaves like a real bridge.

Is this possible with the current version?

   

John Brookes, Moderator
Posted: 21 November 2011 03:25 PM   Total Posts: 732   [ # 2 ]

1.
Make another conatraint between the last rigidbody and the world

eg Add

hinge = new AWPHingeConstraint(currBody, new Vector3D(0, 0, 155), new Vector3D(1, 0, 0));
physicsWorld.addConstraint(hinge);

After the for loop.

2.
Not sure what you mean but Im guessing you dont want to pin both sides of the bridge?
Just remove that first constraint ( the one in if (i == 0) )


3.
For the gravity, set it after you add the rigidbody to the physics world

   

Fab4ce, Jr. Member
Posted: 22 November 2011 10:07 AM   Total Posts: 44   [ # 3 ]

thanks JohnBrookes.
solution 1. and 3. work perfect.

about 2:
yes, i want the connected pieces to fall down….lets say on the static ball. I expect a behaviour similar to cloth.

When commenting out the if like that

/*
    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(00155), new Vector3D(100), currBody, new Vector3D(00, -155), new Vector3D(100));
     
physicsWorld.addConstraint(hinge);
    
//} 

i can´t see anything, black stage.
I´ll try a few things.

   

John Brookes, Moderator
Posted: 22 November 2011 01:19 PM   Total Posts: 732   [ # 4 ]

Just comment out the stuff inside the if (i==0)


or just replace it all with

if (i > 0)
{
hinge = new AWPHingeConstraint(prevBody, new Vector3D(0, 0, 155), new Vector3D(1, 0, 0), currBody, new Vector3D(0, 0, -165), new Vector3D(1, 0, 0));
physicsWorld.addConstraint(hinge);
}

   

Fab4ce, Jr. Member
Posted: 23 November 2011 09:40 AM   Total Posts: 44   [ # 5 ]

Impressive these physics.

Thank you very much.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X