private void ApplyKeyBindings(FrameEventArgs e)
        {
            Vector3 direction = Vector3.Zero;
            bool    rotated   = false;

            slowFlySpeed  = Keyboard[Key.AltLeft];
            fastFlySpeed  = Keyboard[Key.ShiftLeft];
            movementSpeed = fastFlySpeed ? 10.0f : 1.0f;
            movementSpeed = slowFlySpeed ? 0.01f : movementSpeed;



            // Calibrator (for translation debugging)
            if (Keyboard[Key.Number1])
            {
                ActiveCamera.calibTrans.X += ActiveCamera.calibSpeed.X;
            }
            if (Keyboard[Key.Number2])
            {
                ActiveCamera.calibTrans.X -= ActiveCamera.calibSpeed.X;
            }
            if (Keyboard[Key.Number3])
            {
                ActiveCamera.calibTrans.Y += ActiveCamera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number4])
            {
                ActiveCamera.calibTrans.Y -= ActiveCamera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number5])
            {
                ActiveCamera.calibTrans.Z += ActiveCamera.calibSpeed.Z;
            }
            if (Keyboard[Key.Number6])
            {
                ActiveCamera.calibTrans.Z -= ActiveCamera.calibSpeed.Z;
            }

            // Calibrator (for orientation debugging)
            if (Keyboard[Key.Number6])
            {
                ActiveCamera.calibOrient.X += ActiveCamera.calibSpeed.X;
            }
            if (Keyboard[Key.Number7])
            {
                ActiveCamera.calibOrient.X -= ActiveCamera.calibSpeed.X;
            }
            if (Keyboard[Key.Number8])
            {
                ActiveCamera.calibOrient.Y += ActiveCamera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number9])
            {
                ActiveCamera.calibOrient.Y -= ActiveCamera.calibSpeed.Y;
            }
            if (Keyboard[Key.Minus])
            {
                ActiveCamera.calibOrient.Z += ActiveCamera.calibSpeed.Z;
            }
            if (Keyboard[Key.Plus])
            {
                ActiveCamera.calibOrient.Z -= ActiveCamera.calibSpeed.Z;
            }



            if (Keyboard[Key.Escape] || Keyboard[Key.Q])
            {
                // QUIT APPLICATION
                if (window.WindowState == WindowState.Fullscreen)
                {
                    window.WindowState = WindowState.Normal;
                }

                X3DProgram.Quit();
            }
            if (Keyboard[Key.P])
            {
                // LOAD NEW SCENE
                if (window.WindowState == WindowState.Fullscreen)
                {
                    window.WindowState = WindowState.Normal;
                }

                X3DProgram.Restart();
            }

            if (Keyboard[Key.R])
            {
                // RESET CAMERA POSITION+ORIENTATION
                ActiveCamera.Reset();
            }

            if (NavigationInfo.NavigationType != NavigationType.Examine)
            {
                if (Keyboard[Key.T])
                {
                    ActiveCamera.Fly(playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.G])
                {
                    ActiveCamera.Fly(-playerDirectionMagnitude * movementSpeed);
                }

                if (Keyboard[Key.W])
                {
                    ActiveCamera.Walk(playerDirectionMagnitude * movementSpeed);
                    //direction += ActiveCamera.Direction * playerDirectionMagnitude;
                }
                if (Keyboard[Key.S])
                {
                    ActiveCamera.Walk(-playerDirectionMagnitude * movementSpeed);
                    //direction -= ActiveCamera.Direction * playerDirectionMagnitude;
                }
                if (Keyboard[Key.A])
                {
                    ActiveCamera.Strafe(playerDirectionMagnitude * movementSpeed);
                    //ActiveCamera.Right = ActiveCamera.Up.Cross(ActiveCamera.Direction);
                    //direction += ActiveCamera.Right * playerDirectionMagnitude;
                }
                if (Keyboard[Key.D])
                {
                    ActiveCamera.Strafe(-playerDirectionMagnitude * movementSpeed);
                    //ActiveCamera.Right = ActiveCamera.Up.Cross(ActiveCamera.Direction);
                    //direction -= ActiveCamera.Right * playerDirectionMagnitude;
                }

                #region G.3 Emulate pointing device Key Bindings

                if (Keyboard[Key.Left])
                {
                    //ActiveCamera.Horizon();
                    //ActiveCamera.Yaw(-10.0f * 0.007f);
                    ActiveCamera.ApplyYaw(-playerDirectionMagnitude * 0.3f);
                    //ActiveCamera.ApplyRotation();

                    //this.heading += 1.0f;
                    //this.yrot = this.heading;

                    rotated = true;
                }
                if (Keyboard[Key.Right])
                {
                    //ActiveCamera.Horizon();
                    //ActiveCamera.Yaw(10.0f * 0.007f);
                    ActiveCamera.ApplyYaw(playerDirectionMagnitude * 0.3f);
                    //ActiveCamera.ApplyRotation();
                    //this.heading -= 1.0f;
                    //this.yrot = this.heading;

                    rotated = true;
                }
                if (Keyboard[Key.Up])
                {
                    //ActiveCamera.Pitch(10.0f * 0.007f);
                    ActiveCamera.ApplyPitch(-playerDirectionMagnitude * 0.3f);
                    //ActiveCamera.ApplyRotation();

                    //this.xpos += (float)Math.Sin(this.heading * Math.PI / 180.0) * 0.05f;
                    //this.zpos += (float)Math.Cos(this.heading * Math.PI / 180.0) * 0.05f;
                    //if (this.walkbiasangle >= 359.0f)
                    //    this.walkbiasangle = 0.0f;
                    //else
                    //    this.walkbiasangle -= 5.0f;
                    //this.walkbias = (float)Math.Sin(this.walkbiasangle * Math.PI / 180.0) / 10.0f;

                    rotated = true;
                }
                if (Keyboard[Key.Down])
                {
                    //ActiveCamera.Pitch(-10.0f * 0.007f);
                    ActiveCamera.ApplyPitch(playerDirectionMagnitude * 0.3f);
                    //ActiveCamera.ApplyRotation();

                    //this.xpos -= (float)Math.Sin(this.heading * Math.PI / 180.0) * 0.05f;
                    //this.zpos -= (float)Math.Cos(this.heading * Math.PI / 180.0) * 0.05f;
                    //if (this.walkbiasangle >= 359.0f)
                    //    this.walkbiasangle = 0.0f;
                    //else
                    //    this.walkbiasangle += 10.0f;
                    //this.walkbias = (float)Math.Sin(this.walkbiasangle * Math.PI / 180.0) / 10.0f;

                    rotated = true;
                }

                if (Keyboard[Key.Number0])
                {
                    ActiveCamera.ApplyRoll(-0.1f);
                    rotated = true;
                }
                if (Keyboard[Key.Number9])
                {
                    ActiveCamera.ApplyRoll(0.1f);
                    rotated = true;
                }

                #endregion
            }

            if (rotated)
            {
                ActiveCamera.ApplyRotation();
            }
        }
Exemple #2
0
        public void Render(FrameEventArgs e)
        {
            if (reloading)
            {
                return;
            }

            _prev = DateTime.Now;
            GL.Disable(EnableCap.Lighting);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearColor(ClearColor.X, ClearColor.Y, ClearColor.Z, ClearColor.W);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthMask(true);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.PointSize(6.0f);
            //GL.Enable(EnableCap.Blend);

            ActiveCamera.ApplyTransformations();



            if (scene != null && scene.SceneGraph.Loaded)
            {
                RenderingContext rc = new RenderingContext();
                rc.View = View.CreateViewFromWindow(this.window);
                rc.Time = e.Time;
                rc.matricies.worldview  = Matrix4.Identity;
                rc.matricies.projection = ActiveCamera.Projection;

                rc.matricies.modelview   = Matrix4.Identity;
                rc.matricies.orientation = Quaternion.Identity;
                rc.cam      = ActiveCamera;
                rc.Keyboard = this.Keyboard;

                // Apply the current Viewpoint
                Viewpoint.Apply(rc, Viewpoint.CurrentViewpoint);



                Engine.Runtime.Draw(scene.SceneGraph, rc);

                if (showCrosshair && NavigationInfo.NavigationType != NavigationType.Examine)
                {
                    rc.PushMatricies();
                    this._crosshair.Render(rc);
                    rc.PopMatricies();
                }
            }
            else
            {
                X3DProgram.Restart();
            }

            if (e != null)
            {
                UpdateTitle(e);
            }

#if VSYNC_ACTIVE
            System.Threading.Thread.Sleep(1);
#else
#endif
        }