#include <plane.h>
A vector v is said "front" of a plane p if p*v>0.
A "front segment" or a "front polygon" have all their vertices in front of the plane.
Nevrax France
Definition at line 49 of file plane.h.
Public Member Functions | |
Projection / clipping. | |
sint | clipPolygonBack (CVector in[], CVector out[], sint nIn) const |
sint | clipPolygonFront (CVector in[], CVector out[], sint nIn) const |
bool | clipSegmentBack (CVector &p0, CVector &p1) const |
bool | clipSegmentFront (CVector &p0, CVector &p1) const |
float | distance (const CVector &p) const |
CVector | intersect (const CVector &p0, const CVector &p1) const |
Intersect a line onto a plane. p1 is returned if line // to plane. | |
float | operator * (const CVector &p) const |
Return plane*vector. | |
CVector | project (const CVector &p0) const |
Project a point onto a plane. | |
Object. | |
CPlane (const CPlane &v) | |
Copy Constructor. | |
CPlane (float _a, float _b, float _c, float _d) | |
Constructor . | |
CPlane () | |
Constructor that does nothing. | |
Construction/Get. | |
CVector | getNormal () const |
void | make (const CVector &p0, const CVector &p1, const CVector &p2) |
void | make (const CVector &normal, const CVector &pos) |
void | normalize () |
CPlane | normed () const |
normal inversion | |
void | invert () |
invert this plane (same position, but inverted normal) | |
CPlane | inverted () const |
get the inverted version of this plane (same position, but inverted normal) | |
Misc | |
bool | operator== (const CPlane &o) const |
void | serial (IStream &f) |
Data Fields | |
float | a |
float | b |
float | c |
float | d |
|
Constructor that does nothing.
Definition at line 59 of file plane.h. Referenced by inverted().
00059 {} |
|
Constructor .
Definition at line 61 of file plane.h.
|
|
Copy Constructor.
Definition at line 63 of file plane.h.
|
|
Clip a polygon by a plane. The "back polygon" is returned. Nb: Out must be allocated to nIn+1 (at less).
Definition at line 97 of file plane.cpp. References in, intersect(), s, and sint. Referenced by NLMISC::CPolygon::clip(), and NL3D::CCameraCol::minimizeDistanceAgainstTri().
00098 { 00099 sint nOut=0,s,p,i; 00100 if(nIn<=2) return 0; 00101 00102 s=nIn-1; 00103 00104 for (i=0;i<nIn;i++) 00105 { 00106 p=i; 00107 if ( (*this)*in[p] < 0 ) 00108 { 00109 if ( (*this)*in[s] > 0 ) 00110 out[nOut++]= intersect(in[s],in[p]); 00111 out[nOut++]=in[p]; 00112 } 00113 else 00114 { 00115 if ( (*this)*in[s] < 0 ) 00116 out[nOut++]= intersect(in[s],in[p]); 00117 } 00118 s=p; 00119 } 00120 00121 return nOut; 00122 } |
|
Clip a polygon by a plane. The "front polygon" is returned. Nb: Out must be allocated to nIn+1 (at less).
Definition at line 125 of file plane.cpp. References in, intersect(), s, and sint. Referenced by NL3D::CCubeGrid< TCell >::project().
00126 { 00127 sint nOut=0,s,p,i; 00128 if(nIn<=2) return 0; 00129 00130 s=nIn-1; 00131 00132 for (i=0;i<nIn;i++) 00133 { 00134 p=i; 00135 if ( (*this)*in[p] > 0 ) 00136 { 00137 if ( (*this)*in[s] < 0 ) 00138 out[nOut++]= intersect(in[s],in[p]); 00139 out[nOut++]=in[p]; 00140 } 00141 else 00142 { 00143 if ( (*this)*in[s] > 0 ) 00144 out[nOut++]= intersect(in[s],in[p]); 00145 } 00146 s=p; 00147 } 00148 00149 return nOut; 00150 } |
|
Clip a segment onto a plane. The "back segment" is written in (p1,p2). If segment is entirely "front", (p1,p2) is not modified.
Definition at line 54 of file plane.cpp. Referenced by NLMISC::CAABBox::clipSegment(), and NLMISC::CAABBox::intersect().
00055 { 00056 float d0,d1,decal; 00057 CVector proj; 00058 00059 d0= (*this)*p0; 00060 d1= (*this)*p1; 00061 if(d0<0 && d1<0) 00062 return true; 00063 if(d0>=0 && d1>=0) 00064 return false; 00065 // Clip line. 00066 decal= (0-d0) / (d1-d0); 00067 proj= p0+ (p1-p0)*decal; 00068 if(d0>=0) 00069 p0=proj; 00070 else 00071 p1=proj; 00072 return true; 00073 } |
|
Clip a segment onto a plane. The "front segment" is written in (p1,p2). If segment is entirely "back", (p1,p2) is not modified.
Definition at line 74 of file plane.cpp.
00075 { 00076 float d0,d1,decal; 00077 CVector proj; 00078 00079 d0= (*this)*p0; 00080 d1= (*this)*p1; 00081 if(d0>=0 && d1>=0) 00082 return true; 00083 if(d0<0 && d1<0) 00084 return false; 00085 // Clip line. 00086 decal= (0-d0) / (d1-d0); 00087 proj= p0+ (p1-p0)*decal; 00088 if(d0<0) 00089 p0=proj; 00090 else 00091 p1=proj; 00092 return true; 00093 } |
|
Return the distance of p from the plane. Hence, the result is >=0. Since the plane normal may not be normalized, distance() compute the distance with the normalized normal of plane. If you are sure that your plane has a normalized normal, it is much faster to do a Definition at line 40 of file plane_inline.h.
|
|
Return the normal vector of the plane. Since the normal of the plane may not be normalized (if setuped without make()), the returned normal may NOT be normalized. Definition at line 35 of file plane_inline.h. Referenced by NL3D::CZoneLighter::buildZoneInformation(), NL3D::CPortal::clipRay(), NL3D::CInstanceGroup::displayDebugClusters(), NL3D::CMiniCol::getGroundNormal(), NLSOUND::CClusteredSound::getPolyNearestPos(), NL3D::CCameraCol::minimizeDistanceAgainstTri(), normalize(), NL3D::CPSZoneRectangle::performMotion(), NL3D::CPSZoneDisc::performMotion(), NL3D::CPSZonePlane::performMotion(), project(), and NL3D::CRenderZBuffer::run().
00036 {
00037 return CVector(a,b,c);
00038 }
|
|
Intersect a line onto a plane. p1 is returned if line // to plane.
Definition at line 51 of file plane_inline.h. Referenced by clipPolygonBack(), clipPolygonFront(), NL3D::CMiniCol::getGroundNormal(), NLPACS::CLocalRetriever::getHeight(), NLMISC::CBSPNode2v::insert(), NL3D::CEvent3dMouseListener::operator()(), project(), NL3D::CCubeGrid< TCell >::project(), NL3D::CCubeGrid< TCell >::select(), NL3D::CMiniCol::snapToGround(), NLPACS::CLocalRetriever::snapToInteriorGround(), and NL3D::CVisualCollisionEntity::triangleIntersect().
00052 { 00053 float decal; 00054 float da= (*this)*p0; 00055 float db= (*this)*p1; 00056 if(db-da == 0) 00057 return p0; 00058 decal= ( 0-da ) / ( db - da ); 00059 return p0 + (p1-p0)*decal; 00060 } |
|
invert this plane (same position, but inverted normal)
Definition at line 160 of file plane.cpp.
|
|
get the inverted version of this plane (same position, but inverted normal)
Definition at line 154 of file plane.cpp. References a, b, c, CPlane(), and d.
00155 { 00156 return CPlane(-a, -b, -c, -d); 00157 } |
|
Make a plane with 3 vertices. NB: the plane normal is normalized by make(). Definition at line 44 of file plane.cpp.
|
|
|
Normalize the plane, such that getNormal() return a normalized vector. Definition at line 68 of file plane_inline.h. References a, b, c, d, getNormal(), and NLMISC::CVector::norm(). Referenced by NL3D::CBSPTree< T >::CBSPNode::CBSPNode(), NL3D::CMeshMRMSkinnedGeom::clip(), NL3D::CMeshMRMGeom::clip(), NL3D::CMeshGeom::clip(), NL3D::CInstanceGroup::displayDebugClusters(), NL3D::CCluster::makeVolume(), normed(), and NL3D::CPortal::setPoly().
|
|
return the normalized version of a plane.
Definition at line 81 of file plane_inline.h. References normalize(). Referenced by distance().
00082 { 00083 CPlane ret= *this; 00084 ret.normalize(); 00085 return ret; 00086 } |
|
Return plane*vector.
Definition at line 46 of file plane_inline.h. References a, b, c, d, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.
|
|
Definition at line 161 of file plane.h.
|
|
Project a point onto a plane.
Definition at line 62 of file plane_inline.h. References getNormal(), and intersect(). Referenced by NL3D::CInstanceGroup::displayDebugClusters(), and NLSOUND::CClusteredSound::getPolyNearestPos().
|
|
Definition at line 155 of file plane.h. References a, b, c, d, and NLMISC::IStream::serial().
00156 { 00157 f.serial(a,b,c,d); 00158 } |
|
Definition at line 52 of file plane.h. Referenced by CPlane(), getNormal(), invert(), inverted(), make(), normalize(), operator *(), NLMISC::operator *(), operator==(), NL3D::CHeatHaze::performHeatHaze(), and serial(). |
|
Definition at line 52 of file plane.h. Referenced by CPlane(), getNormal(), invert(), inverted(), make(), normalize(), operator *(), NLMISC::operator *(), operator==(), and serial(). |
|
Definition at line 52 of file plane.h. Referenced by CPlane(), getNormal(), invert(), inverted(), make(), normalize(), operator *(), NLMISC::operator *(), operator==(), NL3D::CHeatHaze::performHeatHaze(), and serial(). |
|
Definition at line 52 of file plane.h. Referenced by NL3D::CPortal::clipRay(), NL3D::CWaterModel::computeClippedPoly(), CPlane(), invert(), inverted(), make(), NL3D::CCameraCol::minimizeDistanceAgainstTri(), normalize(), operator *(), NLMISC::operator *(), operator==(), NL3D::CHeatHaze::performHeatHaze(), and serial(). |