RavEngine
Loading...
Searching...
No Matches
box.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_BASE_MATHS_BOX_H_
29#define OZZ_OZZ_BASE_MATHS_BOX_H_
30
31#include <cstddef>
32
33#include "ozz/base/maths/vec_float.h"
34
35namespace ozz {
36namespace math {
37
38// Matrix forward declaration.
39struct Float4x4;
40
41// Defines an axis aligned box.
42struct OZZ_BASE_DLL Box {
43 // Constructs an invalid box.
44 Box();
45
46 // Constructs a box with the specified _min and _max bounds.
47 Box(const Float3& _min, const Float3& _max) : min(_min), max(_max) {}
48
49 // Constructs the smallest box that contains the _count points _points.
50 // _stride is the number of bytes between points.
51 explicit Box(const Float3& _point) : min(_point), max(_point) {}
52
53 // Constructs the smallest box that contains the _count points _points.
54 // _stride is the number of bytes between points, it must be greater or
55 // equal to sizeof(Float3).
56 Box(const Float3* _points, size_t _stride, size_t _count);
57
58 // Tests whether *this is a valid box.
59 bool is_valid() const { return min <= max; }
60
61 // Tests whether _p is within box bounds.
62 bool is_inside(const Float3& _p) const { return _p >= min && _p <= max; }
63
64 // Box's min and max bounds.
65 Float3 min;
66 Float3 max;
67};
68
69// Merges two boxes _a and _b.
70// Both _a and _b can be invalid.
71OZZ_INLINE Box Merge(const Box& _a, const Box& _b) {
72 if (!_a.is_valid()) {
73 return _b;
74 } else if (!_b.is_valid()) {
75 return _a;
76 }
77 return Box(Min(_a.min, _b.min), Max(_a.max, _b.max));
78}
79
80// Compute box transformation by a matrix.
81OZZ_BASE_DLL Box TransformBox(const Float4x4& _matrix, const Box& _box);
82} // namespace math
83} // namespace ozz
84#endif // OZZ_OZZ_BASE_MATHS_BOX_H_
Definition box.h:42
Definition vec_float.h:67