Shaking Camera

Hi, does anyone knwo why the camera shakes when it get closer to the car?

ps: Im using as a base the TestVehicle example…



Thanks… :slight_smile:


package principal;

import java.util.HashMap;

import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.input.ChaseCamera;
import com.jme.input.InputHandler;
import com.jme.input.KeyInput;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.input.thirdperson.ThirdPersonMouseLook;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Cylinder;
import com.jme.scene.state.MaterialState;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.Joint;
import com.jmex.physics.JointAxis;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.material.Material;
import com.jmex.physics.util.SimplePhysicsGame;

public class Teste extends SimplePhysicsGame {

   private ChaseCamera chaser;
   private Box carro;

   @Override
   protected void simpleUpdate() {
      super.simpleUpdate();
      chaser.update(tpf);
   }

    private void buildChaseCamera() {
           Vector3f targetOffset = new Vector3f();
           targetOffset.y = ((BoundingBox) carro.getWorldBound()).yExtent * 3f;
           HashMap<String, Object> props = new HashMap<String, Object>();
           props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "6");
           props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "3");
           props.put(ThirdPersonMouseLook.PROP_MAXASCENT, ""+45 * FastMath.DEG_TO_RAD);
           props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(5, 0, 30 * FastMath.DEG_TO_RAD));
           props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
           chaser = new ChaseCamera(cam, carro, props);
           chaser.setMaxDistance(8);
           chaser.setMinDistance(2);
       }

   protected void simpleInitGame() {
      gerarChao();
      gerarObstaculos();
      final DynamicPhysicsNode chassis = getPhysicsSpace()
            .createDynamicNode();
      carro = new Box("Chassis", Vector3f.ZERO, .5f, 1f, .5f);
      carro.setModelBound(new BoundingBox());
      carro.updateModelBound();
      carro.setLocalTranslation(0f, .7f, 0f);
      chassis.attachChild(carro);
      chassis.setLocalScale(new Vector3f(1, 0.3f, 1));
      chassis.generatePhysicsGeometry();
      chassis.setMaterial(Material.IRON);
      chassis.setMass(100);
      rootNode.attachChild(chassis);
      MaterialState roda = display.getRenderer().createMaterialState();
      roda.setDiffuse(ColorRGBA.black);
      roda.setSpecular(ColorRGBA.gray);
      roda.setShininess(10f);
      buildChaseCamera();
      for (int i = 0; i < 4; i++) {
         DynamicPhysicsNode tire = getPhysicsSpace().createDynamicNode();
         tire.setMaterial(Material.RUBBER);
         Cylinder roda2 = new Cylinder("roda", 10, 25, 1, 1, true);
         roda2.setModelBound(new BoundingSphere());
         roda2.updateModelBound();
         roda2.setRenderState(roda);
         tire.attachChild(roda2);
         tire.setLocalScale(0.3f);
         tire.getLocalTranslation().set((0.5f - (i & 1)), 0,
               (1 - (i & 2)) * 0.5f);
         tire.generatePhysicsGeometry();
         tire.computeMass();
         tire.setMass(50);
         rootNode.attachChild(tire);
         Joint joint = getPhysicsSpace().createJoint();
         joint.attach(chassis, tire);
         joint.setAnchor(tire.getLocalTranslation());
         final JointAxis axis1 = joint.createRotationalAxis();
         axis1.setDirection(new Vector3f(0, 1, 0));
         if (i == 2 || i == 0) {
            axis1.setPositionMinimum(-0.5f);
            axis1.setPositionMaximum(0.5f);
         } else {
            axis1.setPositionMinimum(-0f);
            axis1.setPositionMaximum(0f);
         }
         axis1.setAvailableAcceleration(100);
         axis1.setDesiredVelocity(0);
         final JointAxis axis2 = joint.createRotationalAxis();
         axis2.setDirection(new Vector3f(0, 0, 1));
         axis2.setAvailableAcceleration(100);
         axis2.setRelativeToSecondObject(true);
         if ((i & 1) == 0) {
            input.addAction(new SteerAction(axis1, 10),
                  InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_J,
                  InputHandler.AXIS_NONE, false);
            input.addAction(new SteerAction(axis1, -10),
                  InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_G,
                  InputHandler.AXIS_NONE, false);
         }
         input.addAction(new SteerAction(axis2, 20),
               InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_Y,
               InputHandler.AXIS_NONE, false);
         input.addAction(new SteerAction(axis2, -20),
               InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_H,
               InputHandler.AXIS_NONE, false);
      }

      fpsNode.setCullMode(Node.CULL_ALWAYS);
   }

   private void gerarObstaculos() {
      final DynamicPhysicsNode chassis = getPhysicsSpace()
            .createDynamicNode();
      Box caixa;
      caixa = new Box("aaa", Vector3f.ZERO, .5f, 1f, .5f);
      caixa.setLocalTranslation(0f, 5f, 0f);
      chassis.attachChild(caixa);
      chassis.setLocalScale(new Vector3f(1, 0.3f, 1));
      chassis.generatePhysicsGeometry();
      chassis.setMaterial(Material.IRON);
      chassis.setMass(100);
      rootNode.attachChild(chassis);
   }

   private void gerarChao() {
      final StaticPhysicsNode staticNode = getPhysicsSpace()
            .createStaticNode();
      Box chao;
      chao = new Box("chao", new Vector3f(0, -1, 0), 50f, .2f, 50f);
      MaterialState redgreen = display.getRenderer().createMaterialState();
      redgreen.setDiffuse(ColorRGBA.red);
      redgreen.setShininess(10f);
      chao.setRenderState(redgreen);
      staticNode.attachChild(chao);
      staticNode.generatePhysicsGeometry();
      staticNode.setMaterial(Material.CONCRETE);
      rootNode.attachChild(staticNode);
   }

   public static void main(String[] args) {
      Teste app = new Teste();
      app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
      app.start();
   }

   private static class SteerAction extends InputAction {

      private final JointAxis axis1;
      private float velocity;

      public SteerAction(JointAxis axis1, float velocity) {
         this.axis1 = axis1;
         this.velocity = velocity;
      }

      public void performAction(InputActionEvent evt) {
         if (evt.getTriggerPressed()) {
            axis1.setDesiredVelocity(velocity);
         } else {
            axis1.setDesiredVelocity(0);
         }
      }
   }
}

Im having the same problem to.



Tried serveral variable cahanges. no luck.

Can you try to change:



"carro = new Box("Chassis", Vector3f.ZERO, .5f, 1f, .5f);"



into this:



"carro = new Box("Chassis", new Vector3f(0,0,0), .5f, 1f, .5f);"



?



And do the same change for all static values of Vector3f.