2012-11-24 220 views
1

我想知道是否有一個變量或方式我可以用來旋轉我的遊戲中的相機。我可以沿xyz軸移動它,但我無法弄清楚如何旋轉它! :o如何旋轉相機 - 相機旋轉

下面是變量:

Model spaceShip; 
    float aspectRatio; 
    Vector3 modelPosition = Vector3.Zero; 
    float modelRotation = 0f; 

    Vector3 cameraPosition = new Vector3(0f, 50f, 5000f); 

下面是它的平局(模型(飛船)):

 Matrix[] transforms = new Matrix[spaceShip.Bones.Count]; 
     spaceShip.CopyAbsoluteBoneTransformsTo(transforms); 

     foreach (ModelMesh mesh in spaceShip.Meshes) 
     { 
      foreach (BasicEffect effect in mesh.Effects) 
      { 
       effect.EnableDefaultLighting(); 
       effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(this.modelRotation) * Matrix.CreateTranslation(this.modelPosition); 
       effect.View = Matrix.CreateLookAt(this.cameraPosition, Vector3.Zero, Vector3.Up); 
       effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), aspectRatio, 1f,200000f); 
      } 
      mesh.Draw(); 
     } 

和這個長寬比被加載在:

aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;

+0

的可能重複: HTTP:/ /stackoverflow.com/questions/5906907/xna-rotate-camera-around-its-createlookat-target 另外,看看這個例子:http://msdn.microsoft.com/en-us/library/bb197901.aspx – surfen

回答

0

你可以試着旋轉場景的根容器(這不應該包含攝像頭,攝像頭,你應該有根之外的另一個容器)周圍的攝像機觀察方向矢量

+0

謝謝,但我想通了另一種方式:)。但沒有信用違規採取這種工作也很好!謝謝你的回答 –