[英]How to Rotate a Camera - Camera Rotation
I am wondering if there is a variable or way i could use to rotate the camera in my game. 我想知道我是否可以使用变量或方式来旋转相机。 I can move it along xyz axis's but i cannot figure out how to rotate it!
我可以沿xyz轴移动它,但是我不知道如何旋转它! :O
:O
Here are the variables: 以下是变量:
Model spaceShip;
float aspectRatio;
Vector3 modelPosition = Vector3.Zero;
float modelRotation = 0f;
Vector3 cameraPosition = new Vector3(0f, 50f, 5000f);
Here is how its draw(the model(a spaceship)): 这是它的绘制方式(模型(太空船)):
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();
}
and this aspect ratio is loaded in: 并且此宽高比加载到:
aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; AspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
您可以尝试围绕摄像机的视线方向矢量旋转场景的根容器(该根容器不应包含照相机,对于照相机,您应该在根的外部有另一个容器)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.