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