在XNA中控制3个宇宙飞船

问题描述

| 当我控制1轴的飞船时,一切都很好,即,深度(z)和z平面上的旋转360度,即2轴。我后面也有一个摄像头,必须保持其位置。当第三名到位时,一切都会变糟。让我给你看一些代码: 这是失败的部分: 飞船的绘制方法:
public void Draw(Matrix view,Matrix projection)
        {
public float ForwardDirection { get; set; }
        public float VerticalDirection { get; set; }

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

            Matrix worldMatrix = Matrix.Identity;
            Matrix worldMatrix2 = Matrix.Identity;

            Matrix rotationYMatrix = Matrix.CreateRotationY(ForwardDirection);
            Matrix rotationXMatrix = Matrix.CreateRotationX(VerticalDirection); // me

            Matrix translateMatrix = Matrix.CreateTranslation(Position);

            worldMatrix = rotationYMatrix * translateMatrix;
            worldMatrix2 = rotationXMatrix * translateMatrix;
            //worldMatrix*= rotationXMatrix;

            foreach (ModelMesh mesh in Model.Meshes) //NEED TO FIX THIS
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World =
                        worldMatrix * transforms[mesh.ParentBone.Index]; ; //position
                    //effect.World =
                        //worldMatrix2 * transforms[mesh.ParentBone.Index]; ; //position
                    effect.View = view; //camera
                    effect.Projection = projection; //2d to 3d

                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;
                }
                mesh.Draw();
            }
        }
对于多余的轴,实现了worldMatrix2,我不知道如何与其他轴组合。我会乘吗?也: 相机更新方法有一个类似的问题:
public void Update(float avatarYaw,float avatarXaw,Vector3 position,float aspectRatio)
        {
            //Matrix rotationMatrix = Matrix.CreateRotationY(avatarYaw);
            Matrix rotationMatrix2 = Matrix.CreateRotationX(avatarXaw);

            //Vector3 transformedheadOffset =
                //Vector3.Transform(AvatarHeadOffset,rotationMatrix);

            Vector3 transformedheadOffset2 = Vector3.Transform(AvatarHeadOffset,rotationMatrix2);
            //Vector3 transformedheadOffset2 = Vector3.Transform(transformedheadOffset,rotationMatrix2);


            //Vector3 transformedReference =
                //Vector3.Transform(TargetOffset,rotationMatrix);


            Vector3 transformedReference2 = Vector3.Transform(TargetOffset,rotationMatrix2);
            //Vector3 transformedReference2 = Vector3.Transform(transformedReference,rotationMatrix2);


            Vector3 cameraPosition = position + transformedheadOffset2;  /** + transformedheadOffset;  */
            Vector3 cameraTarget = position + transformedReference2;  /** +  transformedReference;  */

            //Calculate the camera\'s view and projection 
            //matrices based on current values.
            ViewMatrix =
                Matrix.CreateLookAt(cameraPosition,cameraTarget,Vector3.Up);
            ProjectionMatrix =
                Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.ToRadians(GameConstants.ViewAngle),aspectRatio,GameConstants.NearClip,GameConstants.FarClip);
        }
    }
最后是Game类更新的方法:
spaceship.Update(currentGamePadState,currentKeyboardState); // this will be cahnged when asteroids are placed in the game,by adding a new parameter with asteroids.
            float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
            gameCamera.Update(spaceship.ForwardDirection,spaceship.VerticalDirection,spaceship.Position,aspectRatio);
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)