Ejemplo n.º 1
0
void SpriteBatch::draw(const Vector3& dst, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color,
                       const Vector2& rotationPoint, float rotationAngle)
{
    // Expand dst by scale into 4 points.
    float x2 = dst.x + width;
    float y2 = dst.y + height;
    
    Vector2 upLeft(dst.x, dst.y);
    Vector2 upRight(x2, dst.y);
    Vector2 downLeft(dst.x, y2);
    Vector2 downRight(x2, y2);

    // Rotate points around rotationAxis by rotationAngle.
    Vector2 pivotPoint(rotationPoint);
    pivotPoint.x *= width;
    pivotPoint.y *= height;
    pivotPoint.x += dst.x;
    pivotPoint.y += dst.y;
    upLeft.rotate(pivotPoint, rotationAngle);
    upRight.rotate(pivotPoint, rotationAngle);
    downLeft.rotate(pivotPoint, rotationAngle);
    downRight.rotate(pivotPoint, rotationAngle);
    
    // Write sprite vertex data.
    static SpriteVertex v[4];
    ADD_SPRITE_VERTEX(v[0], upLeft.x, upLeft.y, dst.z, u1, v1, color.x, color.y, color.z, color.w);
    ADD_SPRITE_VERTEX(v[1], upRight.x, upRight.y, dst.z, u1, v2, color.x, color.y, color.z, color.w);
    ADD_SPRITE_VERTEX(v[2], downLeft.x, downLeft.y, dst.z, u2, v1, color.x, color.y, color.z, color.w);
    ADD_SPRITE_VERTEX(v[3], downRight.x, downRight.y, dst.z, u2, v2, color.x, color.y, color.z, color.w);
    
    static unsigned short indices[4] = { 0, 1, 2, 3 };

    _batch->add(v, 4, indices, 4);
}
Ejemplo n.º 2
0
void SpriteBatch::draw(float x, float y, float z, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color,
          const Vector2& rotationPoint, float rotationAngle, bool positionIsCenter)
{
    // Treat the given position as the center if the user specified it as such.
    if (positionIsCenter)
    {
        x -= 0.5f * width;
        y -= 0.5f * height;
    }

    // Expand the destination position by scale into 4 points.
    float x2 = x + width;
    float y2 = y + height;
    
    Vector2 upLeft(x, y);
    Vector2 upRight(x2, y);
    Vector2 downLeft(x, y2);
    Vector2 downRight(x2, y2);

    // Rotate points around rotationAxis by rotationAngle.
    if (rotationAngle != 0)
    {
        Vector2 pivotPoint(rotationPoint);
        pivotPoint.x *= width;
        pivotPoint.y *= height;
        pivotPoint.x += x;
        pivotPoint.y += y;
        upLeft.rotate(pivotPoint, rotationAngle);
        upRight.rotate(pivotPoint, rotationAngle);
        downLeft.rotate(pivotPoint, rotationAngle);
        downRight.rotate(pivotPoint, rotationAngle);
    }

    // Write sprite vertex data.
    static SpriteVertex v[4];
    SPRITE_ADD_VERTEX(v[0], downLeft.x, downLeft.y, z, u1, v1, color.x, color.y, color.z, color.w);
    SPRITE_ADD_VERTEX(v[1], upLeft.x, upLeft.y, z, u1, v2, color.x, color.y, color.z, color.w);
    SPRITE_ADD_VERTEX(v[2], downRight.x, downRight.y, z, u2, v1, color.x, color.y, color.z, color.w);
    SPRITE_ADD_VERTEX(v[3], upRight.x, upRight.y, z, u2, v2, color.x, color.y, color.z, color.w);
    
    static unsigned short indices[4] = { 0, 1, 2, 3 };

    _batch->add(v, 4, indices, 4);
}