[372] | 1 | #ifndef _Plane3_H__
|
---|
| 2 | #define _Plane3_H__
|
---|
| 3 |
|
---|
| 4 | #include "Vector3.h"
|
---|
| 5 |
|
---|
[860] | 6 | namespace GtpVisibilityPreprocessor {
|
---|
| 7 |
|
---|
[372] | 8 |
|
---|
| 9 | /** 3D Plane */
|
---|
| 10 | class Plane3 {
|
---|
| 11 | public:
|
---|
| 12 |
|
---|
| 13 | Vector3 mNormal;
|
---|
| 14 | float mD;
|
---|
| 15 |
|
---|
| 16 | Plane3() {}
|
---|
| 17 |
|
---|
| 18 | Plane3(const Vector3 &a,
|
---|
[437] | 19 | const Vector3 &b,
|
---|
| 20 | const Vector3 &c
|
---|
[1076] | 21 | );
|
---|
[372] | 22 |
|
---|
| 23 | Plane3(const Vector3 &normal,
|
---|
[504] | 24 | const Vector3 &point
|
---|
[1076] | 25 | );
|
---|
[372] | 26 |
|
---|
[396] | 27 | void ReverseOrientation()
|
---|
| 28 | {
|
---|
| 29 | mNormal *= -1;
|
---|
| 30 | mD *= -1;
|
---|
| 31 | }
|
---|
[372] | 32 |
|
---|
| 33 | float Distance(const Vector3 &v) const {
|
---|
| 34 | return DotProd(v, mNormal) + mD;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[697] | 37 | enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1};
|
---|
| 38 |
|
---|
| 39 |
|
---|
[639] | 40 | /** Returns 1 if v is on front side, -1 if on back side, 0 if on plane.
|
---|
| 41 | */
|
---|
| 42 | int Side(const Vector3 &v, const float threshold = 1e-6) const;
|
---|
[372] | 43 |
|
---|
[437] | 44 | /** Finds intersection of line segment between points a and b with plane.
|
---|
| 45 | @param a start point
|
---|
| 46 | @param b end point
|
---|
| 47 | @param t if not NULL, returns parameter value of intersections
|
---|
| 48 | @param coplanar if not NULL, returns true if plane and line segments are coplanar.
|
---|
| 49 | */
|
---|
[372] | 50 | Vector3 FindIntersection(const Vector3 &a,
|
---|
[448] | 51 | const Vector3 &b,
|
---|
| 52 | float *t = NULL,
|
---|
[639] | 53 | bool *coplanar = NULL) const;
|
---|
[372] | 54 |
|
---|
[437] | 55 | /** Finds value of intersection parameter t on line segment from a to b.
|
---|
[639] | 56 | @returns 0 if coplanar, else parameter t
|
---|
[437] | 57 | */
|
---|
[639] | 58 | float FindT(const Vector3 &a, const Vector3 &b) const;
|
---|
[372] | 59 |
|
---|
| 60 | friend bool
|
---|
| 61 | PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
|
---|
| 62 |
|
---|
| 63 | friend ostream &operator<<(ostream &s, const Plane3 p) {
|
---|
| 64 | s<<p.mNormal<<" "<<p.mD;
|
---|
| 65 | return s;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 |
|
---|
[1047] | 72 | /** A definition for an axis aligned plane.
|
---|
| 73 | */
|
---|
| 74 | struct AxisAlignedPlane
|
---|
| 75 | {
|
---|
| 76 | public:
|
---|
| 77 | AxisAlignedPlane(){}
|
---|
| 78 | AxisAlignedPlane(const int axis, const float position):
|
---|
[1418] | 79 | mAxis(axis), mPosition(position), mOrientation(false)
|
---|
[1047] | 80 | {
|
---|
| 81 | }
|
---|
| 82 | Plane3 GetPlane() const
|
---|
| 83 | {
|
---|
[1418] | 84 | Vector3 normal(0,0,0); normal[mAxis] = mOrientation ? 1.0f : -1.0f;
|
---|
[1047] | 85 | Vector3 point(0,0,0); point[mAxis] = mPosition;
|
---|
| 86 |
|
---|
| 87 | return Plane3(normal, point);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /// the split axis: one of 0=x, 1=y, 2=z
|
---|
| 91 | int mAxis;
|
---|
| 92 | /// the absolute position of the split axis
|
---|
| 93 | float mPosition;
|
---|
[1418] | 94 | /// the plane orientation
|
---|
| 95 | bool mOrientation;
|
---|
| 96 |
|
---|
| 97 | friend ostream &operator<<(ostream &s, const AxisAlignedPlane &p)
|
---|
| 98 | {
|
---|
| 99 | s << "a: " << p.mAxis << " p: " << p.mPosition;
|
---|
| 100 | return s;
|
---|
| 101 | }
|
---|
[1047] | 102 | };
|
---|
[860] | 103 | }
|
---|
[372] | 104 | #endif
|
---|