我正在用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);
}盒子会像预测的那样移动,但是相机会停留在原来的位置。图表应该是这样的:
因此,相机应该已经绑定到shipNode。我遗漏了什么?
发布于 2012-02-20 17:26:17
阅读您提供的教程,似乎您可能有一个错误。你有:
cameraNode.setControlDir(ControlDirection.CameraToSpatial);然而,本教程有:
//This mode means that camera copies the movements of the target:
camNode.setControlDir(ControlDirection.SpatialToCamera);在本教程的较低部分,它定义了这2 ControlDirections之间的区别。本教程提供的是照相机跟踪物体的运动,而你拥有的物体跟随相机的运动。
希望这能有所帮助。
https://stackoverflow.com/questions/9365217
复制相似问题