#include <portal.h>
Nevrax France
Definition at line 55 of file portal.h.
Public Member Functions | |
bool | clipPyramid (NLMISC::CVector &observer, std::vector< NLMISC::CPlane > &pyramid) |
bool | clipRay (const NLMISC::CVector &start, const NLMISC::CVector &end) |
return true if the portal clip the segment | |
CPortal () | |
CCluster * | getCluster (uint pos) |
return the cluster linked to the portal | |
std::string | getName () |
uint8 | getNbCluster () |
return the number of clusters linked to the portal | |
const std::vector< NLMISC::CVector > & | getPoly () |
void | getPoly (std::vector< NLMISC::CVector > &dest) const |
get this cluster poly in local coordinates | |
bool | isInFront (NLMISC::CVector &v) |
Return true if the vertex v is in front of the portal. | |
bool | isOpened () |
void | open (bool opened) |
void | resetClusterLinks () |
set all link to clusters to NULL. | |
void | serial (NLMISC::IStream &f) |
Serial. | |
bool | setCluster (CCluster *cluster) |
return false if more than 2 clusters added | |
void | setName (std::string &name) |
bool | setPoly (const std::vector< NLMISC::CVector > &poly) |
return false if the polygon is not convex | |
void | setWorldMatrix (const NLMISC::CMatrix &WM) |
const std::string & | getOcclusionModel () |
uint | getOcclusionModelId () |
const std::string & | getOpenOcclusionModel () |
uint | getOpenOcclusionModelId () |
void | setOcclusionModel (const std::string &occlusionModel) |
void | setOpenOcclusionModel (const std::string &occlusionModel) |
Private Attributes | |
CCluster * | _Clusters [2] |
std::vector< NLMISC::CVector > | _LocalPoly |
std::string | _Name |
NLMISC::TStringId | _OcclusionModelId |
bool | _Opened |
NLMISC::TStringId | _OpenOcclusionModelId |
std::vector< NLMISC::CVector > | _Poly |
Friends | |
class | CInstanceGroup |
Friend class. |
|
Definition at line 48 of file portal.cpp. References _OcclusionModelId, _Opened, and _OpenOcclusionModelId.
00049 { 00050 _Clusters[0] = _Clusters[1] = NULL; 00051 _Opened = true; 00052 _OcclusionModelId = CStringMapper::map("no occlusion"); 00053 _OpenOcclusionModelId = CStringMapper::map("no occlusion"); 00054 } |
|
Clip the view pyramid (all planes pass through observer point) against the portal
Definition at line 83 of file portal.cpp. References _Opened, _Poly, NLMISC::CPolygon::clip(), uint, and NLMISC::CPolygon::Vertices. Referenced by NL3D::CCluster::recursTraverseClip().
00084 { 00085 if (!_Opened || _Poly.size()<3) 00086 return false; 00087 // Clip portal with pyramid 00088 CPolygon p; 00089 p.Vertices = _Poly; 00090 p.clip( &pyramid[1], pyramid.size()-1 ); 00091 00092 // Construct pyramid with clipped portal 00093 if( p.Vertices.size() > 2 ) 00094 { 00095 uint i; 00096 // Found the right orientation 00097 CVector n = (p.Vertices[1]-p.Vertices[0])^(p.Vertices[2]-p.Vertices[0]); 00098 if( ((observer-p.Vertices[0])*n) < 0.0f ) 00099 { 00100 // Invert vertices 00101 for( i = 0; i < (p.Vertices.size()/2); ++i ) 00102 { 00103 CVector tmp = p.Vertices[i]; 00104 p.Vertices[i] = p.Vertices[p.Vertices.size()-1-i]; 00105 p.Vertices[p.Vertices.size()-1-i] = tmp; 00106 } 00107 } 00108 // Make pyramid : preserve 0 and 1 plane which are near and far plane 00109 pyramid.resize (p.Vertices.size()+2); 00110 for( i = 0; i < (p.Vertices.size()); ++i ) 00111 { 00112 pyramid[i+2].make( observer, p.Vertices[i], p.Vertices[(i+1)%p.Vertices.size()] ); 00113 } 00114 return true; 00115 } 00116 00117 return false; 00118 } |
|
return true if the portal clip the segment
Definition at line 262 of file portal.cpp. References _Poly, NLMISC::CPlane::d, NLMISC::CPlane::getNormal(), NLMISC::CPlane::make(), sint, and uint. Referenced by NL3D::CCluster::cameraRayClip().
00263 { 00264 if(_Poly.size()<3) 00265 return false; 00266 00267 // Avoid precision problem, make local to poly 00268 const CVector &refVert= _Poly[0]; 00269 CVector start= startWorld - refVert; 00270 CVector end= endWorld - refVert; 00271 00272 // compute the plane of this poly, local to polygon 00273 CPlane plane; 00274 plane.make(CVector::Null, _Poly[1] - refVert, _Poly[2] - refVert); 00275 CVector normal = plane.getNormal(); 00276 00277 float np1 = normal*end; 00278 float np2 = np1-normal*start; 00279 00280 if (np2 == 0.0f) 00281 return false; 00282 00283 float lambda = (plane.d+np1)/np2; 00284 00285 // Checks the intersection belongs to the segment 00286 if (lambda < 0 || lambda > 1.0f) 00287 return false; 00288 00289 // The intersection on the plane 00290 CVector hit = start*lambda+end*(1.0f-lambda); 00291 00292 // Do convex test on each border 00293 sint sign= 0; 00294 uint polySize= _Poly.size(); 00295 for(uint i=0;i<polySize;i++) 00296 { 00297 const CVector v0= _Poly[i] - refVert; 00298 const CVector v1= _Poly[(i+1)%polySize] - refVert; 00299 float d = ((v1-v0)^normal)*(hit-v0); 00300 if(d<0) 00301 { 00302 if(sign==1) 00303 return false; 00304 else 00305 sign=-1; 00306 } 00307 else if(d>0) 00308 { 00309 if(sign==-1) 00310 return false; 00311 else 00312 sign=1; 00313 } 00314 else 00315 return false; 00316 } 00317 00318 // all on same side, ok! 00319 return true; 00320 } |
|
return the cluster linked to the portal
Definition at line 84 of file portal.h. References uint. Referenced by NL3D::CCluster::cameraRayClip(), and NL3D::CCluster::recursTraverseClip().
00084 { return _Clusters[pos]; } |
|
Definition at line 101 of file portal.h.
00101 { return _Name; } |
|
return the number of clusters linked to the portal
Definition at line 156 of file portal.cpp. References uint8.
|
|
Definition at line 60 of file portal.cpp. References _OcclusionModelId.
00061 {
00062 return CStringMapper::unmap(_OcclusionModelId);
00063 }
|
|
Definition at line 64 of file portal.cpp. References _OcclusionModelId, and uint.
00065 { 00066 return _OcclusionModelId; 00067 } |
|
Definition at line 72 of file portal.cpp. References _OpenOcclusionModelId.
00073 {
00074 return CStringMapper::unmap(_OpenOcclusionModelId);
00075 }
|
|
Definition at line 76 of file portal.cpp. References _OpenOcclusionModelId, and uint.
00077 { 00078 return _OpenOcclusionModelId; 00079 } |
|
Definition at line 91 of file portal.h. References _LocalPoly.
00091 {return _LocalPoly;} |
|
get this cluster poly in local coordinates
Definition at line 209 of file portal.cpp. References _LocalPoly.
00210 { 00211 dest = _LocalPoly; 00212 } |
|
Return true if the vertex v is in front of the portal.
Definition at line 121 of file portal.cpp. Referenced by NL3D::CCluster::recursTraverseClip().
|
|
Definition at line 104 of file portal.h. References _Opened.
00104 { return _Opened; } |
|
Definition at line 103 of file portal.h. References _Opened.
00103 { _Opened = opened; } |
|
set all link to clusters to NULL. Accessors --------- Definition at line 134 of file portal.cpp.
|
|
Serial.
Definition at line 216 of file portal.cpp. References _LocalPoly, _OcclusionModelId, _OpenOcclusionModelId, _Poly, NLMISC::IStream::isReading(), NLMISC::IStream::serial(), NLMISC::IStream::serialCont(), and NLMISC::IStream::serialVersion().
00217 { 00218 int version = f.serialVersion (1); 00219 00220 f.serialCont (_LocalPoly); 00221 if (f.isReading()) 00222 _Poly = _LocalPoly; 00223 f.serial (_Name); 00224 00225 if (version >= 1) 00226 { 00227 if (f.isReading()) 00228 { 00229 std::string occName; 00230 f.serial(occName); 00231 if (occName.empty()) 00232 occName = "no occlusion"; 00233 _OcclusionModelId = CStringMapper::map(occName); 00234 00235 f.serial(occName); 00236 if (occName.empty()) 00237 occName = "no occlusion"; 00238 _OpenOcclusionModelId = CStringMapper::map(occName); 00239 } 00240 else 00241 { 00242 std::string occName = CStringMapper::unmap(_OcclusionModelId); 00243 if (occName == "no occlusion") 00244 occName = ""; 00245 f.serial(occName); 00246 occName = CStringMapper::unmap(_OpenOcclusionModelId); 00247 if (occName == "no occlusion") 00248 occName = ""; 00249 f.serial(occName); 00250 } 00251 } 00252 } |
|
return false if more than 2 clusters added
Definition at line 140 of file portal.cpp.
|
|
Definition at line 99 of file portal.h.
00099 { _Name = name; } |
|
Definition at line 56 of file portal.cpp. References _OcclusionModelId.
00057 { 00058 _OcclusionModelId = CStringMapper::map(occlusionModel); 00059 } |
|
Definition at line 68 of file portal.cpp. References _OpenOcclusionModelId.
00069 { 00070 _OpenOcclusionModelId = CStringMapper::map(occlusionModel); 00071 } |
|
return false if the polygon is not convex
Definition at line 167 of file portal.cpp. References _LocalPoly, _Poly, NLMISC::CPlane::make(), NLMISC::CPlane::normalize(), PORTALPRECISION, and uint.
00168 { 00169 uint i; 00170 00171 if( poly.size() < 3 ) 00172 return false; 00173 00174 // Check if the polygon is a plane 00175 CPlane p; 00176 p.make( poly[0], poly[1], poly[2] ); 00177 p.normalize(); 00178 float dist; 00179 for( i = 0; i < (poly.size()-3); ++i ) 00180 { 00181 dist = fabsf(p*poly[i+3]); 00182 if( dist > PORTALPRECISION ) 00183 return false; 00184 } 00185 00186 // Check if the polygon is convex 00188 /* 00189 CPlane p2; 00190 for( i = 0; i < (poly.size()-1); ++i ) 00191 { 00192 p2.make( poly[i], poly[i+1], poly[i]+p.getNormal() ); 00193 for( j = 0; j < poly.size(); ++j ) 00194 if( (j != i) && (j != i+1) ) 00195 { 00196 if( p2*poly[j] < 0.0f ) 00197 return false; 00198 } 00199 }*/ 00200 00201 // Set the value 00202 _LocalPoly = poly; 00203 _Poly = poly; 00204 00205 return true; 00206 } |
|
Definition at line 255 of file portal.cpp. References _LocalPoly, _Poly, NLMISC::CMatrix::mulPoint(), and uint32. Referenced by NL3D::CInstanceGroup::addToSceneWhenAllShapesLoaded(), and NL3D::CCluster::traverseHrc().
00256 { 00257 for (uint32 i = 0; i < _LocalPoly.size(); ++i) 00258 _Poly[i] = WM.mulPoint(_LocalPoly[i]); 00259 } |
|
Friend class.
|
|
|
|
Definition at line 126 of file portal.h. Referenced by getPoly(), serial(), setPoly(), and setWorldMatrix(). |
|
|
|
Definition at line 131 of file portal.h. Referenced by CPortal(), getOcclusionModel(), getOcclusionModelId(), serial(), and setOcclusionModel(). |
|
Definition at line 124 of file portal.h. Referenced by clipPyramid(), CPortal(), isOpened(), and open(). |
|
Definition at line 132 of file portal.h. Referenced by CPortal(), getOpenOcclusionModel(), getOpenOcclusionModelId(), serial(), and setOpenOcclusionModel(). |
|
Definition at line 127 of file portal.h. Referenced by clipPyramid(), clipRay(), isInFront(), serial(), setPoly(), and setWorldMatrix(). |