[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 |
|
---|
[2911] | 10 | /** Class describing a 3D Plane.
|
---|
[2751] | 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 | */
|
---|
[2911] | 37 | int Side(const Vector3 &v, float threshold = 1e-6) const;
|
---|
[2751] | 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 |
|
---|
[2911] | 54 | operator const float*() const
|
---|
| 55 | {
|
---|
| 56 | return (const float*) this;
|
---|
| 57 | }
|
---|
[2751] | 58 |
|
---|
[2911] | 59 | float& operator[] (const int inx)
|
---|
| 60 | {
|
---|
| 61 | return (&mNormal.x)[inx];
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | const float &operator[] (const int inx) const
|
---|
| 65 | {
|
---|
| 66 | return *(&mNormal.x + inx);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[2755] | 69 | ///////////
|
---|
[2751] | 70 | //-- friends
|
---|
| 71 |
|
---|
| 72 | friend bool PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
|
---|
| 73 |
|
---|
| 74 | friend bool PlaneIntersection(const Plane3 &p1, const Plane3 &p2);
|
---|
[2911] | 75 |
|
---|
[2751] | 76 |
|
---|
| 77 | friend std::ostream &operator<<(std::ostream &s, const Plane3 &p)
|
---|
| 78 | {
|
---|
[2755] | 79 | s << p.mNormal << " " << p.mD;
|
---|
[2751] | 80 | return s;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | ///////////////
|
---|
| 85 |
|
---|
| 86 | Vector3 mNormal;
|
---|
| 87 | float mD;
|
---|
| 88 | };
|
---|
| 89 |
|
---|
[2911] | 90 |
|
---|
[2751] | 91 | }
|
---|
| 92 | #endif
|
---|