I'm rotating a sprite using the following, but when the spaceship, which is circular, is facing towards the left side of the screen and I press the thrust key it slows down? Any help? Velocity, acceleration and positon are all vectors. Can't think of anymore code you may need!
Code:
void drawObject() {
...
...
//Acceletion moves the spaceship across the screen
velocity += acceleration * pTheGameTimer->mdFrameTime;
//Adjust bearing angle according to the above key press
velocity.setBearing((dAngle/360*6.282), velocity.magnitude());
//Move helicopter based upon velocity
position += velocity * pTheGameTimer->mdFrameTime;
}
void Vector2D::setBearing(double angle, double magnitude)
{
XValue = magnitude*sin(angle);
YValue = magnitude*cos(angle);
}
double Vector2D::magnitude() const
{
return sqrt(XValue*XValue + YValue*YValue);
}
I didn't develop the 2D class, but it also has:
Code:
Vector2D Vector2D::rotatedBy(double angle) const
{
double s = sin(angle);
double c = cos(angle);
return Vector2D(this->XValue * c - this->YValue*s, this->XValue * s + this->YValue * c);
}
Thanks