コード例 #1
0
        public override ICamera Clone()
        {
            var r = new FreeCamera(Position, _screenWidth, _screenHeight)
                        {
                            //                Angle = Angle,
                            AspectRatio = AspectRatio,
                            FarPlane = FarPlane,
                            FieldOfView = FieldOfView,
                            Frustum = Frustum,
                            LookAt = LookAt,
                            NearPlane = NearPlane,
                            Projection = Projection,
                            Speed = Speed,
                            TurnSpeed = TurnSpeed,
                            LookAtTarget = LookAtTarget,
                            View = View,
                            WoldViewProj = WoldViewProj,
                            World = World
                        };

            return r;
        }
コード例 #2
0
        private void InitCamera(CameraType type, Vector3 cameraPos, ICameraTarget target)
        {
            Components.Remove(_cockpitMesh);

            #region Handle different implementations

            if (type == CameraType.Fixed)
            {
                Camera = new FixedCamera
                             {
                                 FieldOfView = MathHelper.ToRadians(45),
                                 Position = cameraPos,
                             };
            }
            else if (type == CameraType.Chase)
            {
                Camera = new ChaseCamera
                             {
                                 DesiredPositionOffset = new Vector3(0.0f, 0.5f, 3.5f),
                                 LookAtOffset = new Vector3(0.0f, 0.0f, 0.0f),
                                 Damping = 600,
                                 Stiffness = 3000,
                                 IsElastic = true,
                                 FieldOfView = MathHelper.ToRadians(45),
                                 Position = cameraPos,
                             };
            }
            else if (type == CameraType.Free)
            {
                Camera = new FreeCamera(cameraPos, _screenWidth, _screenHeight)
                             {
                                 FieldOfView = MathHelper.ToRadians(45),
                                 Position = cameraPos,
                             };
            }
            else if (type == CameraType.Cockpit)
            {
                var offset = new Vector3(0, -0.1f, 0);
                Camera = new CockpitCamera(target, offset, _screenWidth, _screenHeight)
                             {
                                 FieldOfView = MathHelper.ToRadians(120),
                                 CockpitMesh = _cockpitMesh,
                             };
                Components.Add(_cockpitMesh);
            }
            else
                throw new NotImplementedException("Unknown camera type");

            #endregion


            if (target == null)
                Camera.LookAtTarget = new WorldDummy(Vector3.Zero);
            else
                Camera.LookAtTarget = target;


            Camera.NearPlane = 0.1f;
            Camera.FarPlane = 10000;
            Camera.AspectRatio = (float) _graphics.GraphicsDevice.Viewport.Width/
                                 _graphics.GraphicsDevice.Viewport.Height;
            Camera.Reset();
        }