2
我正在用jMonkeyEngine测试一些东西,我试图让摄像头跟着一个空间框。我跟着官方说明这里:jMonkeyEngine摄像头跟着
http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:making_the_camera_follow_a_character
申请时,我学到的东西在那里我产生了以下代码:
@Override
public void simpleInitApp() {
flyCam.setEnabled(false);
//world objects
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
//Ship node
shipNode = new Node();
rootNode.attachChild(shipNode);
//Ship
Box shipBase = new Box(new Vector3f(0, -1f, 10f), 5, 0.2f, 5);
Geometry shipGeom = new Geometry("Ship Base", shipBase);
Material shipMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
shipMat.setColor("Color", ColorRGBA.Green);
shipGeom.setMaterial(shipMat);
shipNode.attachChild(shipGeom);
//Camera node
cameraNode = new CameraNode("Camera Node", cam);
cameraNode.setControlDir(ControlDirection.CameraToSpatial);
shipNode.attachChild(cameraNode);
initPhysics();
initKeys();
}
当下面的代码被称为:
@Override
public void simpleUpdate(float tpf) {
//Update ship heading
shipHeading = shipHeading.mult(shipRotationMoment);
shipNode.setLocalRotation(shipHeading);
shipPos = shipPos.add(shipVelocity);
shipNode.setLocalTranslation(shipPos);
}
的盒子像预测的那样移动,但相机保持在原来的位置。该图应该是这样的:
- 根节点
- B(盒)
- shipNode
- shipBase
- cameraNode
因此相机应该已经绑定到shipNode。我错过了什么?
为什么相机应该移动,如果它连接到船只,但箱子是移动的对象? – 2012-02-20 17:11:59
如果我看到错误是正确的,但是shipNode移动因此它是child,shipBase(框)随之移动。然而,同时也是该船的孩子的cameraNode仍然是静止的。 – Vampnik 2012-02-20 17:19:21
对不起,我错过了船也在移动的事实。 – 2012-02-20 17:21:28