ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
BoundingBox2D.cpp
Go to the documentation of this file.
1#include "BoundingBox2D.h"
2
4 // Initialize min and max to default values
5 min = Vector2D(0.0f, 0.0f);
6 max = Vector2D(0.0f, 0.0f);
7 mid = Vector2D(0.0f, 0.0f);
8}
9
11 this->min = min;
12 this->max = max;
13
14 mid.X = (min.X + max.X) * 0.5f;
15 mid.Y = (min.Y + max.Y) * 0.5f;
16}
17
19 min = min.Minimum(current);
20 max = max.Maximum(current);
21
22 mid.X = (min.X + max.X) * 0.5f;
23 mid.Y = (min.Y + max.Y) * 0.5f;
24}
25
29
33
37
39 bool xOverlap = bb->GetMinimum().X < max.X && bb->GetMaximum().X > min.X;
40 bool yOverlap = bb->GetMinimum().Y < max.Y && bb->GetMaximum().Y > min.Y;
41
42 return xOverlap && yOverlap;
43}
44
45bool BoundingBox2D::Overlaps(const Vector2D& minI, const Vector2D& maxI){
46 bool xOverlap = minI.X < max.X && maxI.X > min.X;
47 bool yOverlap = minI.Y < max.Y && maxI.Y > min.Y;
48
49 return xOverlap && yOverlap;
50}
51
53 return min.X <= v.X && v.X <= max.X && min.Y <= v.Y && v.Y <= max.Y;
54}
55
Defines the BoundingBox2D class for managing 2D bounding boxes.
Represents a 2D axis-aligned bounding box.
Vector2D GetCenter()
Gets the center point of the bounding box.
bool Overlaps(BoundingBox2D *bb)
Checks if this bounding box overlaps with another BoundingBox2D.
BoundingBox2D()
Default constructor initializing the bounding box to zero dimensions.
Vector2D min
Minimum corner of the bounding box.
Vector2D GetMinimum()
Gets the minimum corner of the bounding box.
Vector2D GetMaximum()
Gets the maximum corner of the bounding box.
bool Contains(const Vector2D &v)
Checks if this bounding box contains a specified point.
Vector2D max
Maximum corner of the bounding box.
Vector2D mid
Center point of the bounding box.
void UpdateBounds(const Vector2D &current)
Updates the bounds of the bounding box to include the specified point.
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
Vector2D Maximum(const Vector2D &v) const
Computes the maximum components between this vector and another Vector2D.
Definition Vector2D.cpp:117
Vector2D Minimum(const Vector2D &v) const
Computes the minimum components between this vector and another Vector2D.
Definition Vector2D.cpp:110
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