Example #1
0
        public void Reload()
        {
            reloading = true;

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearColor(ClearColor.X, ClearColor.Y, ClearColor.Z, ClearColor.W);

            scene.Dispose();

            Init(this.BaseURL, this.BaseMIME);

            ActiveCamera.Reset();

            reloading = false;
        }
Example #2
0
        // "Respawns" the player at a specific spawn point. Passing -1 will move the player to the next spawn point.
        public void RespawnPlayer(int index)
        {
            if (q3bsp.entities != null && camera != null && camera.playerMover != null)
            {
                String          spawn_point_param_name;
                List <Q3Entity> spawns;


                spawn_point_param_name = "info_player_deathmatch"; // Quake 3 bsp file
                spawns = q3bsp.entities.Where(e => e.name == spawn_point_param_name || e.classname == spawn_point_param_name).ToList();

                if (!spawns.Any())
                {
                    spawn_point_param_name = "info_player_start"; // TREMULOUS bsp file

                    spawns = q3bsp.entities.Where(e => e.name == spawn_point_param_name || e.classname == spawn_point_param_name).ToList();
                }



                if (index == -1)
                {
                    index = (lastIndex + 1) % spawns.Count;
                }
                lastIndex = index;

                Q3Entity spawnPoint = spawns[index]; //spawns.First(e => e.Index == index);
                //Entity spawnPoint = q3bsp.entities[spawn_point_param_name];

                float zAngle;
                float xAngle;

                if (spawnPoint.Fields.ContainsKey("angle"))
                {
                    zAngle = (float)((double)(spawnPoint.Fields["angle"]));
                }
                else
                {
                    zAngle = 0.0f;
                }

                zAngle  = -(zAngle);
                zAngle *= ((float)Math.PI / 180.0f) + ((float)Math.PI * 0.5f); // Negative angle in radians + 90 degrees

                xAngle = 0.0f;

                xAngle = (xAngle / 360f) * MathHelper.TwoPi;
                zAngle = (zAngle / 360f) * MathHelper.TwoPi + MathHelper.PiOver2 + MathHelper.PiOver4;

                Vector3 rotation = new Vector3(xAngle, 0.0f, zAngle);

                Vector3 origin = (Vector3)spawnPoint.Fields["origin"];
                origin.Z += 30; // Start a little ways above the floor

                camera.Reset();

                camera.SetOrigin(origin, rotation);

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

            slowFlySpeed  = Keyboard[Key.AltLeft];
            fastFlySpeed  = Keyboard[Key.ShiftLeft];
            movementSpeed = fastFlySpeed ? 10.0f : 0.3f;
            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 (WindowState == WindowState.Fullscreen)
                {
                    WindowState = WindowState.Normal;
                }

                //X3DProgram.Quit();
                System.Diagnostics.Process.GetCurrentProcess().Kill(); // Fast !
            }

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

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

                if (Keyboard[Key.W])
                {
                    ActiveCamera.Walk(playerDirectionMagnitude * movementSpeed);
                    translated = true;
                }
                if (Keyboard[Key.S])
                {
                    ActiveCamera.Walk(-playerDirectionMagnitude * movementSpeed);
                    translated = true;
                }
                if (Keyboard[Key.A])
                {
                    ActiveCamera.Strafe(playerDirectionMagnitude * movementSpeed);
                    translated = true;
                }
                if (Keyboard[Key.D])
                {
                    ActiveCamera.Strafe(-playerDirectionMagnitude * movementSpeed);
                    translated = true;
                }

                #region G.3 Emulate pointing device Key Bindings

                if (Keyboard[Key.Left])
                {
                    ActiveCamera.ApplyYaw(-playerDirectionMagnitude * movementSpeed);

                    rotated = true;
                }
                if (Keyboard[Key.Right])
                {
                    ActiveCamera.ApplyYaw(playerDirectionMagnitude * movementSpeed);

                    rotated = true;
                }
                if (Keyboard[Key.Up])
                {
                    ActiveCamera.ApplyPitch(-playerDirectionMagnitude * movementSpeed);
                    rotated = true;
                }
                if (Keyboard[Key.Down])
                {
                    ActiveCamera.ApplyPitch(playerDirectionMagnitude * movementSpeed);

                    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();
            }
        }