Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }