void ControlledTank::RotateHeadingByRadian(double radian, int sign) { //Clamp the amount to turn to the max turn rate. if (radian > mMaxTurnRate) radian = mMaxTurnRate; else if(radian < -mMaxTurnRate) radian = -mMaxTurnRate; //IncrementTankRotationAngle(RadsToDegs(radian)); mRotationAngle += RadsToDegs(radian)*sign; //Usee a rotation matrix to rotate the player's heading C2DMatrix RotationMatrix; //Calculate the direction of rotation. RotationMatrix.Rotate(radian * sign); //Get the new heading. RotationMatrix.TransformVector2Ds(mHeading); //cout << "RotateHeadingByRadian -- Heading x = " << mHeading.x << " y = " << mHeading.y << endl; //Get the new velocity. RotationMatrix.TransformVector2Ds(mVelocity); //Side vector must always be perpendicular to the heading. mSide = mHeading.Perp(); }
void B020612E_Steering::Vec2DRotateAroundOrigin(Vector2D& v, double ang) { //create a transformation matrix C2DMatrix mat; //rotate mat.Rotate(ang); //now transform the object's vertices mat.TransformVector2Ds(v); }
Vector2D B020612E_Steering::VectorToWorldSpace(const Vector2D &vec, const Vector2D &AgentHeading, const Vector2D &AgentSide) { //make a copy of the point Vector2D TransVec = vec; //create a transformation matrix C2DMatrix matTransform; //rotate matTransform.Rotate(AgentHeading, AgentSide); //now transform the vertices matTransform.TransformVector2Ds(TransVec); return TransVec; }
void BaseTank::RotateManByRadian(double radian, int sign) { //Clamp the amount to turn to the max turn rate. if (radian > mMaxTurnRate) radian = mMaxTurnRate; else if(radian < -mMaxTurnRate) radian = -mMaxTurnRate; IncrementManRotationAngle(RadsToDegs(radian*sign)); //Usee a rotation matrix to rotate the player's heading C2DMatrix RotationMatrix; //Calculate the direction of rotation. RotationMatrix.Rotate(radian * sign); //Get the new fire direction. RotationMatrix.TransformVector2Ds(mManFireDirection); }
Vector2D B020612E_Steering::PointToWorldSpace(const Vector2D &point, const Vector2D &AgentHeading, const Vector2D &AgentSide, const Vector2D &AgentPosition) { //make a copy of the point Vector2D TransPoint = point; //create a transformation matrix C2DMatrix matTransform; //rotate matTransform.Rotate(AgentHeading, AgentSide); //and translate matTransform.Translate(AgentPosition.x, AgentPosition.y); //now transform the vertices matTransform.TransformVector2Ds(TransPoint); return TransPoint; }
Vector2D B020612E_Steering::PointToLocalSpace(const Vector2D &point, Vector2D &AgentHeading, Vector2D &AgentSide, Vector2D &AgentPosition) { //make a copy of the point Vector2D TransPoint = point; //create a transformation matrix C2DMatrix matTransform; 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.TransformVector2Ds(TransPoint); return TransPoint; }
//------------------ RotateFacingTowardPosition ------------------------------- // // given a target position, this method rotates the bot's facing vector // 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 //---------------------------------------------------------------------------- bool Raven_Bot::RotateFacingTowardPosition(Vector2D target) { Vector2D toTarget = Vec2DNormalize(target - m_vPosition); double dot = m_vFacing.Dot(toTarget); //clamp to rectify any rounding errors Clamp(dot, -1, 1); //determine the angle between the heading vector and the target double angle = acos(dot); //return true if the bot's facing is within WeaponAimTolerance degs of //facing the target const double WeaponAimTolerance = 0.01; //2 degs approx if (angle < WeaponAimTolerance) { m_vFacing = toTarget; 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 facing //vector accordingly C2DMatrix RotationMatrix; //notice how the direction of rotation has to be determined when creating //the rotation matrix RotationMatrix.Rotate(angle * m_vFacing.Sign(toTarget)); RotationMatrix.TransformVector2Ds(m_vFacing); return false; }