2012-02-20 5 views
2

저는 jMonkeyEngine으로 뭔가를 테스트하고 있습니다. 카메라를 상자 공간을 따라 가려고합니다. 여기 공식 지침을 따랐 : 다음 코드라고jMonkeyEngine camera follow

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

적용 할 때

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

는, 내가 거기에 배운 것을 나는 다음과 같은 코드를 생성 상자는 예상대로 움직이지만 카메라는 그대로 있습니다. 그래프는이 같은 같아야

  • rootNode를
    • B (박스) shipBase
      • shipNode
      • cameraNode

따라서 카메라는 이미 shipNode에 바인딩되어 있어야합니다. 내가 뭘 놓치고 있니?

+0

왜 카메라가 배에 부착되어 있지만 움직이는 물체 인 경우 카메라를 움직여야합니까? –

+0

내가 잘못 된 것을보고 있지만 shipNode가 자식이므로 shipBase (상자)도 함께 움직입니다. 아직 shipNode의 자식 인 cameraNode는 여전히 남아 있습니다. – Vampnik

+0

미안하지만 나는 배가 또한 움직이고 있다는 사실을 놓쳤다. –

답변

4

입력 한 튜토리얼을 읽는 것은 오타가있는 것 같습니다. 당신은이 :

cameraNode.setControlDir(ControlDirection.CameraToSpatial); 

그러나, 튜토리얼이 있습니다

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

튜토리얼에서 아래로 낮은 이들 2 ControlDirections의 차이를 정의합니다. 튜토리얼에서 제공하는 것은 카메라가 객체의 움직임을 따르는 반면, 객체가있는 객체는 카메라의 움직임을 따릅니다.

희망이 도움이됩니다.