Why my camera is shaking?
[java]import com.jme3.renderer.RenderManager;
import com.jme3.system.AppSettings;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.bullet.BulletAppState;
import com.jme3.scene.Node;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.scene.Spatial;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.scene.shape.Box;
/**
- test
-
@author normenhansen
/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
AppSettings settings=new AppSettings(true);
settings.setRenderer(AppSettings.LWJGL_OPENGL1);
app.setSettings(settings);
app.start();
}
Boolean isRunning=true;
float acel=0;
private RigidBodyControl landscape;
private RigidBodyControl landscape2;
float x=0;
Vector3f posoka;
Spatial korab;
private RigidBodyControl korab_phy;
private RigidBodyControl stancia_phy;
Spatial stancia;
Geometry blue;
Geometry red ;
Boolean gf=false;
private CharacterControl player;
Geometry korab_geo;
Geometry stancia_geo;
private BulletAppState bulletAppState;
public void simpleInitApp() {
initobjects();
initcammera();
initphysics();
// rootNode.attachChild(korab);
// rootNode.attachChild(stancia);
Node pivot = new Node("pivot");
//rootNode.attachChild(pivot);
pivot.attachChild(blue);
pivot.attachChild(red);
pivot.rotate(.4f,.4f,0f);
initKeys();
}
private void initphysics()
{
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setPhysicsLocation(new Vector3f(0, 0, -1000));
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
// CollisionShape sceneShape3 = CollisionShapeFactory.createMeshShape((Node) korab);
CollisionShape sceneShape =CollisionShapeFactory.createMeshShape( stancia);
CollisionShape sceneShape2 =CollisionShapeFactory.createMeshShape( korab);
stancia_phy=new RigidBodyControl(sceneShape,0);
korab_phy=new RigidBodyControl(3f);
stancia_geo.addControl(stancia_phy);
korab_geo.addControl(korab_phy);
bulletAppState.getPhysicsSpace().add(stancia_phy);
bulletAppState.getPhysicsSpace().add(korab_phy);
rootNode.attachChild(korab_geo);
rootNode.attachChild(stancia_geo);
// korab_phy.setLinearVelocity(new Vector3f(0,0,1000));
}
private void initcammera()
{
cam.lookAt(new Vector3f(1,3,1), new Vector3f(10,30,20));
}
private void initobjects()
{
Box box1 = new Box( new Vector3f(1,-1,1), 1,1,1);
blue = new Geometry("Box", box1);
Material mat1 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
blue.setMaterial(mat1);
Box box2 = new Box( new Vector3f(1,3,1), 1,1,1);
red = new Geometry("Box", box2);
Material mat2 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Red);
red.setMaterial(mat2);
korab = assetManager.loadModel("Models/KORAB.obj");
korab_geo= (Geometry) korab;
stancia = assetManager.loadModel("Models/Space.obj");
Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
korab.setMaterial(mat_default);
stancia.setMaterial(mat_default);
stancia.setLocalRotation(new Quaternion(4f,0.5f,0.6f,1));
stancia.setLocalTranslation(0, 0, -1000);
stancia_geo=(Geometry) stancia;
}
private void initKeys() {
inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P));
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K));
inputManager.addMapping("Acel", new KeyTrigger(KeyInput.KEY_R));
inputManager.addMapping("DEC", new KeyTrigger(KeyInput.KEY_F));
inputManager.addMapping("Rotate", new KeyTrigger(KeyInput.KEY_SPACE),new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, new String[]{"Pause"});
inputManager.addListener(analogListener, new String[]{"Left", "Right", "Rotate","DEC","Acel"});
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Pause") && !keyPressed) {
isRunning = !isRunning;
}
}
};
private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
if (name.equals("Rotate")) {
korab.rotate(0, valuespeed, 0);
}
if (name.equals("Acel")) {
acel-=1;
}
if (name.equals("DEC")) {
acel+=1;
}
if (name.equals("Right")) {
Vector3f v = korab.getLocalTranslation();
korab.setLocalTranslation(v.x + valuespeed, v.y, v.z);
}
if (name.equals("Left")) {
Vector3f v = korab.getLocalTranslation();
korab.setLocalTranslation(v.x - valuespeed, v.y, v.z);
}
}
};
public void simpleUpdate(float tpf) {
x=tpfacel0.1f + x;
korab_phy.setLinearVelocity(new Vector3f(0,0,x));
posoka=korab.getWorldTranslation();
cam.setLocation(new Vector3f(0f,4f,posoka.getZ()+14f));
cam.lookAt(korab_geo.getLocalTranslation(), new Vector3f(0,0,0));
}
@Override
public void simpleRender(RenderManager rm) {
}
}[/java]