Color and movement

Hello,



is it possible to give objects a color in SimplePhysicsGame? If I set a color with setSolidColor() everything stays grey.



But that's only a question beside the real one: I have a pseudo-car with 4 spheres as wheels and a box as chassis. I can addForce as I want, the thing does only move when it's in the air. Possibly I have to rotate the axs instead of adding Force but I don't know how. Here is my code until now:

public class Auto extends SimplePhysicsGame {

   /**

   * @param args

   */

   public static void main(String[] args) {

      LoggingSystem.getLogger().setLevel( Level.WARNING );

      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(-10,0,-10),new Vector3f(15,0.1f,15));

      

      terrainmesh.copyFrom( terrainbox );

      terrainmesh.getLocalTranslation().set( terrain.getLocalTranslation() );

      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),2,0.1f,1);

      

      myboxmesh.copyFrom( mybox );

      mybox.setModelBound( new BoundingBox() );

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

        mybox.updateModelBound();

        chassis.attachChild(mybox);

        //chassis.computeMass();

        //chassis.setMass(100);

        rootNode.attachChild( chassis );

       

        DynamicPhysicsNode wheels[] = new DynamicPhysicsNode[4];

        for(int i=0;i<4;i++) {

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

           wheels[i]=tire;

           tire.createMesh( "tire" );

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

          Sphere tiresphere=new Sphere("Tire Sphere",10,10,0.4f);

          tiremesh.copyFrom( tiresphere );

          tiresphere.setModelBound( new BoundingSphere() );

          

            tiresphere.updateModelBound();

            tire.setMaterial( Material.RUBBER );

            tire.getLocalTranslation().set( ( 0.5f - ( i & 1 ) ), 1, ( 1 - ( i & 2 ) ) * 0.5f );

            tire.computeMass();

            tire.setMass( 10 );

           

            rootNode.attachChild( tire );

            tire.computeMass();

           

            Joint joint = getPhysicsSpace().createJoint();

            joint.attach( chassis, tire);

            joint.setAnchor( new Vector3f(0,0,0) );

            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 ) {

                   tire.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 ) {

                   tire.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 ) {

                   tire.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 ) {

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

                }

            };

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

           

        }

       

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

       

        showPhysics=true;

        rootNode.updateGeometricState(0.0f, true);

        rootNode.updateRenderState();

   }

}

Color: you have to either deactivate lighting or apply a material state instead of vertex color. (possibly read up on GL lighting and colors)

Vehicle: TestVehicle shows how to rotate axes.

Vehicle: TestVehicle shows how to rotate axes.
That's exactly my problem: nothing moves there when I use it. I also tried to assign other keys but the car stays at its place.

Also if you hold down NUM_8 really long? If yes, please increase availableAcceleration from 100 to 1000 and try again. That test really should work.

I set acceleration to 1000 and pressed the key for 30 seconds - nothing moves.

But again to the problem that I don't see a System.out.print()-message that I wrote into the performAction method. I think the action isn't performed, otherwise the message would appear.



I also downloaded the package again from java.net - same result as before: no movement  :frowning:

I think I have a solution: If I comment ou the "if ( evt.getTriggerPressed() ) {" line it works. I tried to show the boolena result of evt.getTriggerPressed() and it is always false, so it sets desired velocity to 0 - so he does nothing because accelerating from 0 to 0 means standing still.



So is there another if-request needed?



An6ther thing is that only if I set last parameter to true in the input.addAction method both front wheels turn (but after pressing don't turn back - but that would be ok with another if request in performAction() I think). If I use false only one wheel turns and also accelerating lets only one wheel turn.

hmm, that's interesting - which jME Version do you use? it seems to be an outdated one - trigger pressed should be true when the key goes down…

I downloaded JME from jmonkeyengine.com from "Download nightly build" (secod point in the left navigation). Is this an old one? Can I get a newer one without CVS?

Have the same issue with evt.getTriggerPressed() - it's never true.

Running on Windows, recent CVS.

This is initalizeing:


      inputHandler.addAction(new VelocityRight(cam, moveSpeed, maxSpeed), "right", true);
      KeyBindingManager.getKeyBindingManager().set("right", KeyInput.KEY_J);



and in Velocityright class the perform action looks like this:


    public void performAction(InputActionEvent evt) {
       
       System.out.println("Backward: " + evt + " : " +evt.getTriggerPressed());

    }



Did i forget to init smth?

Greetz
snare

A nightly build should be fine. I fixed some things on 23. of May - maybe you downloaded before that date? But then jME Physics 2 should have other problems, too. Strange :?



@snareoj: it should definately be true all the time (as you have specified to call the action every frame the button is down). And it is over here. Please update from CVS or download a recent nightly build and try again. (or are you using the latest release? If yes, this is a known issue which was corrected in the developer version)

I am updateing regularly from CVS :).

I updated and i tried again now - but it is always false…



Forget to write that VelocityBackward extends KeyInputAction, dont know if this is relevant.

Oh, wait :-o - snareoj, you havn't used the button stuff but the commands. That behaviour is correct. Commands are not 'pressed'. Have a look into the Wiki how to use the device buttons (it's another addAction method).

Yeah, now it works.I downloaded the nightly build of JME and some files have been changed since my last download.

great :slight_smile:

Ah ok thx i'll check that