简体   繁体   English

jMonkeyEngine摄像头关注

[英]jMonkeyEngine camera follow

I'm testing something with jMonkeyEngine and I'm attempting to have the camera follow a box spatial. 我正在使用jMonkeyEngine进行测试,并且试图使相机遵循空间框。 I followed official instructions here: 我在这里遵循官方指示:

http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:making_the_camera_follow_a_character http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:making_the_camera_follow_a_character

When applying, what I learnt there I produced the following code: 申请时,我从那里学到了以下代码:

@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();


}

When the following code is called: 调用以下代码时:

@Override
public void simpleUpdate(float tpf) {
    //Update ship heading
    shipHeading = shipHeading.mult(shipRotationMoment);
    shipNode.setLocalRotation(shipHeading);

    shipPos = shipPos.add(shipVelocity);
    shipNode.setLocalTranslation(shipPos);
}

The box moves as is predicted but the camera stays where it is. 盒子会像预期的那样移动,但相机会停留在原处。 The graph should be something like this: 该图应如下所示:

  • rootNode 根节点
    • b (Box) b(盒)
    • shipNode shipNode
      • shipBase shipBase
      • cameraNode cameraNode

Therefore the camera should be already bound to shipNode. 因此,摄像头应该已经绑定到shipNode。 What am I missing? 我想念什么?

Reading through the tutorial you provided, it seems you might have a typo. 通读您提供的教程,看来您可能有错字。 You have: 你有:

cameraNode.setControlDir(ControlDirection.CameraToSpatial);

However, the tutorial has: 但是,该教程具有:

//This mode means that camera copies the movements of the target:
camNode.setControlDir(ControlDirection.SpatialToCamera);

Lower down in the tutorial it defines the difference between these 2 ControlDirections. 在本教程的下部,它定义了这两个ControlDirection之间的区别。 The one the tutorial provides has the camera follow the movement of the object, whereas what you have the object follows the movement of the camera. 本教程提供的一种是使照相机跟随对象的运动,而您拥有的对象随照相机的运动。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM