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