gpt4 book ai didi

java - jMonkeyEngine 相机跟随

转载 作者:行者123 更新时间:2023-11-30 07:28:00 30 4
gpt4 key购买 nike

我正在用 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(盒子)
    • 船节点
      • 船舶基地
      • 相机节点

因此相机应该已经绑定(bind)到shipNode。我错过了什么?

最佳答案

通读了您提供的教程,您似乎有错字。你有:

cameraNode.setControlDir(ControlDirection.CameraToSpatial);

但是,教程有:

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

在教程的下方,它定义了这两个 ControlDirections 之间的区别。教程提供的是让相机跟随对象的移动,而您拥有的对象跟随相机的移动。

希望这对您有所帮助。

关于java - jMonkeyEngine 相机跟随,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9365217/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com