Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Frustum.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_FRUSTUM_HPP
8 #define NAZARA_FRUSTUM_HPP
9 
10 #include <Nazara/Core/String.hpp>
11 #include <Nazara/Math/BoundingVolume.hpp>
12 #include <Nazara/Math/Enums.hpp>
13 #include <Nazara/Math/Matrix4.hpp>
14 #include <Nazara/Math/OrientedBox.hpp>
15 #include <Nazara/Math/Plane.hpp>
16 #include <Nazara/Math/Sphere.hpp>
17 #include <Nazara/Math/Vector3.hpp>
18 
19 namespace Nz
20 {
21  struct SerializationContext;
22 
23  template<typename T>
24  class Frustum
25  {
26  public:
27  Frustum() = default;
28  template<typename U> explicit Frustum(const Frustum<U>& frustum);
29  Frustum(const Frustum& frustum) = default;
30  ~Frustum() = default;
31 
32  Frustum& Build(T angle, T ratio, T zNear, T zFar, const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up = Vector3<T>::Up());
33 
34  bool Contains(const BoundingVolume<T>& volume) const;
35  bool Contains(const Box<T>& box) const;
36  bool Contains(const OrientedBox<T>& orientedBox) const;
37  bool Contains(const Sphere<T>& sphere) const;
38  bool Contains(const Vector3<T>& point) const;
39  bool Contains(const Vector3<T>* points, unsigned int pointCount) const;
40 
41  Frustum& Extract(const Matrix4<T>& clipMatrix);
42  Frustum& Extract(const Matrix4<T>& view, const Matrix4<T>& projection);
43 
44  const Vector3<T>& GetCorner(BoxCorner corner) const;
45  const Plane<T>& GetPlane(FrustumPlane plane) const;
46 
47  IntersectionSide Intersect(const BoundingVolume<T>& volume) const;
48  IntersectionSide Intersect(const Box<T>& box) const;
49  IntersectionSide Intersect(const OrientedBox<T>& orientedBox) const;
50  IntersectionSide Intersect(const Sphere<T>& sphere) const;
51  IntersectionSide Intersect(const Vector3<T>* points, unsigned int pointCount) const;
52 
53  Frustum& operator=(const Frustum& other) = default;
54 
55  Frustum& Set(const Frustum& frustum);
56  template<typename U> Frustum& Set(const Frustum<U>& frustum);
57 
58  String ToString() const;
59 
60  template<typename U>
61  friend bool Serialize(SerializationContext& context, const Frustum<U>& frustum);
62  template<typename U>
63  friend bool Unserialize(SerializationContext& context, Frustum<U>* frustum);
64 
65  private:
66  Vector3<T> m_corners[BoxCorner_Max+1];
67  Plane<T> m_planes[FrustumPlane_Max+1];
68  };
69 
70  typedef Frustum<double> Frustumd;
71  typedef Frustum<float> Frustumf;
72 }
73 
74 template<typename T>
75 std::ostream& operator<<(std::ostream& out, const Nz::Frustum<T>& frustum);
76 
77 #include <Nazara/Math/Frustum.inl>
78 
79 #endif // NAZARA_FRUSTUM_HPP
Math class that represents a frustum in the three dimensional vector space.
Definition: Frustum.hpp:24
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Math class that represents an oriented three dimensional box.
Definition: OrientedBox.hpp:20
String ToString() const
Gives a string representation.
Definition: Frustum.inl:667
const Vector3< T > & GetCorner(BoxCorner corner) const
Gets the Vector3 for the corner.
Definition: Frustum.inl:446
Math class that represents a plane in 3D.
Definition: Plane.hpp:18
Math class that represents a sphere "S2" in a three dimensional euclidean space.
Definition: Sphere.hpp:20
Frustum & Extract(const Matrix4< T > &clipMatrix)
Constructs the frustum from a Matrix4.
Definition: Frustum.inl:254
Core class that represents a string.
Definition: String.hpp:22
Frustum & Build(T angle, T ratio, T zNear, T zFar, const Vector3< T > &eye, const Vector3< T > &target, const Vector3< T > &up=Vector3< T >::Up())
Builds the frustum object.
Definition: Frustum.inl:55
Math class that represents a bounding volume, a combination of a box and an oriented box...
Definition: BoundingVolume.hpp:20
Structure containing a serialization/unserialization context states.
Definition: SerializationContext.hpp:18
Frustum & Set(const Frustum &frustum)
Sets the components of the frustum from another frustum.
Definition: Frustum.inl:634
IntersectionSide Intersect(const BoundingVolume< T > &volume) const
Checks whether or not a bounding volume intersects with the frustum.
Definition: Frustum.inl:499
Math class that represents a transformation of the four dimensional vector space with the notion of p...
Definition: Matrix4.hpp:26
const Plane< T > & GetPlane(FrustumPlane plane) const
Gets the Plane for the face.
Definition: Frustum.inl:471
bool Contains(const BoundingVolume< T > &volume) const
Checks whether or not a bounding volume is contained in the frustum.
Definition: Frustum.inl:112
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