Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
Rectangle Struct Reference

Represents a 2D axis-aligned rectangle used for UI, collision detection, or rendering. Supports AABB collision checks and conversion to SDL's rectangle format. More...

#include <Rectangle.h>

Public Member Functions

 Rectangle (Vector2 pPosition=Vector2::ZERO, Vector2 pDimensions=Vector2::ONE)
 Constructor for Rectangle.
 
SDL_Rect ToSdlRect () const
 Converts the rectangle to an SDL_Rect structure for rendering or input detection.
 
bool operator== (const Rectangle &other) const
 
bool operator!= (const Rectangle &other) const
 

Static Public Member Functions

static bool Collision (const Rectangle &a, const Rectangle &b)
 Checks for AABB (Axis-Aligned Bounding Box) collision between two rectangles.
 

Public Attributes

Vector2 position
 Top-left corner of the rectangle.
 
Vector2 dimensions
 Width (x) and height (y) of the rectangle.
 

Static Public Attributes

static const Rectangle NullRect
 A predefined rectangle with zero size and position.
 

Detailed Description

Represents a 2D axis-aligned rectangle used for UI, collision detection, or rendering. Supports AABB collision checks and conversion to SDL's rectangle format.

Constructor & Destructor Documentation

◆ Rectangle()

Rectangle::Rectangle ( Vector2 pPosition = Vector2::ZERO,
Vector2 pDimensions = Vector2::ONE )

Constructor for Rectangle.

Parameters
pPositionThe top-left position of the rectangle (default: Vector2::ZERO).
pDimensionsThe width and height of the rectangle (default: Vector2::ONE).

Member Function Documentation

◆ Collision()

bool Rectangle::Collision ( const Rectangle & a,
const Rectangle & b )
static

Checks for AABB (Axis-Aligned Bounding Box) collision between two rectangles.

Parameters
aThe first rectangle.
bThe second rectangle.
Returns
True if the rectangles overlap, false otherwise.

◆ operator!=()

bool Rectangle::operator!= ( const Rectangle & other) const

◆ operator==()

bool Rectangle::operator== ( const Rectangle & other) const

◆ ToSdlRect()

SDL_Rect Rectangle::ToSdlRect ( ) const

Converts the rectangle to an SDL_Rect structure for rendering or input detection.

Returns
SDL_Rect equivalent of this rectangle.

Member Data Documentation

◆ dimensions

Vector2 Rectangle::dimensions

Width (x) and height (y) of the rectangle.

◆ NullRect

const Rectangle Rectangle::NullRect
static

A predefined rectangle with zero size and position.

◆ position

Vector2 Rectangle::position

Top-left corner of the rectangle.


The documentation for this struct was generated from the following files: