//-------------------------- Vec2DRotateAroundOrigin -------------------------- // // rotates a vector ang rads around the origin //----------------------------------------------------------------------------- public static void Vec2DRotateAroundOrigin(Vector2D v, double ang) { //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); //rotate matTransform.Rotate(ang); //now transform the object's vertices matTransform.TransformVector2D(v); }
//--------------------- VectorToWorldSpace -------------------------------- // // Transforms a vector from the agent's local space into world space //------------------------------------------------------------------------ public static Vector2D VectorToWorldSpace(Vector2D vec, Vector2D AgentHeading, Vector2D AgentSide) { //make a copy of the point Vector2D TransVec = new Vector2D(vec.X, vec.Y);; //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); //rotate matTransform.Rotate(AgentHeading, AgentSide); //now transform the vertices matTransform.TransformVector2D(TransVec); return(TransVec); }
//--------------------- VectorToLocalSpace -------------------------------- // //------------------------------------------------------------------------ public static Vector2D VectorToLocalSpace(Vector2D vec, Vector2D AgentHeading, Vector2D AgentSide) { //make a copy of the point Vector2D TransPoint = new Vector2D(vec.X, vec.Y); //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); //create the transformation matrix matTransform._11(AgentHeading.X); matTransform._12(AgentSide.X); matTransform._21(AgentHeading.Y); matTransform._22(AgentSide.Y); //now transform the vertices matTransform.TransformVector2D(TransPoint); return(TransPoint); }
//--------------------- PointToWorldSpace -------------------------------- // // Transforms a point from the agent's local space into world space //------------------------------------------------------------------------ public static Vector2D PointToWorldSpace(Vector2D point, Vector2D AgentHeading, Vector2D AgentSide, Vector2D AgentPosition) { //make a copy of the point Vector2D TransPoint = new Vector2D(point.X, point.Y);; //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.TransformVector2D(TransPoint); return(TransPoint); }
//--------------------- PointToLocalSpace -------------------------------- // //------------------------------------------------------------------------ public static Vector2D PointToLocalSpace(Vector2D point, Vector2D AgentHeading, Vector2D AgentSide, Vector2D AgentPosition) { //make a copy of the point Vector2D TransPoint = new Vector2D(point.X, point.Y); //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); double Tx = -AgentPosition.Dot(AgentHeading); double Ty = -AgentPosition.Dot(AgentSide); //create the transformation matrix matTransform._11(AgentHeading.X); matTransform._12(AgentSide.X); matTransform._21(AgentHeading.Y); matTransform._22(AgentSide.Y); matTransform._31(Tx); matTransform._32(Ty); //now transform the vertices matTransform.TransformVector2D(TransPoint); return(TransPoint); }
//--------------------------- 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; }
//-------------------------- Vec2DRotateAroundOrigin -------------------------- // // rotates a vector ang rads around the origin //----------------------------------------------------------------------------- public static void Vec2DRotateAroundOrigin(Vector2D v, double ang) { //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); //rotate matTransform.Rotate(ang); //now transform the object's vertices matTransform.TransformVector2D( v); }
//--------------------- VectorToLocalSpace -------------------------------- // //------------------------------------------------------------------------ public static Vector2D VectorToLocalSpace(Vector2D vec, Vector2D AgentHeading, Vector2D AgentSide) { //make a copy of the point Vector2D TransPoint = new Vector2D(vec.X, vec.Y); //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); //create the transformation matrix matTransform._11(AgentHeading.X); matTransform._12(AgentSide.X); matTransform._21(AgentHeading.Y); matTransform._22(AgentSide.Y); //now transform the vertices matTransform.TransformVector2D( TransPoint); return TransPoint; }
//--------------------- PointToLocalSpace -------------------------------- // //------------------------------------------------------------------------ public static Vector2D PointToLocalSpace(Vector2D point, Vector2D AgentHeading, Vector2D AgentSide, Vector2D AgentPosition) { //make a copy of the point Vector2D TransPoint = new Vector2D(point.X, point.Y); //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); double Tx = -AgentPosition.Dot(AgentHeading); double Ty = -AgentPosition.Dot(AgentSide); //create the transformation matrix matTransform._11(AgentHeading.X); matTransform._12(AgentSide.X); matTransform._21(AgentHeading.Y); matTransform._22(AgentSide.Y); matTransform._31(Tx); matTransform._32(Ty); //now transform the vertices matTransform.TransformVector2D( TransPoint); return TransPoint; }
//--------------------- VectorToWorldSpace -------------------------------- // // Transforms a vector from the agent's local space into world space //------------------------------------------------------------------------ public static Vector2D VectorToWorldSpace(Vector2D vec, Vector2D AgentHeading, Vector2D AgentSide) { //make a copy of the point Vector2D TransVec = new Vector2D(vec.X, vec.Y); ; //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); //rotate matTransform.Rotate(AgentHeading, AgentSide); //now transform the vertices matTransform.TransformVector2D( TransVec); return TransVec; }
//--------------------- PointToWorldSpace -------------------------------- // // Transforms a point from the agent's local space into world space //------------------------------------------------------------------------ public static Vector2D PointToWorldSpace(Vector2D point, Vector2D AgentHeading, Vector2D AgentSide, Vector2D AgentPosition) { //make a copy of the point Vector2D TransPoint = new Vector2D(point.X, point.Y); ; //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.TransformVector2D(TransPoint); return TransPoint; }