VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
boundingBox.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers 20.12.2025.
5//
6#pragma once
7
8#include <core/math/vector3.h>
9
10namespace visutwin::canvas
11{
21 {
22 public:
23 BoundingBox(): _center(0, 0, 0), _halfExtents(0.5f, 0.5f, 0.5f) {}
25 : _center(center), _halfExtents(halfExtents) {}
26
27 const Vector3& center() const { return _center; }
28 void setCenter(const Vector3& center) { _center = center; }
29
30 void setCenter(float x, float y, float z)
31 {
32 _center = {x, y, z};
33 }
34
35 const Vector3& halfExtents() const { return _halfExtents; }
36 void setHalfExtents(const Vector3& halfExtents) { _halfExtents = halfExtents; }
37
38 void setHalfExtents(float x, float y, float z)
39 {
40 _halfExtents = {x, y, z};
41 }
42
43 void setFromTransformedAabb(const BoundingBox& aabb, const Matrix4& m, bool ignoreScale = false);
44
45 void add(const BoundingBox& other);
46
47 private:
48 Vector3 _center;
49
50 // Half the distance across the box in each axis
51 Vector3 _halfExtents;
52
53 // Cached min/max vectors for getMin/getMax (avoid repeated allocations)
54 mutable Vector3 _min;
55 mutable Vector3 _max;
56 };
57}
Axis-Aligned Bounding Box defined by center and half-extents.
Definition boundingBox.h:21
void setHalfExtents(const Vector3 &halfExtents)
Definition boundingBox.h:36
void setHalfExtents(float x, float y, float z)
Definition boundingBox.h:38
BoundingBox(const Vector3 &center, const Vector3 &halfExtents)
Definition boundingBox.h:24
void setCenter(float x, float y, float z)
Definition boundingBox.h:30
void add(const BoundingBox &other)
void setFromTransformedAabb(const BoundingBox &aabb, const Matrix4 &m, bool ignoreScale=false)
const Vector3 & center() const
Definition boundingBox.h:27
void setCenter(const Vector3 &center)
Definition boundingBox.h:28
const Vector3 & halfExtents() const
Definition boundingBox.h:35
4x4 column-major transformation matrix with SIMD acceleration.
Definition matrix4.h:31
3D vector for positions, directions, and normals with multi-backend SIMD acceleration.
Definition vector3.h:29