Hi,
I'm a beginner here and while trying to focus my camera towards a moving object, the screen flickers between the original view and the view pointing towards the said object. All (I think) I do is to call the
cam.lookAt(focusPoint.getWorldTranslation(), cam.getUp());
in the simpleUpdate() method. Can someone give me a clue? (Most of the code comes from the physics ragdoll test class)
The code is below, the cam.lookAt method is in the adjustView method called in the init and in the simpleUpdate:
package com.copycatz.balldrop.prototype;
import static com.copycatz.balldrop.util.SpatialUtils.color;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.copycatz.balldrop.props.Swing;
import com.jme.input.InputHandler;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.action.InputAction; import com.jme.input.action.InputActionEvent;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.shape.GeoSphere;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.material.Material;
import com.jmex.physics.util.SimplePhysicsGame;
/**
* @author Ky Vinh
*
*/
public class BallDrop1 extends SimplePhysicsGame {
private Swing slide;
private Node focusPoint;
/*
* (non-Javadoc)
*
* @see com.jme.app.BaseSimpleGame#simpleInitGame()
*/
@Override
protected void simpleInitGame() {
addSimpleSlide();
configurePhysicsPicker();
registerDropBallAction();
adjustCameraView();
}
private void registerDropBallAction() {
InputAction createAction = new InputAction() {
public void performAction(InputActionEvent evt) {
if (evt == null || evt.getTriggerPressed()) {
focusPoint = addDroppingBall();
}
}
};
input.addAction(createAction, InputHandler.DEVICE_KEYBOARD,
KeyInput.KEY_SPACE, InputHandler.AXIS_NONE, false);
}
private Node addDroppingBall() {
DynamicPhysicsNode ballNode = getPhysicsSpace().createDynamicNode();
rootNode.attachChild(ballNode);
GeoSphere ball = new GeoSphere("droppingball", true, 2);
ballNode.attachChild(ball);
ballNode.generatePhysicsGeometry();
ballNode.setLocalScale(0.75f);
ballNode.setMaterial(Material.GRANITE);
color(ballNode, display, new ColorRGBA(0.5f, 0.5f, 0.9f, 0.3f));
ballNode.computeMass();
ballNode.getLocalTranslation().y += 3;
ballNode.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
rootNode.updateWorldData(0);
rootNode.updateGeometricState(0, false);
rootNode.updateRenderState();
return ballNode;
}
@Override
protected void simpleUpdate() {
slide.update();
adjustCameraView();
/*
* rootNode.updateWorldData(0); rootNode.updateGeometricState(0, false);
* rootNode.updateRenderState();
*/
}
private void addSimpleSlide() {
slide = new Swing(getPhysicsSpace(), 20);
color(slide, display, new ColorRGBA(0.9f, 0.9f, 0.3f, 1));
rootNode.attachChild(slide);
}
private void adjustCameraView() {
if (focusPoint != null) {
// [b]The line below makes the screen flicker[/b]
cam.lookAt(focusPoint.getWorldTranslation(), cam.getUp());
// cam.getLocation().y = focusPoint.getLocalTranslation().y;
// cam.update();
} else {
// cam.getLocation().x -= 10;
// cam.getLocation().y += 10;
// cam.getLocation().z += 10;
cam.lookAt(slide.getWorldTranslation(), new Vector3f(0, 1, 0));
}
}
public static void main(String[] args) {
Logger.getLogger("").setLevel(Level.WARNING);
final BallDrop1 app = new BallDrop1();
// app.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
new Thread() {
@Override
public void run() {
app.start();
}
}.start();
}
private void configurePhysicsPicker() {
cameraInputHandler.setEnabled(false);
// new PhysicsPicker(input, rootNode, getPhysicsSpace(), true);
MouseInput.get().setCursorVisible(true);
}
}