Example #1
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (!Focused)
            {
                return;
            }

            KeyboardState k = OpenTK.Input.Keyboard.GetState();
            MouseState    m = OpenTK.Input.Mouse.GetState();

            bool isShiftDown = false;

            if (k[Key.LShift] || k[Key.RShift])
            {
                isShiftDown = true;
            }

            //TODO make cam speed/shift speedup controllable from GUI
            float camSpeed  = 10f * (float)e.Time * (isShiftDown ? 3f : 1f);
            float zoomSpeed = (float)Math.PI * (float)e.Time * (isShiftDown ? 0.2f : 0.1f);

            if (k[Key.W])
            {
                cam.Move(-camSpeed);
            }
            if (k[Key.A])
            {
                cam.Strafe(-camSpeed);
            }
            if (k[Key.S])
            {
                cam.Move(camSpeed);
            }
            if (k[Key.D])
            {
                cam.Strafe(camSpeed);
            }
            if (k[Key.Q])
            {
                cam.Elevate(camSpeed);
            }
            if (k[Key.E])
            {
                cam.Elevate(-camSpeed);
            }
            if (k[Key.Z])
            {
                zoom += zoomSpeed;
                if (zoom > MathHelper.PiOver2)
                {
                    zoom = MathHelper.PiOver2;
                }
            }
            if (k[Key.C])
            {
                zoom -= zoomSpeed;
                if (zoom < 0.002f)
                {
                    zoom = 0.002f;
                }
            }

            if (m[MouseButton.Right])
            {
                cam.RotatePitch((m.X - prevM.X) * (float)e.Time * 2f);
                cam.RotateHeading((prevM.Y - m.Y) * (float)e.Time * 2f);
            }

            float   aspect = Width / (float)Height;
            Matrix4 persp  = Matrix4.CreatePerspectiveFieldOfView(zoom, aspect, 0.1f, 1000f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref persp);
            GL.MatrixMode(MatrixMode.Modelview);
            cam.LoadView();
            if (crowd != null)
            {
                crowd.Update((float)e.Time);
            }

            prevK = k;
            prevM = m;

            if (gwenRenderer.TextCacheSize > 1000)
            {
                gwenRenderer.FlushTextCache();
            }
        }
Example #2
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (!Focused)
            {
                return;
            }

            KeyboardState k = OpenTK.Input.Keyboard.GetState();
            MouseState    m = OpenTK.Input.Mouse.GetState();

            bool isShiftDown = false;

            if (k[Key.LShift] || k[Key.RShift])
            {
                isShiftDown = true;
            }

            //TODO make cam speed/shift speedup controllable from GUI
            float camSpeed  = 5f * (float)e.Time * (isShiftDown ? 3f : 1f);
            float zoomSpeed = (float)Math.PI * (float)e.Time * (isShiftDown ? 0.2f : 0.1f);

            if (k[Key.W])
            {
                cam.Move(-camSpeed);
            }
            if (k[Key.A])
            {
                cam.Strafe(-camSpeed);
            }
            if (k[Key.S])
            {
                cam.Move(camSpeed);
            }
            if (k[Key.D])
            {
                cam.Strafe(camSpeed);
            }
            if (k[Key.Q])
            {
                cam.Elevate(camSpeed);
            }
            if (k[Key.E])
            {
                cam.Elevate(-camSpeed);
            }
            if (k[Key.Z])
            {
                zoom += zoomSpeed;
                if (zoom > MathHelper.PiOver2)
                {
                    zoom = MathHelper.PiOver2;
                }
            }
            if (k[Key.C])
            {
                zoom -= zoomSpeed;
                if (zoom < 0.002f)
                {
                    zoom = 0.002f;
                }
            }

            if (m[MouseButton.Right])
            {
                cam.RotatePitch((m.X - prevM.X) * (float)e.Time * 2f);
                cam.RotateHeading((prevM.Y - m.Y) * (float)e.Time * 2f);
            }

            float   aspect = Width / (float)Height;
            Matrix4 persp  = Matrix4.CreatePerspectiveFieldOfView(zoom, aspect, 0.1f, 1000f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref persp);
            GL.MatrixMode(MatrixMode.Modelview);
            cam.LoadView();

            if (hasGenerated && displayMode == DisplayMode.Crowd)
            {
                crowd.Update((float)e.Time);

                //Iterate through each crowd agent

                /*for (int j = 0; j < numActiveAgents; j++)
                 * {
                 *      Crowd.CrowdAgent ag = crowd.GetAgent(j);
                 *      if (!ag.Active)
                 *              continue;
                 *
                 *      //update agent movement trail
                 *      trails[j].HTrail = (trails[j].HTrail + 1) % AGENT_MAX_TRAIL;
                 *      trails[j].Trail[trails[j].HTrail] = ag.NPos;
                 * }*/
            }

            prevK = k;
            prevM = m;

            if (gwenRenderer.TextCacheSize > 1000)
            {
                gwenRenderer.FlushTextCache();
            }
        }