class Vector{public: float x; float y;};
class Rect {public: // Center of the Rect Vector CenterVertex; // 4 Vertices of the Rect Vector Vertex1; Vector Vertex2; Vector Vertex3; Vector Vertex4; // Width and Height float w; float h; ~Rect(){} Rect(){} Rect(float x, float y, float W, float H){ CenterVertex.x = x; CenterVertex.y = y; w = W; h = H; moveRect(); } void moveRect(){ Vertex1.x = CenterVertex.x - w/2; Vertex1.y = CenterVertex.y + h/2; Vertex2.x = CenterVertex.x + w/2; Vertex2.y = CenterVertex.y + h/2; Vertex3.x = CenterVertex.x + w/2; Vertex3.y = CenterVertex.y - h/2; Vertex4.x = CenterVertex.x - w/2; Vertex4.y = CenterVertex.y - h/2; }};
then somewhere in the code if you want to move the rect
you just update it's center vertex like
// Update myRect positionmyRect.CenterVertex.x += 1;myRect.CenterVertex.y += 1;// Call update function to update the position on the screenmyRect.moveRect();
is that a good way of actually moving the rect?
Thanks for your time guys!