1 | #ifndef __Plane3_H__
|
---|
2 | #define __Plane3_H__
|
---|
3 |
|
---|
4 | #include "Vector3.h"
|
---|
5 |
|
---|
6 |
|
---|
7 | namespace CHCDemoEngine
|
---|
8 | {
|
---|
9 |
|
---|
10 | /** 3D Plane.
|
---|
11 | */
|
---|
12 | class Plane3
|
---|
13 | {
|
---|
14 | public:
|
---|
15 |
|
---|
16 | Plane3() {}
|
---|
17 |
|
---|
18 | //Plane3(const Vector3 &normal, float dist);
|
---|
19 |
|
---|
20 | Plane3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
|
---|
21 |
|
---|
22 | Plane3(const Vector3 &normal, const Vector3 &point);
|
---|
23 |
|
---|
24 | inline void ReverseOrientation()
|
---|
25 | {
|
---|
26 | mNormal *= -1;
|
---|
27 | mD *= -1;
|
---|
28 | }
|
---|
29 | /** Get disance to point.
|
---|
30 | */
|
---|
31 | inline float Distance(const Vector3 &v) const
|
---|
32 | {
|
---|
33 | return DotProd(v, mNormal) + mD;
|
---|
34 | }
|
---|
35 |
|
---|
36 | enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1};
|
---|
37 | /** Returns 1 if v is on front side, -1 if on back side, 0 if on plane.
|
---|
38 | */
|
---|
39 | int Side(const Vector3 &v, const float threshold = 1e-6) const;
|
---|
40 | /** Finds intersection of line segment between points a and b with plane.
|
---|
41 | @param a start point
|
---|
42 | @param b end point
|
---|
43 | @param t if not NULL, returns parameter value of intersections
|
---|
44 | @param coplanar if not NULL, returns true if plane and line segments are coplanar.
|
---|
45 | */
|
---|
46 | Vector3 FindIntersection(const Vector3 &a,
|
---|
47 | const Vector3 &b,
|
---|
48 | float *t = NULL,
|
---|
49 | bool *coplanar = NULL) const;
|
---|
50 |
|
---|
51 | /** Finds value of intersection parameter t on line segment from a to b.
|
---|
52 | @returns 0 if coplanar, else parameter t
|
---|
53 | */
|
---|
54 | float FindT(const Vector3 &a, const Vector3 &b) const;
|
---|
55 |
|
---|
56 |
|
---|
57 | ///////////
|
---|
58 | //-- friends
|
---|
59 |
|
---|
60 | friend bool PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
|
---|
61 |
|
---|
62 | friend bool PlaneIntersection(const Plane3 &p1, const Plane3 &p2);
|
---|
63 |
|
---|
64 | friend std::ostream &operator<<(std::ostream &s, const Plane3 &p)
|
---|
65 | {
|
---|
66 | s << p.mNormal << " " << p.mD;
|
---|
67 | return s;
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | ///////////////
|
---|
72 |
|
---|
73 | Vector3 mNormal;
|
---|
74 | float mD;
|
---|
75 |
|
---|
76 | //////////////////
|
---|
77 |
|
---|
78 | };
|
---|
79 |
|
---|
80 | }
|
---|
81 | #endif
|
---|