ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Rectangle.cpp
Go to the documentation of this file.
1#include "Rectangle.h"
2
3Rectangle::Rectangle(Vector2D center, Vector2D size, float rotation) : Shape(center, size, rotation) {}
4
6 float x = (point.X - center.X);
7 float y = (point.Y - center.Y);
8
9 float sinR = sinf(rotation * Mathematics::MPID180);
10 float cosR = cosf(rotation * Mathematics::MPID180);
11
12 float xP = x * cosR - y * sinR; // rotate about center
13 float yP = x * sinR + y * cosR; // rotate about center
14
15 return fabs(xP) <= size.X / 2.0f && fabs(yP) <= size.Y / 2.0f;
16}
Defines the Rectangle class for representing rectangular shapes in 2D space.
static const float MPID180
The value of , useful for converting degrees to radians.
Definition Mathematics.h:47
Rectangle(Vector2D center, Vector2D size, float rotation)
Constructs a Rectangle object with specified center, size, and rotation.
Definition Rectangle.cpp:3
bool IsInShape(Vector2D point) override
Checks if a given point lies within the rectangle's boundaries.
Definition Rectangle.cpp:5
Abstract base class for 2D geometric shapes.
Definition Shape.h:22
float rotation
The rotation of the shape in degrees.
Definition Shape.h:26
Vector2D center
The center point of the shape.
Definition Shape.h:24
Vector2D size
The size of the shape, large enough to fit within a bounding rectangle.
Definition Shape.h:25
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
float X
The X-component of the 2D vector.
Definition Vector2D.h:29
float Y
The Y-component of the 2D vector.
Definition Vector2D.h:30