graphics – I’m having an issue with rect class in openGL

I implemented a Rect class in my custom game engine that utilizes openGL. I decided to approach the whole Rect class design like unity’s implementation.

Essentially, what I do is I directly manipulate the X and Y coordinates of the rectangle and also it’s width and height and then I update the Vertex Buffer Object using the following function glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data).

Here is my design:

class Rect
{
private:
    VertexArray* vao = nullptr;
    VertexBuffer* vbo = nullptr;
    IndexBuffer* ibo = nullptr;
private:
    real* dataBuffer = nullptr;
    uint32* indicesBuffer = nullptr;
private:
    real x, y;
    real width, height;
    real xMax, yMax;
public:
    Rect(real x, real y, real width, real height);
    ~Rect();
public:
    void SetX(real x);
    void SetY(real y);
    void SetWidth(real width);
    void SetHeight(real height);
    void SetUV(Vector2 v1, Vector2 v2, Vector2 v3, Vector2 v4);
    real GetX();
    real GetY();
    real GetWidth();
    real GetHeight();
    std::vector<Vector2> GetUV();
    Vector2 GetCenter();
public:
    bool Contains(Vector2 point);
public:
    void Bind();
    void UnBind();
};

Now the issue occurs when I multiply the rectangle’s Vertex Buffer Object with model matrix which causes the actual vertex data inside the GPU to change but the Rect object data remains the same inside the CPU (The rectangle could be at coordiantes (100,250) but the X and Y coordinates stored in the object are (50, 50)) which will cause all kind of issues especially when performing hit testing for UI or picking up GameObjects.

How can I approach such a problem while remaining true to unity’s design.