Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
plane.h
1 #pragma once
2 
3 #include "../generic/optional.h"
4 
5 #include "vec3.h"
6 
7 namespace smlt {
8 
9 struct Vec3;
10 
11 enum PlaneClassification {
12  PLANE_CLASSIFICATION_IS_BEHIND_PLANE,
13  PLANE_CLASSIFICATION_IS_ON_PLANE,
14  PLANE_CLASSIFICATION_IS_IN_FRONT_OF_PLANE
15 };
16 
17 
18 struct Plane {
19  Vec3 n;
20  float d;
21 
22  Plane():
23  n(Vec3()),
24  d(0) {
25  }
26 
27  Plane(const Vec3& N, float D):
28  n(N),
29  d(D) {
30 
31  }
32 
33  Plane(const Vec3& N, const Vec3& P):
34  n(N),
35  d(P.dot(N)) {
36  }
37 
38  Plane(float A, float B, float C, float D):
39  n(A, B, C),
40  d(D) {
41 
42  }
43 
44  Vec3 project(const Vec3& p);
45 
46  Vec3 normal() const {
47  return n;
48  }
49 
50  float distance_to(const Vec3& p) const;
51 
52  PlaneClassification classify_point(const Vec3& p) const;
53 
54  static smlt::optional<Vec3> intersect_planes(
55  const Plane& p1,
56  const Plane& p2,
57  const Plane& p3
58  );
59 };
60 
61 
62 }
smlt::Vec3
Definition: vec3.h:23
smlt
Definition: animation.cpp:25
smlt::optional
Definition: optional.h:13
smlt::Plane
Definition: plane.h:18