2012-11-24 174 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

谢谢,但我想通了另一种方式:)。但没有信用违规采取这种工作也很好!谢谢你的回答 –