简体   繁体   中英

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! :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;

您可以尝试围绕摄像机的视线方向矢量旋转场景的根容器(该根容器不应包含照相机,对于照相机,您应该在根的外部有另一个容器)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM