I returned with simple code.
Left and Right keys move camera along X axis. Red cube suppose to be attached to camera, but with Vsync on, its noticeably lag.
What do I do wrong?
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.InputListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.CameraControl;
public class camFollowTest extends SimpleApplication {
private Spatial smallbox;
private CameraNode camNode;
public static void main(String[] args){
camFollowTest app = new camFollowTest();
app.start(); // start the game
}
@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue
geom.setMaterial(mat); // set the cube’s material
rootNode.attachChild(geom); // make the cube appear in the scene
Box b2 = new Box(Vector3f.ZERO, 0.1f, 0.1f, 0.1f); // create cube shape at the origin
smallbox = new Geometry("Box", b2); // create cube geometry from the shape
Material mat2 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat2.setColor("Color", ColorRGBA.Red); // set color of material to blue
smallbox.setMaterial(mat2); // set the cube’s material
rootNode.attachChild(smallbox); // make the cube appear in the scene
//flyCam.setMoveSpeed(60);
flyCam.setEnabled(false);
camNode = new CameraNode("Camera Node", cam);
camNode.setControlDir(CameraControl.ControlDirection.SpatialToCamera);
rootNode.attachChild(camNode);
camNode.setLocalTranslation(0, 1.3f, -7);
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_LEFT));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_RIGHT));
inputManager.addListener(analogListener, new String[]{"Left", "Right"});
}
public void simpleUpdate(float tpf) {
//Vector3f pos = cam.getWorldCoordinates(new Vector2f(200,200), 0.2f);
//smallbox.setLocalTranslation(pos);
}
@Override
public void simpleRender(RenderManager rm) {
Vector3f pos = cam.getWorldCoordinates(new Vector2f(200,200), 0.2f);
smallbox.setLocalTranslation(pos);
}
private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
if (name.equals("Left")) {
camNode.move(1*tpf, 0, 0);
}
if (name.equals("Right")) {
camNode.move(-1*tpf, 0, 0);
}
}
};
}
[/java]
EDIT: Fixed broken quotes symbols in code.
EDIT2: Not worked, still broken 