Ejemplo n.º 1
0
        private void AdjustFlashlight()
        {
            if (_flashlight.CurrentWorld != null)
            {
                if (CurrentWorld.IsFirstPersonMode)
                {
                    Vector3 lookAt    = GetLookAtVector();
                    Vector3 middle    = this.GetCenterPointForAllHitboxes();
                    Vector3 lookAtRot = HelperRotation.RotateVector(lookAt, -70, Plane.Y);
                    middle.Y += Scale.Y / 3f;
                    Vector3 source = middle + lookAtRot * 0.8f;

                    _flashlight.SetPosition(source);
                    if (_flashlight.Type == LightType.Directional || _flashlight.Type == LightType.DirectionalShadow)
                    {
                        lookAt.Y = lookAt.Y - 0.02f;
                        _flashlight.SetTarget(middle + lookAt * 2f);
                    }
                }
                else
                {
                    Vector3 lookAt = GetLookAtVector();
                    Vector3 middle = this.GetCenterPointForAllHitboxes();
                    middle.Y += Scale.Y / 3f;
                    Vector3 source = middle + lookAt * 0.7f;
                    _flashlight.SetPosition(source);
                    if (_flashlight.Type == LightType.Directional || _flashlight.Type == LightType.DirectionalShadow)
                    {
                        lookAt.Y = lookAt.Y - 0.075f;
                        _flashlight.SetTarget(middle + lookAt * 0.8f);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private Vector3 DoCameraPosition(Vector2 m)
        {
            _currentCameraRotationDegrees.X += m.X * 40;
            _currentCameraRotationDegrees.Y += m.Y * 40;
            if (_currentCameraRotationDegrees.Y < -75)
            {
                _currentCameraRotationDegrees.Y = -75;
            }
            if (_currentCameraRotationDegrees.Y > 5)
            {
                _currentCameraRotationDegrees.Y = 5;
            }

            float lav_factor  = (0.00012f * (_currentCameraRotationDegrees.Y * _currentCameraRotationDegrees.Y) + 0.02099f * _currentCameraRotationDegrees.Y + 0.89190f);
            float lav_factor2 = _currentCameraRotationDegrees.Y >= -15 ? (_currentCameraRotationDegrees.Y + 15) / 20f : 0f;

            Vector3 offset1       = HelperRotation.RotateVector(GetLookAtVector(), -90, Plane.Y) * 1 + GetLookAtVector() * 5 * lav_factor;
            Vector3 offset2       = HelperRotation.RotateVector(GetLookAtVector(), -90, Plane.Y) * 1 + GetLookAtVector() * 2 + _offsetVertical * 2 * lav_factor2;
            Vector3 arcBallCenter = new Vector3(Position.X, GetCenterPointForAllHitboxes().Y, Position.Z);

            Vector3 newCamPos = HelperRotation.CalculateRotationForArcBallCamera(
                arcBallCenter,
                10f,
                _currentCameraRotationDegrees.X,
                _currentCameraRotationDegrees.Y,
                false,
                false);

            CurrentWorld.SetCameraPosition(newCamPos + offset1);
            CurrentWorld.SetCameraTarget(new Vector3(Position.X, GetCenterPointForAllHitboxes().Y, Position.Z) + offset2);

            return(offset2);
        }
Ejemplo n.º 3
0
        internal void Act()
        {
            long now = DeltaTime.Watch.ElapsedMilliseconds;

            if (KWEngine.CurrentWorld.IsFirstPersonMode)
            {
                Vector3 fpPos = KWEngine.CurrentWorld.GetFirstPersonObject().Position;
                fpPos.Y += KWEngine.CurrentWorld.GetFirstPersonObject().FPSEyeOffset;
                Quaternion tmp = HelperRotation.GetRotationForPoint(Position, fpPos);
                _rotation = Matrix4.CreateFromQuaternion(tmp * Turn180);
            }
            else
            {
                Quaternion tmp = HelperRotation.GetRotationForPoint(Position, KWEngine.CurrentWorld.GetCameraPosition());
                _rotation = Matrix4.CreateFromQuaternion(tmp * Turn180);
            }


            long diff = _lastUpdate < 0 ? 0 : now - _lastUpdate;

            _aliveInMS += diff;
            _frame      = (int)(_aliveInMS / 32);
            int frameloop = _frame % _info.Samples;

            if (_type == ParticleType.LoopSmoke1 || _type == ParticleType.LoopSmoke2 || _type == ParticleType.LoopSmoke3)
            {
                _frame = frameloop;
                float liveInPercent = _aliveInMS / (float)_durationInMS;
                // f(x) = -64000(x - 0.5)¹⁶ + 1
                _scaleFactor    = -64000f * (float)Math.Pow(liveInPercent - 0.5f, 16) + 1;
                _scaleCurrent.X = _scale.X * _scaleFactor;
                _scaleCurrent.Y = _scale.Y * _scaleFactor;
                _scaleCurrent.Z = _scale.Z * _scaleFactor;

                if (_aliveInMS > _durationInMS)
                {
                    KWEngine.CurrentWorld.RemoveParticleObject(this);
                }
            }
            else
            {
                if (_frame > _info.Samples - 1)
                {
                    KWEngine.CurrentWorld.RemoveParticleObject(this);
                }
            }

            _modelMatrix = Matrix4.CreateScale(_scaleCurrent) * _rotation * Matrix4.CreateTranslation(Position);
            _lastUpdate  = now;
        }
Ejemplo n.º 4
0
        public override void Act(KeyboardState ks, MouseState ms)
        {
            if (Position.Y < -5)
            {
                SetPosition(1, 10, 1);
                return;
            }

            Vector3 bodyCenter = new Vector3(Position.X, GetCenterPointForAllHitboxes().Y, Position.Z);


            Vector2 msMovement = CurrentWindow.GetMouseCursorMovement(ms);

            AddRotationY(-msMovement.X * 40);
            Vector3 cameraLav        = GetLookAtVector();
            Vector3 cameraLavRotated = HelperRotation.RotateVector(cameraLav, -90, Plane.Y);

            float currentSpeed = 0.1f * KWEngine.DeltaTimeFactor;


            if (ks[Key.A] || ks[Key.D] || ks[Key.W] || ks[Key.S])
            {
                if (ks[Key.W])
                {
                    MoveAlongVector(cameraLav, currentSpeed);
                }
                if (ks[Key.S])
                {
                    MoveAlongVector(cameraLav, -currentSpeed);
                }
                if (ks[Key.A])
                {
                    MoveAlongVector(-cameraLavRotated, currentSpeed);
                }
                if (ks[Key.D])
                {
                    MoveAlongVector(cameraLavRotated, currentSpeed);
                }
            }
            else
            {
            }
            MoveOffset(0, -0.1f, 0);

            DoCollisionDetection();

            Console.WriteLine(Position);
        }
Ejemplo n.º 5
0
        private void AdjustFPVWeapon()
        {
            if (fpvWeapon == null)
            {
                return;
            }

            Vector3 offset = HelperRotation.RotateVector(this.GetLookAtVector(), -90, Plane.Y);

            offset.Y *= 2f;
            offset.Z *= 0.5f;
            offset.X *= 0.5f;

            fpvWeapon.SetPosition(this.Position + this.GetLookAtVector() * 0.25f + offset * 0.01f);
            fpvWeapon.SetRotation(this.Rotation);
        }
 public override void Act(KeyboardState kb, MouseState ms)
 {
     if (kb[Key.Escape])
     {
         CurrentWindow.SetWorld(new GameWorldStart());
         return;
     }
     if (kb[Key.Left])
     {
         _degrees--;
         Vector3 newCamPos = HelperRotation.CalculateRotationAroundPointOnAxis(Vector3.Zero, 10, _degrees);
         SetCameraPosition(newCamPos.X, 5, newCamPos.Z);
     }
     if (kb[Key.Right])
     {
         _degrees++;
         Vector3 newCamPos = HelperRotation.CalculateRotationAroundPointOnAxis(Vector3.Zero, 10, _degrees);
         SetCameraPosition(newCamPos.X, 5, newCamPos.Z);
     }
 }
Ejemplo n.º 7
0
        public override void Act(KeyboardState ks, MouseState ms)
        {
            if (Position.Y < -5)
            {
                _momentum = 0;
                SetPosition(1, 10, 1);
                return;
            }

            Vector3 bodyCenter = new Vector3(Position.X, GetCenterPointForAllHitboxes().Y, Position.Z);


            Vector2 msMovement = CurrentWindow.GetMouseCursorMovement(ms);

            AddRotationY(-msMovement.X * 40);
            //Vector3 camTargetWithOffset = DoCameraPosition(msMovement);
            Vector3 cameraLav        = GetLookAtVector();
            Vector3 cameraLavRotated = HelperRotation.RotateVector(cameraLav, -90, Plane.Y);

            float currentSpeed = _speed * KWEngine.DeltaTimeFactor;


            if (ks[Key.A] || ks[Key.D] || ks[Key.W] || ks[Key.S])
            {
                if (ks[Key.W])
                {
                    MoveAlongVector(cameraLav, currentSpeed);
                }
                if (ks[Key.S])
                {
                    MoveAlongVector(cameraLav, -currentSpeed);
                }
                if (ks[Key.A])
                {
                    MoveAlongVector(-cameraLavRotated, currentSpeed);
                }
                if (ks[Key.D])
                {
                    MoveAlongVector(cameraLavRotated, currentSpeed);
                }

                _running   = true;
                _attacking = false;
            }
            else
            {
                if (_running)
                {
                    _percentage = 0;
                    _running    = false;
                }
            }

            if (_state == PlayerState.OnFloor && (ks[Key.Space] || ms[MouseButton.Right]))
            {
                if (!_upKeyPressed)
                {
                    _state        = PlayerState.Jump;
                    _percentage   = 0;
                    _momentum     = 0.35f;
                    _upKeyPressed = true;
                    _attacking    = false;
                }
            }
            else if (!(ks[Key.Space] || ms[MouseButton.Right]))
            {
                _upKeyPressed = false;
            }

            if (ks[Key.ShiftLeft] || ms[MouseButton.Left])
            {
                DoShoot(ms);
            }

            DoStates();
            DoCollisionDetection();
            DoAnimation();
        }
Ejemplo n.º 8
0
        public override void Act(KeyboardState ks, MouseState ms, float deltaTimeFactor)
        {
            bool runs = false;

            if (CurrentWorld.IsFirstPersonMode && CurrentWorld.GetFirstPersonObject().Equals(this))
            {
                float forward = 0;
                float strafe  = 0;
                if (ks[Key.A])
                {
                    strafe -= 1;
                    runs    = true;
                }
                if (ks[Key.D])
                {
                    strafe += 1;
                    runs    = true;
                }
                if (ks[Key.W])
                {
                    forward += 1;
                    runs     = true;
                }
                if (ks[Key.S])
                {
                    forward -= 1;
                    runs     = true;
                }
                MoveFPSCamera(ms);
                MoveAndStrafeFirstPerson(forward, strafe, 0.1f * deltaTimeFactor);
                FPSEyeOffset = 5;
                if (ks[Key.Q])
                {
                    MoveOffset(0, -0.2f, 0);
                }
                if (ks[Key.E])
                {
                    MoveOffset(0, +0.2f, 0);
                }
            }
            else
            {
                TurnTowardsXZ(GetMouseIntersectionPoint(ms, Plane.Y));
                Vector3 cameraLookAt = GetCameraLookAtVector();
                cameraLookAt.Y = 0;
                cameraLookAt.NormalizeFast();

                Vector3 strafe = HelperRotation.RotateVector(cameraLookAt, 90, Plane.Y);

                if (ks[Key.A])
                {
                    MoveAlongVector(strafe, 0.1f * deltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.D])
                {
                    MoveAlongVector(strafe, -0.1f * deltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.W])
                {
                    MoveAlongVector(cameraLookAt, 0.1f * deltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.S])
                {
                    MoveAlongVector(cameraLookAt, -0.1f * deltaTimeFactor);
                    runs = true;
                }

                if (ks[Key.T])
                {
                    MoveOffset(0, 0.2f * deltaTimeFactor, 0);
                }

                if (ks[Key.Q])
                {
                    _height += 0.5f;
                }
                if (ks[Key.E])
                {
                    _height -= 0.5f;
                }
            }

            if (IsMouseCursorInsideMyHitbox(ms))
            {
                SetColorOutline(0, 1, 0, 0.2f);
            }
            else
            {
                SetColorOutline(0, 1, 0, 0);
            }

            /*
             * if (ms.LeftButton == ButtonState.Pressed)
             * {
             *  GameObject o = PickGameObject(ms);
             *  Console.WriteLine(o);
             * }
             */

            MoveOffset(0, -0.1f * deltaTimeFactor, 0);
            List <Intersection> intersections = GetIntersections();

            foreach (Intersection i in intersections)
            {
                if (i.IsTerrain)
                {
                    SetPosition(Position.X, i.HeightOnTerrainSuggested, Position.Z);
                }
                else
                {
                    Position += i.MTV;
                }
            }

            AdjustFlashlight();
            AdjustAnimation(runs, deltaTimeFactor);

            Vector3 camPos = this.Position + new Vector3(50, _height, 50);

            camPos.Y = _height;
            CurrentWorld.SetCameraPosition(camPos);
            CurrentWorld.SetCameraTarget(Position.X, 0, Position.Z);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Setzt die Rotation des HUD-Objekts
 /// </summary>
 /// <param name="x">X-Rotation in Grad</param>
 /// <param name="y">Y-Rotation in Grad</param>
 public void SetRotation(float x, float y)
 {
     _rotation       = HelperRotation.GetQuaternionForEulerDegrees(x, y, 0);
     _rotationMatrix = Matrix4.CreateFromQuaternion(_rotation);
     UpdatePositions();
 }
Ejemplo n.º 10
0
        internal static void DrawCoordinateSystem(ref Matrix4 viewProjection)
        {
            if (CurrentWorld == null)
            {
                return;
            }

            CSScale = CurrentWorld.IsFirstPersonMode ? Vector3.Distance(CurrentWorld.GetFirstPersonObject().GetCenterPointForAllHitboxes(), CoordinateSystemCenter) : Vector3.Distance(CurrentWorld.GetCameraPosition(), CoordinateSystemCenter) / 6f;

            GL.UseProgram(RendererSimple.GetProgramId());
            Matrix4 _modelViewProjection;

            // Simple lines:
            CoordinateSystemMatrix = Matrix4.CreateScale(CSScale);
            Matrix4.Mult(ref CoordinateSystemMatrix, ref viewProjection, out _modelViewProjection);
            GL.UniformMatrix4(RendererSimple.GetUniformHandleMVP(), false, ref _modelViewProjection);
            foreach (string meshName in CoordinateSystem.Meshes.Keys)
            {
                GeoMesh mesh = CoordinateSystem.Meshes[meshName];

                GL.Uniform3(RendererSimple.GetUniformBaseColor(), mesh.Material.ColorDiffuse.X, mesh.Material.ColorDiffuse.Y, mesh.Material.ColorDiffuse.Z);

                GL.BindVertexArray(mesh.VAO);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.VBOIndex);
                GL.DrawElements(mesh.Primitive, mesh.IndexCount, DrawElementsType.UnsignedInt, 0);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

                GL.BindVertexArray(0);
            }

            // X
            CoordinateSystemMatrixX     = Matrix4.CreateScale(CSScale * 3f) * Matrix4.CreateFromQuaternion(HelperRotation.GetRotationForPoint(CoordinateSystemXOffset * CSScale, CurrentWorld.IsFirstPersonMode ? CurrentWorld.GetFirstPersonObject().GetCenterPointForAllHitboxes() : CurrentWorld.GetCameraPosition()));
            CoordinateSystemMatrixX.M41 = CoordinateSystemXOffset.X * CSScale * 1.05f;
            CoordinateSystemMatrixX.M42 = CoordinateSystemXOffset.Y;
            CoordinateSystemMatrixX.M43 = CoordinateSystemXOffset.Z;
            Matrix4.Mult(ref CoordinateSystemMatrixX, ref viewProjection, out _modelViewProjection);
            GL.UniformMatrix4(RendererSimple.GetUniformHandleMVP(), false, ref _modelViewProjection);
            foreach (string meshName in CoordinateSystemX.Meshes.Keys)
            {
                GeoMesh mesh = CoordinateSystemX.Meshes[meshName];

                GL.Uniform3(RendererSimple.GetUniformBaseColor(), mesh.Material.ColorDiffuse.X, mesh.Material.ColorDiffuse.Y, mesh.Material.ColorDiffuse.Z);

                GL.BindVertexArray(mesh.VAO);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.VBOIndex);
                GL.DrawElements(mesh.Primitive, mesh.IndexCount, DrawElementsType.UnsignedInt, 0);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

                GL.BindVertexArray(0);
            }

            // Y
            CoordinateSystemMatrixY     = Matrix4.CreateScale(CSScale * 3f) * Matrix4.CreateFromQuaternion(HelperRotation.GetRotationForPoint(CoordinateSystemYOffset * CSScale, CurrentWorld.IsFirstPersonMode ? CurrentWorld.GetFirstPersonObject().GetCenterPointForAllHitboxes() : CurrentWorld.GetCameraPosition()));
            CoordinateSystemMatrixY.M41 = CoordinateSystemYOffset.X;
            CoordinateSystemMatrixY.M42 = CoordinateSystemYOffset.Y * CSScale * 1.05f;
            CoordinateSystemMatrixY.M43 = CoordinateSystemYOffset.Z;
            Matrix4.Mult(ref CoordinateSystemMatrixY, ref viewProjection, out _modelViewProjection);
            GL.UniformMatrix4(RendererSimple.GetUniformHandleMVP(), false, ref _modelViewProjection);
            foreach (string meshName in CoordinateSystemY.Meshes.Keys)
            {
                GeoMesh mesh = CoordinateSystemY.Meshes[meshName];

                GL.Uniform3(RendererSimple.GetUniformBaseColor(), mesh.Material.ColorDiffuse.X, mesh.Material.ColorDiffuse.Y, mesh.Material.ColorDiffuse.Z);

                GL.BindVertexArray(mesh.VAO);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.VBOIndex);
                GL.DrawElements(mesh.Primitive, mesh.IndexCount, DrawElementsType.UnsignedInt, 0);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

                GL.BindVertexArray(0);
            }

            // Z
            CoordinateSystemMatrixZ     = Matrix4.CreateScale(CSScale * 3f) * Matrix4.CreateFromQuaternion(HelperRotation.GetRotationForPoint(CoordinateSystemZOffset * CSScale, CurrentWorld.IsFirstPersonMode ? CurrentWorld.GetFirstPersonObject().GetCenterPointForAllHitboxes() : CurrentWorld.GetCameraPosition()));
            CoordinateSystemMatrixZ.M41 = CoordinateSystemZOffset.X;
            CoordinateSystemMatrixZ.M42 = CoordinateSystemZOffset.Y;
            CoordinateSystemMatrixZ.M43 = CoordinateSystemZOffset.Z * CSScale * 1.05f;
            Matrix4.Mult(ref CoordinateSystemMatrixZ, ref viewProjection, out _modelViewProjection);
            GL.UniformMatrix4(RendererSimple.GetUniformHandleMVP(), false, ref _modelViewProjection);
            foreach (string meshName in CoordinateSystemZ.Meshes.Keys)
            {
                GeoMesh mesh = CoordinateSystemZ.Meshes[meshName];

                GL.Uniform3(RendererSimple.GetUniformBaseColor(), mesh.Material.ColorDiffuse.X, mesh.Material.ColorDiffuse.Y, mesh.Material.ColorDiffuse.Z);

                GL.BindVertexArray(mesh.VAO);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.VBOIndex);
                GL.DrawElements(mesh.Primitive, mesh.IndexCount, DrawElementsType.UnsignedInt, 0);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

                GL.BindVertexArray(0);
            }

            GL.UseProgram(0);
        }
Ejemplo n.º 11
0
        public override void Act(KeyboardState ks, MouseState ms)
        {
            if (Position.Y < -25)
            {
                SetPosition(0, 0, 0);
                return;
            }

            Vector3 bodyCenter = new Vector3(Position.X, GetCenterPointForAllHitboxes().Y, Position.Z);


            Vector2 msMovement = CurrentWindow.GetMouseCursorMovement(ms);

            AddRotationY(-msMovement.X * 40);
            Vector3 camTargetWithOffset = DoCameraPosition(msMovement);
            Vector3 cameraLav           = GetLookAtVector();
            Vector3 cameraLavRotated    = HelperRotation.RotateVector(cameraLav, -90, Plane.Y);

            float currentSpeed = _speed * KWEngine.DeltaTimeFactor;


            if (ks[Key.A] || ks[Key.D] || ks[Key.W] || ks[Key.S])
            {
                if (ks[Key.W])
                {
                    MoveAlongVector(cameraLav, currentSpeed);
                }
                if (ks[Key.S])
                {
                    MoveAlongVector(cameraLav, -currentSpeed);
                }
                if (ks[Key.A])
                {
                    MoveAlongVector(-cameraLavRotated, currentSpeed);
                }
                if (ks[Key.D])
                {
                    MoveAlongVector(cameraLavRotated, currentSpeed);
                }

                _running   = true;
                _attacking = false;
            }
            else
            {
                if (_running)
                {
                    _percentage = 0;
                    _running    = false;
                }
            }

            if (_state == PlayerState.OnFloor && (ks[Key.Space] || ms[MouseButton.Right]))
            {
                if (!_upKeyPressed)
                {
                    _state        = PlayerState.Jump;
                    _percentage   = 0;
                    _momentum     = 0.35f;
                    _upKeyPressed = true;
                    _attacking    = false;
                }
            }
            else if (!(ks[Key.Space] || ms[MouseButton.Right]))
            {
                _upKeyPressed = false;
            }



            //_sphere.SetPosition(target);

            if (ks[Key.ShiftLeft] || ms[MouseButton.Left])
            {
                DoShoot(ms);
                //_attacking = true;
                //_percentage = 0.25f;
            }
            //if (_attacking && _percentage >= 1)
            //{
            //    _attacking = false;
            //    _percentage = 0;
            //}



            DoStates();
            DoCollisionDetection();
            DoAnimation();

            /*
             * List<GameObject> objects = PickGameObjectsFromLookAtVector(GetLookAtVector() + new Vector3(0, 1, 0), 0);
             * foreach(GameObject g in objects)
             * {
             *  Console.WriteLine(CurrentWorld.GetCurrentTimeInMilliseconds() + ": " + g.Name);
             * }
             */
        }
Ejemplo n.º 12
0
        private void RotateS1()
        {
            Vector3 pos = HelperRotation.CalculateRotationAroundPointOnAxis(new Vector3(0, 0, 0), 2.5f, _s1Rotation, Plane.Z);

            _s1.SetPosition(pos);
        }