コード例 #1
0
        /// <summary>
        /// 更新摄像机状态
        /// </summary>
        /// <param name="gameTime"></param>
        private void UpdateCameraState(GameTime gameTime)
        {
            if (m_CameraState.CameraType == CameraState.ENUM_CameraType.eCT_AutoRotating)
            {
                m_fCameraAngle += 0.6f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else if (m_CameraState.CameraType == CameraState.ENUM_CameraType.eCT_Static)
            {
                m_fCameraAngle = 0.0f;
            }

            if (m_CameraState.CameraType == CameraState.ENUM_CameraType.eCT_AutoRotating ||
                m_CameraState.CameraType == CameraState.ENUM_CameraType.eCT_Static)
            {
                Chunk currentChunk = GetCurrentChunk();
                var   dist         = currentChunk == null ? 3 : currentChunk.SizeZ + 80;
                m_Camera.TargetDistance = dist;

                // 更新摄像机
                m_Camera.Update();

                // 更新模型的世界矩阵
                m_WorldMatrix = Matrix.CreateRotationX(m_fCameraAngle) * Matrix.CreateRotationY(m_fCameraAngle) * Matrix.CreateRotationZ(m_fCameraAngle);
            }
        }
コード例 #2
0
ファイル: LightingGame.cs プロジェクト: asiftastos/HabiCS
        protected override void OnUpdateFrame(FrameEventArgs args)
        {
            base.OnUpdateFrame(args);

            if (KeyboardState.IsKeyDown(Keys.E))
            {
                _camera.Rotate(0.5f * args.Time);
            }
            if (KeyboardState.IsKeyDown(Keys.Q))
            {
                _camera.Rotate(-0.5f * args.Time);
            }
            if (KeyboardState.IsKeyDown(Keys.D))
            {
                _camera.Move(0.5f * args.Time, _camera.Right);
            }
            if (KeyboardState.IsKeyDown(Keys.A))
            {
                _camera.Move(-0.5f * args.Time, _camera.Right);
            }
            if (KeyboardState.IsKeyDown(Keys.W))
            {
                _camera.Move(-0.5f * args.Time, _camera.Forward);
            }
            if (KeyboardState.IsKeyDown(Keys.S))
            {
                _camera.Move(0.5f * args.Time, _camera.Forward);
            }

            _camera.Update(args.Time);
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: CartBlanche/MGVoxelViewer
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // We must call StartFrame at the top of Update to indicate to the TimeRuler
            // that a new frame has started.
            DebugSystem.Instance.TimeRuler.StartFrame();

            // We can now begin measuring our Update method
            DebugSystem.Instance.TimeRuler.BeginMark("Update", Color.Blue);

            //Camera
            m_cam.Update(0);

            //Rotation
            m_fAngle += (float)(gameTime.ElapsedGameTime.Milliseconds / 1000.0);

            //Update VoxelBrush world Matrix
            if (m_voxelBrush != null)
            {
                var mtx = Matrix.CreateTranslation(m_voxelBrush.m_vec3Origin);
                mtx *= Matrix.CreateRotationY(m_fAngle);

                m_voxelBrush.m_worldMtx = mtx;
            }

            // End measuring the Update method
            DebugSystem.Instance.TimeRuler.EndMark("Update");

            base.Update(gameTime);
        }
コード例 #4
0
        public FKGameState(List <string> modelNames, List <Chunk> modelChunks)
        {
            m_RenderState            = new RenderState();
            m_RenderState.RenderType = RenderState.ENUM_RenderType.eRS_SimpleRender;
            m_CameraState            = new CameraState();
            m_CameraState.CameraType = CameraState.ENUM_CameraType.eCT_Static;
            m_RasterizerState        = new RasterizerState {
                CullMode = CullMode.CullCounterClockwiseFace,
                FillMode = FillMode.WireFrame
            };
            m_ModelNameList  = modelNames;
            m_ModelChunkList = modelChunks;

            // 创建基本图元
            m_DefaultGeoPrimitiveNameList = Utils.GetDefaultGeoPrimitiveNameList();

            m_DefaultGeoPrimitiveList = new List <GeometricPrimitive>();
            m_DefaultGeoPrimitiveList.Add(new CubePrimitive(GraphicsDevice()));
            m_DefaultGeoPrimitiveList.Add(new SpherePrimitive(GraphicsDevice()));
            m_DefaultGeoPrimitiveList.Add(new TorusPrimitive(GraphicsDevice()));
            m_DefaultGeoPrimitiveList.Add(new TeapotPrimitive(GraphicsDevice()));

            // 设置默认对象
            m_nCurrentGeoPrimitiveIndex = 0;
            m_nCurrentChunkIndex        = int.MaxValue;
            m_WorldMatrix = Matrix.Identity;

            // 重计算
            m_Camera = new OrbitCamera(Program.s_GameInstance);
            m_Camera.Update();
        }
コード例 #5
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            camera.Update(gameTime);

            base.Update(gameTime);
        }