示例#1
0
        /// <summary>
        /// Rotates the entity to a target direction
        /// </summary>
        /// <param name="target">The target to be rotated to</param>
        /// <returns>Returns true of it faces the target</returns>
        public bool RotateHeadingToFacePosition(Vector2D target)
        {
            Vector2D toTarget = Vector2D.Vec2DNormalize(target - position);

            float angle = (float)Math.Acos(heading.Dot(toTarget));

            if (angle < 0.1)
            {
                return(true);
            }

            if (angle > maxTurnRate)
            {
                angle = maxTurnRate;
            }

            C2DMatrix RotationMatrix = new C2DMatrix();

            RotationMatrix.Rotate(angle * heading.Sign(toTarget));
            RotationMatrix.TransformVector2Ds(ref heading);
            RotationMatrix.TransformVector2Ds(ref velocity);

            side = heading.Perp();

            return(false);
        }
示例#2
0
        public bool RotateHeadingToFacePosition(Vector2D target)
        {
            Vector2D toTarget = Vector2D.Vec2DNormalize(target - Pos);

            double angle = Math.Acos(Heading.Dot(toTarget));

            if (angle < 0.2)
            {
                return(true);
            }

            if (angle > MaxTurnRate)
            {
                angle = MaxTurnRate;
            }

            C2DMatrix RotationMatrix = new C2DMatrix();

            RotationMatrix.Rotate((float)angle * Heading.Sign(toTarget));
            Vector2D heading  = Vector2D.Zero;
            Vector2D velocity = Vector2D.Zero;

            RotationMatrix.TransformVector2Ds(ref heading);
            RotationMatrix.TransformVector2Ds(ref velocity);
            Heading  = heading;
            Velocity = velocity;
            Side     = Heading.Perp();
            return(false);
        }
示例#3
0
        //--------------------------- RotateHeadingToFacePosition ---------------------
        //
        //  given a target position, this method rotates the entity's heading and
        //  side vectors by an amount not greater than m_dMaxTurnRate until it
        //  directly faces the target.
        //
        //  returns true when the heading is facing in the desired direction
        //-----------------------------------------------------------------------------
        public bool RotateHeadingToFacePosition(Vector2D target)
        {
            Vector2D toTarget = Vector2D.Vec2DNormalize(target - m_vPos);

            //first determine the angle between the heading vector and the target
            double angle = Math.Acos(m_vHeading.Dot(toTarget));

            //return true if the player is facing the target
            if (angle < 0.00001)
            {
                return(true);
            }

            //clamp the amount to turn to the max turn rate
            if (angle > m_dMaxTurnRate)
            {
                angle = m_dMaxTurnRate;
            }

            //The next few lines use a rotation matrix to rotate the player's heading
            //vector accordingly
            C2DMatrix RotationMatrix = new C2DMatrix();

            //notice how the direction of rotation has to be determined when creating
            //the rotation matrix
            RotationMatrix.Rotate(angle * m_vHeading.Sign(toTarget));

            RotationMatrix.TransformVector2D(m_vHeading);
            RotationMatrix.TransformVector2D(m_vVelocity);

            //finally recreate m_vSide
            m_vSide = m_vHeading.Perp();

            return(false);
        }
示例#4
0
        public static Vector2D PointToWorldSpace(Vector2D point, Vector2D agentHeading, Vector2D agentSide, Vector2D agentPosition)
        {
            Vector2D  transPoint   = point;
            C2DMatrix matTransform = new C2DMatrix();

            matTransform.Rotate(agentHeading, agentSide);
            matTransform.Translate(agentPosition.x, agentPosition.y);
            matTransform.TransformVector2Ds(ref transPoint);
            return(transPoint);
        }
示例#5
0
        public static Vector2D PointToWorldSpace(Vector2D point, Vector2D AgentHeading, Vector2D AgentSide, Vector2D AgentPosition)
        {
            //make a copy of the point
            Vector2D TransPoint = point;

            //create a transformation matrix
            C2DMatrix matTransform = new C2DMatrix();

            //rotate
            matTransform.Rotate(AgentHeading, AgentSide);

            //and translate
            matTransform.Translate(AgentPosition.X, AgentPosition.Y);

            //now transform the vertices
            matTransform.TransformVector2Ds(TransPoint);

            return(TransPoint);
        }