Let's start as a noob

I did not understand the big examples of jme physics, that's why I decided to start again, trying to advance step by step.

I hope I get the help I need here in the forum because this is the only help source beside the complete source texts but these don't help me to understand what is really going on.



I have created a really simple program with a floor and a box - but why does the box move that strange (normally it should simply lay on the floor but it moves) - can somebody explain why?



Imports left out to save space.

public class Auto extends SimplePhysicsGame {

   /**
    * @param args
    */
   public static void main(String[] args) {
      new Auto().start();
   }

   @Override
   protected void simpleInitGame() {
      StaticPhysicsNode terrain = getPhysicsSpace().createStaticNode();
      terrain.createMesh("Boden");
      PhysicsMesh terrainmesh = terrain.createMesh( "terrain mesh" );
      Box terrainbox=new Box("Terrain Box",new Vector3f(0,0,0),new Vector3f(15,0.1f,15));
      terrainbox.setSolidColor(ColorRGBA.blue);
      terrainmesh.copyFrom( terrainbox );
      terrainbox.setModelBound( new BoundingBox() );
        terrainbox.updateModelBound();
        terrain.attachChild(terrainbox);
        rootNode.attachChild(terrain);
      
      DynamicPhysicsNode chassis = getPhysicsSpace().createDynamicNode();
      chassis.createMesh( "chassis" );
      PhysicsMesh myboxmesh = chassis.createMesh( "sphere mesh" );
      Box mybox=new Box("Chassis Box",new Vector3f(0,0,0),new Vector3f(1,1,1));
      myboxmesh.copyFrom( mybox );
      mybox.setModelBound( new BoundingBox() );
      chassis.setLocalTranslation(new Vector3f(5,5,5));
        mybox.updateModelBound();
        chassis.attachChild(mybox);
        rootNode.attachChild( chassis );
        chassis.computeMass();
       
        showPhysics=true;
   }
}

Your box has a center of gravity at the edge of the box (the green cross is the center of gravity if you show physics) :

This code

Box mybox=new Box("Chassis Box",new Vector3f(0,0,0),new Vector3f(1,1,1));


creates a box with a center at (0.5, 0.5, 0.5)! The center of gravity remains at (0,0,0).
Create your box via

Box mybox=new Box("Chassis Box",new Vector3f(0,0,0),1,1,1);


(different constructor!!) to get a center of (0,0,0).

And be sure to either add that line I posted in your other thread or update OdeMesh from CVS.

Ok, I thought of the center of mass but didn't work after I set setCenterOfMass(0.5f,0.5f,0.5f);

But now it works fine.



I looked at the addForce method. That works also well but I don't know how I could set it that if the cube would be a car it will go forward? With addForce I can only give a vector where the car should go but if I turned it before, forwards will be another direction than before. Could you help me again?

simply multiply the rotation of the object with your force to obtain a force in the direction the object is facing

Yep, I got it :wink: Now I can move my cube.



Now I want to try to put wheels under my cube. I started with 1 cube (I read that I can only use spheres as wheels because cylinders are not realiable in collision detection, right?). I read and saw in the TestVehicle example that I have to use Joints. As I understood a joint is a connection between 2 Nodes, isn't it?

Now I tried to use these but get a high-jumping object (I mean very high)

Here is my code:

public class Auto extends SimplePhysicsGame {

   /**

    * @param args

    */

   public static void main(String[] args) {

      new Auto().start();

   }



   @Override

   protected void simpleInitGame() {

      final StaticPhysicsNode terrain = getPhysicsSpace().createStaticNode();

      terrain.createMesh("Boden");

      PhysicsMesh terrainmesh = terrain.createMesh( "terrain mesh" );

      Box terrainbox=new Box("Terrain Box",new Vector3f(0,0,0),new Vector3f(15,0.1f,15));

      terrainbox.setSolidColor(ColorRGBA.blue);

      terrainmesh.copyFrom( terrainbox );

      terrainbox.setModelBound( new BoundingBox() );

        terrainbox.updateModelBound();

        terrain.attachChild(terrainbox);

        rootNode.attachChild(terrain);

      

      final DynamicPhysicsNode chassis = getPhysicsSpace().createDynamicNode();

      chassis.createMesh( "chassis" );

      PhysicsMesh myboxmesh = chassis.createMesh( "sphere mesh" );

      Box mybox=new Box("Chassis Box",new Vector3f(0,0,0),1,2,2);

      myboxmesh.copyFrom( mybox );

      mybox.setModelBound( new BoundingBox() );

      chassis.setLocalTranslation(new Vector3f(5,5,5));

        mybox.updateModelBound();

        chassis.attachChild(mybox);

        chassis.computeMass();

        chassis.setMass(10);

        rootNode.attachChild( chassis );

       

       

        final DynamicPhysicsNode[] tire = new DynamicPhysicsNode[1];

        DynamicPhysicsNode tire0 = getPhysicsSpace().createDynamicNode();;

        for(int i=0;i<tire.length;i++) {

           chassis.createMesh( "tire 0" );

          PhysicsMesh tiremesh = tire0.createMesh( "sphere mesh" );

          Sphere tiresphere=new Sphere("Chassis Box",10,10,1);

          tiremesh.copyFrom( tiresphere );

          tiresphere.setModelBound( new BoundingSphere() );

          tire0.setLocalTranslation(new Vector3f(8,8,8));

            tiresphere.updateModelBound();

            tire0.attachChild(tiresphere);

            rootNode.attachChild( tire0 );

            tire0.computeMass();

            tire0.setMass(1);

        }

       

        getPhysicsSpace().setDirectionalGravity(new Vector3f(0f,-2.81f,0f));

       

        Joint joint = getPhysicsSpace().createJoint();

        joint.attach( chassis, tire0 );

        joint.setAnchor( tire0.getLocalTranslation() );

        final JointAxis axis1 = joint.createRotationalAxis();

        axis1.setDirection( new Vector3f( 0, 1, 0 ) );

        axis1.setPositionMinimum( -0.5f );

        axis1.setPositionMaximum( 0.5f );

        axis1.setAvailableAcceleration( 100 );

        axis1.setDesiredVelocity( 0 );

        final JointAxis axis2 = joint.createRotationalAxis();

        axis2.setDirection( new Vector3f( 0, 0, 1 ) );

        axis2.setAvailableAcceleration( 100 );

        axis2.setRelativeToSecondObject( true );

       

        InputAction throttleAction = new InputAction() {

            public void performAction( InputActionEvent evt ) {

               chassis.addForce(chassis.getLocalRotation().mult(new Vector3f(1,0,0)));

            }

        };

        input.addAction( throttleAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_O, InputHandler.AXIS_NONE, true );

       

        InputAction steerLeftAction = new InputAction() {

            public void performAction( InputActionEvent evt ) {

               chassis.setAngularVelocity(new Vector3f(0,1,0));

            }

        };

        input.addAction( steerLeftAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_K, InputHandler.AXIS_NONE, true );

       

        InputAction steerRightAction = new InputAction() {

            public void performAction( InputActionEvent evt ) {

               chassis.setAngularVelocity(new Vector3f(0,-1,0));

            }

        };

        input.addAction( steerRightAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_L, InputHandler.AXIS_NONE, true );

       

        InputAction brakeAction = new InputAction() {

            public void performAction( InputActionEvent evt ) {

               chassis.addForce(chassis.getLocalRotation().mult(new Vector3f(-1,0,0)));

            }

        };

        input.addAction( brakeAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_COMMA, InputHandler.AXIS_NONE, true );

       

        showPhysics=true;

   }

}



Hope somebody could solve my problem and also explain how Joints exactly work (or is there a forum message about this topic - I search…)

Thanks, daryl

have a look at the ode doc on http://ode.org

Ok I understood. But I didn't find anything about the reason why my object jumps that high - without the joint they act as expected (jumping a bit but not very high). Could you help me with this problem, too?

I need a Hinge2Joint I think as I also need 2 axisses. But how can I implement this? I saw there is a joint and it's attached with 2 axisses in TestVehicle - there it works but why does that thing jump that high??? I also set the mass of the objects higher but that reduces this effect only a bit. Then I tried to move the Anchor but that doesn't solve the problem either.