Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
BoundingVolume.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Mathematics module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #ifndef NAZARA_BOUNDINGVOLUME_HPP
6 #define NAZARA_BOUNDINGVOLUME_HPP
7 
8 #include <Nazara/Core/String.hpp>
9 #include <Nazara/Math/Box.hpp>
10 #include <Nazara/Math/Enums.hpp>
11 #include <Nazara/Math/Matrix4.hpp>
12 #include <Nazara/Math/OrientedBox.hpp>
13 #include <Nazara/Math/Vector3.hpp>
14 
15 namespace Nz
16 {
17  struct SerializationContext;
18 
19  template<typename T>
21  {
22  public:
24  BoundingVolume(Extend Extend);
25  BoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth);
26  BoundingVolume(const Box<T>& box);
27  BoundingVolume(const OrientedBox<T>& orientedBox);
28  BoundingVolume(const Vector3<T>& vec1, const Vector3<T>& vec2);
29  template<typename U> explicit BoundingVolume(const BoundingVolume<U>& volume);
30  BoundingVolume(const BoundingVolume& volume) = default;
31  ~BoundingVolume() = default;
32 
33  BoundingVolume& ExtendTo(const BoundingVolume& volume);
34 
35  bool IsFinite() const;
36  bool IsInfinite() const;
37  bool IsNull() const;
38 
41 
42  BoundingVolume& Set(Extend Extend);
43  BoundingVolume& Set(T X, T Y, T Z, T Width, T Height, T Depth);
44  BoundingVolume& Set(const BoundingVolume<T>& volume);
45  BoundingVolume& Set(const Box<T>& box);
46  BoundingVolume& Set(const OrientedBox<T>& orientedBox);
47  BoundingVolume& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
48  template<typename U> BoundingVolume& Set(const BoundingVolume<U>& volume);
49 
50  String ToString() const;
51 
52  void Update(const Matrix4<T>& transformMatrix);
53  void Update(const Vector3<T>& translation);
54 
55  BoundingVolume operator*(T scalar) const;
56  BoundingVolume& operator=(const BoundingVolume& other) = default;
57 
58  BoundingVolume& operator*=(T scalar);
59 
60  bool operator==(const BoundingVolume& volume) const;
61  bool operator!=(const BoundingVolume& volume) const;
62 
63  static BoundingVolume Infinite();
64  static BoundingVolume Lerp(const BoundingVolume& from, const BoundingVolume& to, T interpolation);
65  static BoundingVolume Null();
66 
67  Extend extend;
68  Box<T> aabb;
69  OrientedBox<T> obb;
70  };
71 
74 
75  template<typename T> bool Serialize(SerializationContext& context, const BoundingVolume<T>& boundingVolume);
76  template<typename T> bool Unserialize(SerializationContext& context, BoundingVolume<T>* boundingVolume);
77 }
78 
79 template<typename T>
80 std::ostream& operator<<(std::ostream& out, const Nz::BoundingVolume<T>& volume);
81 
82 #include <Nazara/Math/BoundingVolume.inl>
83 
84 #endif // NAZARA_BOUNDINGVOLUME_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
BoundingVolume operator*(T scalar) const
Multiplies the lengths of the obb with the scalar.
Definition: BoundingVolume.inl:423
Math class that represents an oriented three dimensional box.
Definition: OrientedBox.hpp:20
bool operator!=(const BoundingVolume &volume) const
Compares the bounding volume to other one.
Definition: BoundingVolume.inl:473
bool Unserialize(SerializationContext &context, bool *value)
Unserializes a boolean.
Definition: Algorithm.inl:279
bool IsInfinite() const
Checks whether the volume is infinite.
Definition: BoundingVolume.inl:190
Core class that represents a string.
Definition: String.hpp:22
static BoundingVolume Lerp(const BoundingVolume &from, const BoundingVolume &to, T interpolation)
Interpolates the bounding volume to other one with a factor of interpolation.
Definition: BoundingVolume.inl:510
Math class that represents a bounding volume, a combination of a box and an oriented box...
Definition: BoundingVolume.hpp:20
BoundingVolume & MakeNull()
Makes the bounding volume null.
Definition: BoundingVolume.inl:229
BoundingVolume & operator*=(T scalar)
Multiplies the lengths of this bounding volume with the scalar.
Definition: BoundingVolume.inl:439
Structure containing a serialization/unserialization context states.
Definition: SerializationContext.hpp:18
bool operator==(const BoundingVolume &volume) const
Compares the bounding volume to other one.
Definition: BoundingVolume.inl:454
BoundingVolume & Set(Extend Extend)
Sets the extend of the bounding volume from Extend.
Definition: BoundingVolume.inl:246
bool Serialize(SerializationContext &context, bool value)
Serializes a boolean.
Definition: Algorithm.inl:214
BoundingVolume & ExtendTo(const BoundingVolume &volume)
Extends the bounding volume to contain another bounding volume.
Definition: BoundingVolume.inl:137
BoundingVolume()
Constructs a BoundingVolume object by default.
Definition: BoundingVolume.inl:33
static BoundingVolume Infinite()
Shorthand for the bounding volume (Extend_Infinite)
Definition: BoundingVolume.inl:486
bool IsFinite() const
Checks whether the volume is finite.
Definition: BoundingVolume.inl:179
Math class that represents a transformation of the four dimensional vector space with the notion of p...
Definition: Matrix4.hpp:26
static BoundingVolume Null()
Shorthand for the bounding volume (Extend_Null)
Definition: BoundingVolume.inl:588
String ToString() const
Gives a string representation.
Definition: BoundingVolume.inl:364
Math class that represents an element of the three dimensional vector space.
Definition: Matrix4.hpp:22
BoundingVolume & MakeInfinite()
Makes the bounding volume infinite.
Definition: BoundingVolume.inl:214
bool IsNull() const
Checks whether the volume is null.
Definition: BoundingVolume.inl:201
void Update(const Matrix4< T > &transformMatrix)
Updates the obb and the aabb of the bounding volume.
Definition: BoundingVolume.inl:390
Math class that represents a three dimensional box.
Definition: Box.hpp:22