1

So currently im making a game in raylib library in C

I was expecting to rotate the rectangle but what really did happen the rectangle was being rotated using rectanglepro function but collision were'nt defined on it so it failed.

I am using the following code but it doesn't work:

RotatedVector = Vector2Rotate(Vector2Normalize(Center), angle * DEG2RAD); 

Where as Vector2Rotate is function of raymath.h defined as:

RMAPI Vector2 Vector2Rotate(Vector2 v, float angle)
{
    Vector2 result = { 0 };

    float cosres = cosf(angle);
    float sinres = sinf(angle);

    result.x = v.x * cosres - v.y * sinres;
    result.y = v.x * sinres + v.y * cosres;

    return result;
}

Vector2Normalize is defined as

RMAPI Vector2 Vector2Normalize(Vector2 v)
{
    Vector2 result = { 0 };
    float length = sqrtf((v.x * v.x) + (v.y * v.y));

    if (length > 0)
    {
        float ilength = 1.0f / length;
        result.x = v.x * ilength;
        result.y = v.y * ilength;
    }

    return result;
}
chqrlie
  • 131,814
  • 10
  • 121
  • 189

1 Answers1

1

RectanglePro is a drawing function. It will only produce the visual representation of a rectangle, and therefore it will not do collisions for you.

You could use a separate library for physics and use Raylib's RectanglePro to draw the result.

Samie Bencherif
  • 1,285
  • 12
  • 27