Exemplo n.º 1
0
        public void UpdatePos(GameTime gameTime, CTerrain terrain)
        {
            if (!_isCollisioned)
            {
                _fallElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds;

                _pos += (5.6f * _direction + 0.70f * _fallElapsedTime * Vector3.Down) * (float)gameTime.TotalGameTime.Seconds * 0.018f;

                _model._modelRotation = _pos - _model._modelPosition;
                _model._modelRotation.Normalize();

                _model._modelPosition = _pos;

                Ray ray = new Ray(_pos, _model._modelRotation);

                int   modelId;
                float Steepness;

                float?modelIntersectsDist = Display3D.CModelManager.CheckRayIntersectsModel(ray, out modelId, _damage, 0.5f);
                if (modelIntersectsDist != null)
                {
                    _isCollisioned        = true;
                    _model._modelPosition = _pos + _model._modelRotation * (float)modelIntersectsDist;
                }
                else if (_pos.Y - terrain.GetHeightAtPosition(_pos.X, _pos.Z, out Steepness, false) <= 0.5f)
                {
                    _isCollisioned        = true;
                    _model._modelPosition = new Vector3(_pos.X, terrain.GetHeightAtPosition(_pos.X, _pos.Z, out Steepness, false), _pos.Z);
                }
            }
        }
Exemplo n.º 2
0
 public static void updateProjectileList(GameTime gameTime, CTerrain terrain)
 {
     // Change position/rotation of all arrows above the terrain
     foreach (Display3D.CProjectile projectile in _thrownProjectiles)
     {
         projectile.UpdatePos(gameTime, terrain);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize the class
        /// </summary>
        /// <param name="device">GraphicsDevice class</param>
        /// <param name="cameraPos">Default position of the camera</param>
        /// <param name="target">Default target of the camera</param>
        /// <param name="nearClip">Closest elements to be rendered</param>
        /// <param name="farClip">Farthest elements to be rentered</param>
        /// <param name="camVelocity">Camera movement speed</param>
        /// <param name="isCamFrozen">Camera Frozen or not</param>
        /// <param name="freeCam">Is the camera free of physics or not</param>
        /// /// <param name="camVelocity">Give an map (heightmap) instance</param>
        public CCamera(GraphicsDevice device, Vector3 cameraPos, Vector3 target, float nearClip, float farClip, bool isCamFrozen, bool freeCam = false, CTerrain map = null, bool[] componentUsages = null)
        {
            this._graphics = device;
            _Viewport      = device.Viewport;
            _aspectRatio   = _graphics.Viewport.AspectRatio; // 16::9 - 4::3 etc

            this._nearClip = nearClip;
            this._farClip  = farClip;

            this._cameraPos    = cameraPos;
            this._cameraTarget = target;

            this._pitch = 0f;
            this._yaw   = 0f;
            this._roll  = 0f;

            this._elapsedStepTime         = 0;
            this._isPitchShiftedStepSound = false;

            this.isCamFrozen = isCamFrozen;
            this.isFreeCam   = freeCam;

            //this._physicsMap = new Game.CPhysics2(9.81f / 500, _map, _playerHeight);
            this._physicsMap = new Game.CPhysics();

            if (map != null)
            {
                _physicsMap.LoadContent(_playerHeight, componentUsages);
                _physicsMap._terrain = map;
            }

            this._up          = Vector3.Up;
            this._right       = Vector3.Cross(Vector3.Forward, _up);
            this._translation = Vector3.Zero;

            this._middleScreen = new Point(_graphics.Viewport.Width / 2, _graphics.Viewport.Height / 2);

            _isMoving = false;

            _view = Matrix.CreateLookAt(cameraPos, target, Vector3.Up);

            fieldOfView     = MathHelper.ToRadians(40);
            _projection     = Matrix.CreatePerspectiveFieldOfView(fieldOfView, _aspectRatio, _nearClip, _farClip);
            _nearProjection = Matrix.CreatePerspectiveFieldOfView(fieldOfView, _aspectRatio, 0.02f, 1f);

            generateFrustum();
        }