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;

4

1 回答 1

0

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

于 2012-11-27T14:58:51.793 回答