Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
OrientedBox.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 #pragma once
6 
7 #ifndef NAZARA_ORIENTEDBOX_HPP
8 #define NAZARA_ORIENTEDBOX_HPP
9 
10 #include <Nazara/Core/String.hpp>
11 #include <Nazara/Math/Box.hpp>
12 #include <Nazara/Math/Matrix4.hpp>
13 #include <Nazara/Math/Vector3.hpp>
14 
15 namespace Nz
16 {
17  struct SerializationContext;
18 
19  template<typename T>
21  {
22  public:
23  OrientedBox() = default;
24  OrientedBox(T X, T Y, T Z, T Width, T Height, T Depth);
25  OrientedBox(const Box<T>& box);
26  OrientedBox(const Vector3<T>& vec1, const Vector3<T>& vec2);
27  template<typename U> explicit OrientedBox(const OrientedBox<U>& orientedBox);
28  OrientedBox(const OrientedBox& orientedBox) = default;
29  ~OrientedBox() = default;
30 
31  const Vector3<T>& GetCorner(BoxCorner corner) const;
32 
33  bool IsValid() const;
34 
36 
37  OrientedBox& Set(T X, T Y, T Z, T Width, T Height, T Depth);
38  OrientedBox& Set(const Box<T>& box);
39  OrientedBox& Set(const OrientedBox& orientedBox);
40  OrientedBox& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
41  template<typename U> OrientedBox& Set(const OrientedBox<U>& orientedBox);
42 
43  String ToString() const;
44 
45  void Update(const Matrix4<T>& transformMatrix);
46  void Update(const Vector3<T>& transformMatrix);
47 
48  operator Vector3<T>* ();
49  operator const Vector3<T>* () const;
50 
51  Vector3<T>& operator()(unsigned int i);
52  Vector3<T> operator()(unsigned int i) const;
53 
54  OrientedBox operator*(T scalar) const;
55  OrientedBox& operator=(const OrientedBox& other) = default;
56 
57  OrientedBox& operator*=(T scalar);
58 
59  bool operator==(const OrientedBox& box) const;
60  bool operator!=(const OrientedBox& box) const;
61 
62  static OrientedBox Lerp(const OrientedBox& from, const OrientedBox& to, T interpolation);
63  static OrientedBox Zero();
64 
65  Box<T> localBox;
66 
67  private:
68  Vector3<T> m_corners[BoxCorner_Max+1]; // Ne peuvent pas être modifiés directement
69  };
70 
73 
74  template<typename T> bool Serialize(SerializationContext& context, const OrientedBox<T>& obb);
75  template<typename T> bool Unserialize(SerializationContext& context, OrientedBox<T>* obb);
76 }
77 
78 template<typename T>
79 std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox<T>& orientedBox);
80 
81 #include <Nazara/Math/OrientedBox.inl>
82 
83 #endif // NAZARA_ORIENTEDBOX_HPP
OrientedBox & Set(T X, T Y, T Z, T Width, T Height, T Depth)
Sets the components of the oriented box.
Definition: OrientedBox.inl:145
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Math class that represents an oriented three dimensional box.
Definition: OrientedBox.hpp:20
bool Unserialize(SerializationContext &context, bool *value)
Unserializes a boolean.
Definition: Algorithm.inl:279
Core class that represents a string.
Definition: String.hpp:22
static OrientedBox Lerp(const OrientedBox &from, const OrientedBox &to, T interpolation)
Interpolates the oriented box to other one with a factor of interpolation.
Definition: OrientedBox.inl:411
static OrientedBox Zero()
Shorthand for the oriented box (0, 0, 0, 0, 0, 0)
Definition: OrientedBox.inl:427
bool operator==(const OrientedBox &box) const
Compares the oriented box to other one.
Definition: OrientedBox.inl:378
void Update(const Matrix4< T > &transformMatrix)
Updates the corners of the box.
Definition: OrientedBox.inl:244
OrientedBox & operator*=(T scalar)
Multiplies the lengths of this oriented box with the scalar.
Definition: OrientedBox.inl:363
Structure containing a serialization/unserialization context states.
Definition: SerializationContext.hpp:18
const Vector3< T > & GetCorner(BoxCorner corner) const
Gets the Vector3 for the corner.
Definition: OrientedBox.inl:91
bool operator!=(const OrientedBox &box) const
Compares the oriented box to other one.
Definition: OrientedBox.inl:391
bool Serialize(SerializationContext &context, bool value)
Serializes a boolean.
Definition: Algorithm.inl:214
OrientedBox operator*(T scalar) const
Multiplies the lengths with the scalar.
Definition: OrientedBox.inl:347
String ToString() const
Gives a string representation.
Definition: OrientedBox.inl:223
bool IsValid() const
Checks whether this oriented box is valid.
Definition: OrientedBox.inl:112
Math class that represents a transformation of the four dimensional vector space with the notion of p...
Definition: Matrix4.hpp:26
OrientedBox & MakeZero()
Makes the oriented box position (0, 0, 0) and lengths (0, 0, 0)
Definition: OrientedBox.inl:125
Vector3< T > & operator()(unsigned int i)
Gets the ith corner of the oriented box.
Definition: OrientedBox.inl:298
Math class that represents an element of the three dimensional vector space.
Definition: Matrix4.hpp:22
Math class that represents a three dimensional box.
Definition: Box.hpp:22