Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Plane.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_PLANE_HPP
8 #define NAZARA_PLANE_HPP
9 
10 #include <Nazara/Core/String.hpp>
11 #include <Nazara/Math/Vector3.hpp>
12 
13 namespace Nz
14 {
15  struct SerializationContext;
16 
17  template<typename T>
18  class Plane
19  {
20  public:
21  Plane() = default;
22  Plane(T normalX, T normalY, T normalZ, T Distance);
23  Plane(const T plane[4]);
24  Plane(const Vector3<T>& Normal, T Distance);
25  Plane(const Vector3<T>& Normal, const Vector3<T>& point);
26  Plane(const Vector3<T>& point1, const Vector3<T>& point2, const Vector3<T>& point3);
27  template<typename U> explicit Plane(const Plane<U>& plane);
28  Plane(const Plane& plane) = default;
29  ~Plane() = default;
30 
31  T Distance(T x, T y, T z) const;
32  T Distance(const Vector3<T>& point) const;
33 
34  Plane& MakeXY();
35  Plane& MakeXZ();
36  Plane& MakeYZ();
37 
38  Plane& Set(T normalX, T normalY, T normalZ, T Distance);
39  Plane& Set(const T plane[4]);
40  Plane& Set(const Plane& plane);
41  Plane& Set(const Vector3<T>& Normal, T Distance);
42  Plane& Set(const Vector3<T>& Normal, const Vector3<T>& point);
43  Plane& Set(const Vector3<T>& point1, const Vector3<T>& point2, const Vector3<T>& point3);
44  template<typename U> Plane& Set(const Plane<U>& plane);
45 
46  String ToString() const;
47 
48  Plane& operator=(const Plane& other) = default;
49 
50  bool operator==(const Plane& plane) const;
51  bool operator!=(const Plane& plane) const;
52 
53  static Plane Lerp(const Plane& from, const Plane& to, T interpolation);
54  static Plane XY();
55  static Plane XZ();
56  static Plane YZ();
57 
58  Vector3<T> normal;
59  T distance;
60  };
61 
62  typedef Plane<double> Planed;
63  typedef Plane<float> Planef;
64 
65  template<typename T> bool Serialize(SerializationContext& context, const Plane<T>& plane);
66  template<typename T> bool Unserialize(SerializationContext& context, Plane<T>* plane);
67 }
68 
69 template<typename T>
70 std::ostream& operator<<(std::ostream& out, const Nz::Plane<T>& plane);
71 
72 #include <Nazara/Math/Plane.inl>
73 
74 #endif // NAZARA_PLANE_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
bool Unserialize(SerializationContext &context, bool *value)
Unserializes a boolean.
Definition: Algorithm.inl:279
Math class that represents a plane in 3D.
Definition: Plane.hpp:18
Core class that represents a string.
Definition: String.hpp:22
static Plane XZ()
Shorthand for the plane (0, 1, 0, 0)
Definition: Plane.inl:405
bool operator==(const Plane &plane) const
Compares the plane to other one.
Definition: Plane.inl:328
Plane & MakeXY()
Makes the plane (0, 0, 1, 0)
Definition: Plane.inl:149
bool operator!=(const Plane &plane) const
Compares the plane to other one.
Definition: Plane.inl:343
Plane & Set(T normalX, T normalY, T normalZ, T Distance)
Sets the components of the plane.
Definition: Plane.inl:191
Structure containing a serialization/unserialization context states.
Definition: SerializationContext.hpp:18
T Distance(T x, T y, T z) const
Returns the distance from the plane to the point.
Definition: Plane.inl:119
bool Serialize(SerializationContext &context, bool value)
Serializes a boolean.
Definition: Algorithm.inl:214
String ToString() const
Gives a string representation.
Definition: Plane.inl:311
static Plane XY()
Shorthand for the plane (0, 0, 1, 0)
Definition: Plane.inl:389
static Plane YZ()
Shorthand for the plane (1, 0, 0, 0)
Definition: Plane.inl:421
static Plane Lerp(const Plane &from, const Plane &to, T interpolation)
Interpolates the plane to other one with a factor of interpolation.
Definition: Plane.inl:363
Plane & MakeYZ()
Makes the plane (1, 0, 0, 0)
Definition: Plane.inl:175
Plane & MakeXZ()
Makes the plane (0, 1, 0, 0)
Definition: Plane.inl:162
Math class that represents an element of the three dimensional vector space.
Definition: Matrix4.hpp:22