#include <primitive_world_image.h>
Nevrax France
Definition at line 43 of file primitive_world_image.h.
Public Member Functions | |
| void | addMoveElement (CMoveCell &cell, uint16 x, uint16 y, double centerX, double centerY, CMovePrimitive *primitive, CMoveContainer &container, uint8 worldImage) |
| Add the primitive in the cell and resort the list. | |
| void | checkSortedList (uint8 worldImage) |
| Check sorted lists. | |
| void | copy (const CPrimitiveWorldImage &source) |
| CPrimitiveWorldImage () | |
| void | CPrimitiveWorldImage::addMoveElementendOfList (CMoveCell &cell, uint16 x, uint16 y, CMovePrimitive *primitive, CMoveContainer &container) |
| Add the primitive in the cell at the end of the list and don't sort. | |
| void | deleteIt (CMoveContainer &container, uint8 worldImage) |
| void | dirtBB (CMoveContainer *container, CMovePrimitive *primitive, uint8 worldImage) |
| void | dirtPos (CMoveContainer *container, CMovePrimitive *primitive, uint8 worldImage) |
| void | doMove (double timeMax) |
| void | doMove (CGlobalRetriever &retriever, CCollisionSurfaceTemp &surfaceTemp, double originalMax, double finalMax, bool keepZ=false) |
| const TCollisionSurfaceDescVector * | evalCollision (CGlobalRetriever &retriever, CCollisionSurfaceTemp &surfaceTemp, uint32 testTime, uint32 maxTestIteration, CMovePrimitive &primitive) |
| bool | evalCollision (CPrimitiveWorldImage &other, class CCollisionDesc &desc, double timeMin, double timeMax, uint32 testTime, uint32 maxTestIteration, double &firstContactTime, double &lastContactTime, CMovePrimitive &primitive, CMovePrimitive &otherPrimitive) |
| bool | evalCollisionOBoverOB (CPrimitiveWorldImage &other, CCollisionDesc &desc, double timeMin, double timeMax, double &firstContactTime, double &lastContactTime, CMovePrimitive &primitive, CMovePrimitive &otherPrimitive) |
| bool | evalCollisionOBoverOC (CPrimitiveWorldImage &other, CCollisionDesc &desc, double timeMin, double timeMax, double &firstContactTime, double &lastContactTime, CMovePrimitive &primitive, CMovePrimitive &otherPrimitive) |
| bool | evalCollisionOCoverOC (CPrimitiveWorldImage &other, CCollisionDesc &desc, double timeMin, double timeMax, double &firstContactTime, double &lastContactTime, CMovePrimitive &primitive, CMovePrimitive &otherPrimitive) |
| bool | evalCollisionPoverOC (CPrimitiveWorldImage &other, CCollisionDesc &desc, uint numPoint, double &firstContactTime, double &lastContactTime, CMovePrimitive &primitive, CMovePrimitive &otherPrimitive) |
| bool | evalCollisionPoverS (CPrimitiveWorldImage &other, CCollisionDesc &desc, uint numPoint, uint numSeg, CMovePrimitive &primitive, CMovePrimitive &otherPrimitive) |
| bool | evalCollisionSoverOC (CPrimitiveWorldImage &other, CCollisionDesc &desc, uint numPoint, CMovePrimitive &primitive, CMovePrimitive &otherPrimitive) |
| double | getBBXMax () const |
| double | getBBXMin () const |
| double | getBBYMax () const |
| double | getBBYMin () const |
| const NLMISC::CVectorD & | getDeltaPosition () const |
| NLMISC::CVectorD | getFinalPosition () const |
| const UGlobalPosition & | getGlobalPosition () |
| double | getInitTime () const |
| CMoveElement * | getMoveElement (uint i) |
| Return the nieme MoveElement. The primitive can have 4 move elements. Can be NULL if the ineme elment is not in a list. | |
| CMovePrimitive * | getNextModified () const |
| Get next modified primitive. | |
| double | getOrientation () const |
| const NLMISC::CVectorD & | getSpeed () const |
| bool | isInModifiedListFlag () |
| Is in modified list ? | |
| bool | isInWorldImageFlag () |
| Is in modified list ? | |
| void | linkInModifiedList (CMovePrimitive *next) |
| void | move (const NLMISC::CVectorD &speed, CMoveContainer &container, CMovePrimitive &primitive, uint8 worldImage) |
| void | precalcBB (double beginTime, double endTime, CMovePrimitive &primitive) |
| void | precalcPos (CMovePrimitive &primitive) |
| void | precalcSpeed () |
| void | reaction (const CCollisionSurfaceDesc &surfaceDesc, const UGlobalPosition &globalPosition, CGlobalRetriever &retriever, double ratio, double dt, CMovePrimitive &primitive, CMoveContainer &container, uint8 worldImage) |
| void | reaction (CPrimitiveWorldImage &second, const CCollisionDesc &desc, CGlobalRetriever *retriver, CCollisionSurfaceTemp &surfaceTemp, bool collision, CMovePrimitive &primitive, CMovePrimitive &otherPrimitive, CMoveContainer *container, uint8 worldImage, uint8 secondWorldImage, bool secondConst) |
| void | removeMoveElement (uint i, CMoveContainer &container, uint8 worldImage) |
| Remove the nieme MoveElement. | |
| void | setGlobalPosition (const NLMISC::CVectorD &pos, CMoveContainer &container, CMovePrimitive &primitive, uint8 worldImage, bool keepZ=false, UGlobalPosition::TType type=UGlobalPosition::Unspecified) |
| void | setGlobalPosition (const UGlobalPosition &pos, CMoveContainer &container, CMovePrimitive &primitive, uint8 worldImage) |
| void | setInModifiedListFlag (bool itis) |
| Clear the inModifiedList flag. | |
| void | setInWorldImageFlag (bool itis) |
| Clear the inModifiedList flag. | |
| void | setOrientation (double rot, CMoveContainer *container, CMovePrimitive *primitive, uint8 worldImage) |
| void | setSpeed (const NLMISC::CVectorD &speed, CMoveContainer *container, CMovePrimitive *primitive, uint8 worldImage) |
| void | update (double beginTime, double endTime, CMovePrimitive &primitive) |
| Update precalculated data. | |
Private Types | |
| enum | TDynamicFlags { DirtPosFlag = 0x0001, DirtBBFlag = 0x0002, InModifiedListFlag = 0x0004, InWorldImageFlag = 0x0008, ForceSize = 0xffff } |
Private Attributes | |
| NLMISC::CVectorD | _3dInitPosition |
| double | _BBXMax |
| double | _BBXMin |
| double | _BBYMax |
| double | _BBYMin |
| NLMISC::CVectorD | _DeltaPosition |
| uint16 | _DynamicFlags |
| double | _InitTime |
| CMoveElement * | _MoveElement [4] |
| CMovePrimitive * | _NextModified |
| CPosition | _Position |
| NLMISC::CVectorD | _Speed |
|
|
Definition at line 385 of file primitive_world_image.h.
00386 {
00387 // The dirt flag. Precalculated data for the position must be recomputed.
00388 DirtPosFlag =0x0001,
00389
00390 // The dirt bounding box. Precalculated data for the bounding box must be recomputed.
00391 DirtBBFlag =0x0002,
00392
00393 // In modified list.
00394 InModifiedListFlag =0x0004,
00395
00396 // Inserted in the world image.
00397 InWorldImageFlag =0x0008,
00398
00399 // Force the size to uint16.
00400 ForceSize =0xffff
00401 };
|
|
|
Definition at line 42 of file primitive_world_image.cpp. References _BBXMax, _BBXMin, _BBYMax, _BBYMin, _DynamicFlags, _MoveElement, and uint.
00043 {
00044 // Set to NULL
00045 for (uint i=0; i<4; i++)
00046 _MoveElement[i]=NULL;
00047
00048 _DynamicFlags=0;
00049 _BBXMin=-FLT_MAX;
00050 _BBXMax=-FLT_MAX;
00051 _BBYMin=-FLT_MAX;
00052 _BBYMax=-FLT_MAX;
00053 }
|
|
||||||||||||||||||||||||||||||||||||
|
Add the primitive in the cell and resort the list.
Definition at line 1058 of file primitive_world_image.cpp. References _BBXMax, _BBXMin, _MoveElement, NLPACS::CMoveContainer::allocateMoveElement(), NLPACS::CMoveCell::linkFirstX(), NLPACS::CMoveCell::linkLastX(), NLPACS::CMoveElement::Primitive, uint, uint16, uint8, NLPACS::CMoveCell::updateSortedLists(), NLPACS::CMoveElement::X, x, NLPACS::CMoveElement::Y, and y.
01060 {
01061 // Find a free place
01062 uint slot;
01063 for (slot=0; slot<4; slot++)
01064 {
01065 // Empty ?
01066 if (_MoveElement[slot]==NULL)
01067 {
01068 // Primitive center
01069 double cx=(_BBXMin+_BBXMax)/2.f;
01070
01071 // Allocate move element
01072 _MoveElement[slot]=container.allocateMoveElement ();
01073 _MoveElement[slot]->Primitive=primitive;
01074 _MoveElement[slot]->X=x;
01075 _MoveElement[slot]->Y=y;
01076
01077 // Insert in left or right ?
01078 if (cx<centerX)
01079 // In the left
01080 cell.linkFirstX (_MoveElement[slot]);
01081 else
01082 // In the right
01083 cell.linkLastX (_MoveElement[slot]);
01084
01085 /*// Insert in left or right ?
01086 if (cy<centerY)
01087 // In the left
01088 cell.linkFirstY (_MoveElement[slot]);
01089 else
01090 // In the right
01091 cell.linkLastY (_MoveElement[slot]);*/
01092
01093 // Move it
01094 cell.updateSortedLists (_MoveElement[slot], worldImage);
01095
01096 // End
01097 break;
01098 }
01099 }
01100 }
|
|
|
Check sorted lists.
Definition at line 1149 of file primitive_world_image.cpp. References _BBXMin, _MoveElement, NLPACS::CMovePrimitive::getWorldImage(), NLPACS::CMoveElement::NextX, nlassertonce, NLPACS::CMoveElement::PreviousX, NLPACS::CMoveElement::Primitive, uint, and uint8.
01150 {
01151 // For the 4 elements
01152 for (uint i=0; i<4; i++)
01153 {
01154 // element here ?
01155 if (_MoveElement[i])
01156 {
01157 if (_MoveElement[i]->PreviousX)
01158 nlassertonce (_MoveElement[i]->PreviousX->Primitive->getWorldImage(worldImage)->_BBXMin <= _BBXMin);
01159 if (_MoveElement[i]->NextX)
01160 nlassertonce (_BBXMin <= _MoveElement[i]->NextX->Primitive->getWorldImage(worldImage)->_BBXMin);
01161 }
01162 }
01163 }
|
|
|
Definition at line 66 of file primitive_world_image.cpp. References _DynamicFlags, _MoveElement, InModifiedListFlag, and uint.
00067 {
00068 // Copy
00069 this->operator=(source);
00070
00071 // Reset some flags
00072 _DynamicFlags&=~InModifiedListFlag;
00073
00074 // Pointer into the 4 possibles sorted lists of movable primitives. Must be NULL
00075 for (uint i=0; i<4; i++)
00076 _MoveElement[i]=NULL;
00077 }
|
|
||||||||||||||||||||||||
|
Add the primitive in the cell at the end of the list and don't sort.
|
|
||||||||||||
|
Definition at line 57 of file primitive_world_image.cpp. References _MoveElement, removeMoveElement(), uint, and uint8.
00058 {
00059 // Free the move elements
00060 for (uint i=0; i<4; i++)
00061 if (_MoveElement[i])
00062 removeMoveElement (i, container, worldImage);
00063 }
|
|
||||||||||||||||
|
Definition at line 277 of file primitive_world_image.h. References _DynamicFlags, NLPACS::CMoveContainer::changed(), DirtBBFlag, and uint8. Referenced by dirtPos().
00278 {
00279 // Warn container that BB has changed
00280 container->changed (primitive, worldImage);
00281
00282 _DynamicFlags|=DirtBBFlag;
00283 }
|
|
||||||||||||||||
|
Definition at line 270 of file primitive_world_image.h. References _DynamicFlags, dirtBB(), DirtPosFlag, and uint8. Referenced by NLPACS::CMovePrimitive::dirtAllPos(), move(), reaction(), setGlobalPosition(), setOrientation(), and setSpeed().
00271 {
00272 _DynamicFlags|=DirtPosFlag;
00273 dirtBB (container, primitive, worldImage);
00274 }
|
|
|
Definition at line 230 of file primitive_world_image.cpp. References NLPACS::CPrimitiveWorldImage::CPosition::getPos(), and NLPACS::CPrimitiveWorldImage::CPosition::setPos().
|
|
||||||||||||||||||||||||
|
Definition at line 201 of file primitive_world_image.cpp. References _DeltaPosition, NLPACS::CGlobalRetriever::doMove(), NLPACS::CPrimitiveWorldImage::CPosition::getGlobalPos(), H_AUTO, NLPACS::CPrimitiveWorldImage::CPosition::setGlobalPos(), and NLPACS::CPrimitiveWorldImage::CPosition::setGlobalPosKeepZ().
00202 {
00203 H_AUTO(NLPACS_PWI_Do_Move);
00204
00205
00206 // Time to avance
00207 double ratio;
00208 if (finalMax!=originalMax)
00209 ratio=(finalMax-_InitTime)/(originalMax-_InitTime);
00210 else
00211 ratio=1;
00212
00213 // Make the move
00214 if (!keepZ)
00215 {
00216 _Position.setGlobalPos (retriever.doMove(_Position.getGlobalPos(), _DeltaPosition, (float)ratio, surfaceTemp, false), retriever);
00217 }
00218 else
00219 {
00220 _Position.setGlobalPosKeepZ(retriever.doMove(_Position.getGlobalPos(), _DeltaPosition, (float)ratio, surfaceTemp, false), retriever);
00221 }
00222
00223
00224 // Final position
00225 _InitTime=finalMax;
00226 }
|
|
||||||||||||||||||||||||
|
Eval collisions with the global retriever.
Definition at line 166 of file primitive_world_image.cpp. References _DeltaPosition, _OBData, NLPACS::CMovePrimitive::checkTestTime(), NLPACS::CPrimitiveWorldImage::CPosition::getGlobalPos(), NLPACS::CMovePrimitive::getLength(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), NLPACS::CMovePrimitive::getRadiusInternal(), nlassert, NLPACS::TCollisionSurfaceDescVector, NLPACS::CGlobalRetriever::testBBoxMove(), NLPACS::CGlobalRetriever::testCylinderMove(), and uint32.
00168 {
00169 // H_AUTO(PACS_PWI_evalCollision_short);
00170
00171 // Test time
00172 if (!primitive.checkTestTime (testTime, maxTestIteration))
00173 return NULL;
00174
00175 // Switch the good test
00176 if (primitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedBox)
00177 {
00178 // Local I
00179 CVector locI ((float)(_OBData.EdgeDirectionX[0]*primitive.getLength(0)/2.0), (float)(_OBData.EdgeDirectionY[0]*primitive.getLength(1)/2.0), 0);
00180
00181 // Local J
00182 CVector locJ ((float)(_OBData.EdgeDirectionX[1]*primitive.getLength(0)/2.0), (float)(_OBData.EdgeDirectionY[1]*primitive.getLength(1)/2.0), 0);
00183
00184 // Test
00185 return retriever.testBBoxMove (_Position.getGlobalPos (), _DeltaPosition, locI, locJ, surfaceTemp);
00186 }
00187 else
00188 {
00189 // Check
00190 nlassert (primitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedCylinder);
00191
00192 // Test
00193 //nlinfo ("1) %f %f %f\n", _DeltaPosition.x, _DeltaPosition.y, _DeltaPosition.z);
00194
00195 return retriever.testCylinderMove (_Position.getGlobalPos (), _DeltaPosition, primitive.getRadiusInternal(), surfaceTemp);
00196 }
00197 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Eval collisions with the other primitive.
Definition at line 81 of file primitive_world_image.cpp. References NLPACS::CMovePrimitive::checkTestTime(), evalCollisionOBoverOB(), evalCollisionOBoverOC(), evalCollisionOCoverOC(), NLPACS::CMovePrimitive::getCollisionMaskInternal(), NLPACS::CMovePrimitive::getOcclusionMaskInternal(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), nlstop, uint32, and NLPACS::CCollisionDesc::XChgContactNormals().
00084 {
00085 // H_AUTO(PACS_PWI_evalCollision_long);
00086
00087 // Mask test
00088 if (( (primitive.getCollisionMaskInternal() & otherPrimitive.getOcclusionMaskInternal()) == 0) &&
00089 ( (primitive.getOcclusionMaskInternal() & otherPrimitive.getCollisionMaskInternal()) == 0))
00090 return false;
00091
00092 // Test time
00093 if ( (!primitive.checkTestTime (testTime, maxTestIteration)) || (!otherPrimitive.checkTestTime (testTime, maxTestIteration)) )
00094 return false;
00095
00096 // Clear time min time max
00097 firstContactTime=FLT_MAX;
00098 lastContactTime=-FLT_MAX;
00099
00100 // Switch the good test
00101 switch (primitive.getPrimitiveTypeInternal())
00102 {
00103
00104 // Static box over...
00105 case UMovePrimitive::_2DOrientedBox:
00106 {
00107 // Switch second type
00108 switch (otherPrimitive.getPrimitiveTypeInternal())
00109 {
00110
00111 // Static box over movable box
00112 case UMovePrimitive::_2DOrientedBox:
00113 // Make the test
00114 return evalCollisionOBoverOB (other, desc, timeMin, timeMax, firstContactTime, lastContactTime, primitive, otherPrimitive);
00115
00116 // Static box over movable cylinder
00117 case UMovePrimitive::_2DOrientedCylinder:
00118 // Make the test
00119 return evalCollisionOBoverOC (other, desc, timeMin, timeMax, firstContactTime, lastContactTime, primitive, otherPrimitive);
00120
00121 default:
00122 // Should not go here
00123 nlstop;
00124 }
00125 }
00126
00127 // Static box over...
00128 case UMovePrimitive::_2DOrientedCylinder:
00129 {
00130 // Switch second type
00131 switch (otherPrimitive.getPrimitiveTypeInternal())
00132 {
00133
00134 // Static box over movable box
00135 case UMovePrimitive::_2DOrientedBox:
00136 {
00137 // Make the test
00138 bool collid=other.evalCollisionOBoverOC (*this, desc, timeMin, timeMax, firstContactTime, lastContactTime, otherPrimitive,
00139 primitive);
00140 if (collid)
00141 desc.XChgContactNormals ();
00142 return collid;
00143 }
00144
00145 // Static box over movable cylinder
00146 case UMovePrimitive::_2DOrientedCylinder:
00147 // Make the test
00148 return evalCollisionOCoverOC (other, desc, timeMin, timeMax, firstContactTime, lastContactTime, primitive, otherPrimitive);
00149
00150 default:
00151 // Should not go here
00152 nlstop;
00153 }
00154 }
00155
00156 default:
00157 // Should not go here
00158 nlstop;
00159 }
00160
00161 return false;
00162 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 243 of file primitive_world_image.cpp. References NLPACS::UCollisionDesc::ContactTime, evalCollisionPoverS(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), nlassert, and uint. Referenced by evalCollision().
00246 {
00247 // Checks
00248 nlassert (primitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedBox);
00249 nlassert (otherPrimitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedBox);
00250
00251 // Find a collision
00252 bool find=false;
00253
00254 // Best time
00255 desc.ContactTime=FLT_MAX;
00256
00257 // Timemin
00258 double _timeMax=-FLT_MAX;
00259
00260 // Check movable points over the edge
00261 uint pt;
00262 uint seg;
00263 for (pt=0; pt<4; pt++)
00264 for (seg=0; seg<4; seg++)
00265 {
00266 // Get collision time of the point over the segment
00267 CCollisionDesc d;
00268 if ( evalCollisionPoverS (other, d, pt, seg, primitive, otherPrimitive) )
00269 {
00270 // Find
00271 find=true;
00272
00273 // Best time ?
00274 if (d.ContactTime<desc.ContactTime)
00275 {
00276 // This is the new descriptor
00277 desc=d;
00278 }
00279
00280 // Best max time ?
00281 if (d.ContactTime>_timeMax)
00282 {
00283 // This is the new max time
00284 _timeMax=d.ContactTime;
00285 }
00286 }
00287 }
00288
00289 // Check static points over the movable box
00290 for (pt=0; pt<4; pt++)
00291 for (seg=0; seg<4; seg++)
00292 {
00293 // Get collision time of the point over the segment
00294 CCollisionDesc d;
00295 if (other.evalCollisionPoverS (*this, d, pt, seg, primitive, otherPrimitive))
00296 {
00297 // Find
00298 find=true;
00299
00300 // Best time ?
00301 if (d.ContactTime<desc.ContactTime)
00302 {
00303 // This is the new descriptor
00304 desc=d;
00305 }
00306
00307 // Best max time ?
00308 if (d.ContactTime>_timeMax)
00309 {
00310 // This is the new max time
00311 _timeMax=d.ContactTime;
00312 }
00313 }
00314 }
00315
00316 if (find)
00317 {
00318 // First last contact time
00319 firstContactTime=desc.ContactTime;
00320 lastContactTime=_timeMax;
00321
00322 // Half time
00323 //double halfTime = (_timeMax+desc.ContactTime)/2.0;
00324
00325 // Collision in the past ?
00326 //if (timeMin > halfTime)
00327 if (timeMin > _timeMax)
00328 // yes, abort
00329 return false;
00330
00331 // Collision not in the future ?
00332 if (timeMax>desc.ContactTime)
00333 {
00334 // Clamp time
00335 if (desc.ContactTime<timeMin)
00336 desc.ContactTime=timeMin;
00337
00338 // yes, found it
00339 return true;
00340 }
00341 }
00342
00343 // No collision found
00344 return false;
00345 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 349 of file primitive_world_image.cpp. References NLPACS::UCollisionDesc::ContactTime, evalCollisionPoverOC(), evalCollisionSoverOC(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), nlassert, and uint. Referenced by evalCollision().
00352 {
00353 // Checks
00354 nlassert (primitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedBox);
00355 nlassert (otherPrimitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedCylinder);
00356
00357 // Find a collision
00358 bool find=false;
00359
00360 // Best time
00361 desc.ContactTime=FLT_MAX;
00362
00363 // time min clip
00364 double _timeMax = -FLT_MAX;
00365
00366 // Check movable points over the cylinder
00367 uint pt;
00368 for (pt=0; pt<4; pt++)
00369 {
00370 // Get collision time of the point over the segment
00371 CCollisionDesc d;
00372 double firstContactTime;
00373 double lastContactTime;
00374 if (evalCollisionPoverOC (other, d, pt, firstContactTime, lastContactTime, primitive, otherPrimitive))
00375 {
00376 // Found
00377 find=true;
00378
00379 // Best time ?
00380 if (firstContactTime<desc.ContactTime)
00381 {
00382 // This is the new descriptor
00383 desc=d;
00384 }
00385
00386 // Best max time ?
00387 if (lastContactTime>_timeMax)
00388 {
00389 // New max time
00390 _timeMax=lastContactTime;
00391 }
00392 }
00393 }
00394
00395 // Check static points over the movable box
00396 uint seg;
00397 for (seg=0; seg<4; seg++)
00398 {
00399 // Get collision time of the point over the segment
00400 CCollisionDesc d;
00401 if (evalCollisionSoverOC (other, d, seg, primitive, otherPrimitive))
00402 {
00403 // Found
00404 find=true;
00405
00406 // Best time ?
00407 if (d.ContactTime<desc.ContactTime)
00408 {
00409 // This is the new descriptor
00410 desc=d;
00411 }
00412
00413 // Best max time ?
00414 if (d.ContactTime>_timeMax)
00415 {
00416 // New max time
00417 _timeMax=d.ContactTime;
00418 }
00419 }
00420 }
00421
00422 if (find)
00423 {
00424 // First last contact time
00425 firstContactTime=desc.ContactTime;
00426 lastContactTime=_timeMax;
00427
00428 // Half time
00429 //double halfTime = (_timeMax+desc.ContactTime)/2.0;
00430
00431 // Collision in the past ?
00432 //if (timeMin > halfTime)
00433 if (timeMin > _timeMax)
00434 // yes, abort
00435 return false;
00436
00437 // Collision not in the future ?
00438 if (timeMax>desc.ContactTime)
00439 {
00440 // Clamp time
00441 if (desc.ContactTime<timeMin)
00442 desc.ContactTime=timeMin;
00443
00444 // yes, found it
00445 return true;
00446 }
00447 }
00448
00449 // No collision found
00450 return false;
00451 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 780 of file primitive_world_image.cpp. References _3dInitPosition, _Speed, NLPACS::UCollisionDesc::ContactNormal0, NLPACS::UCollisionDesc::ContactNormal1, NLPACS::UCollisionDesc::ContactPosition, NLPACS::UCollisionDesc::ContactTime, NLPACS::CMovePrimitive::getHeightInternal(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), NLPACS::CMovePrimitive::getRadiusInternal(), nlassert, NLMISC::CVectorD::normalize(), NLPACS::secondDegree(), uint, NLMISC::CVectorD::x, NLMISC::CVectorD::y, and NLMISC::CVectorD::z. Referenced by evalCollision().
00783 {
00784 // Checks
00785 nlassert (primitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedCylinder);
00786 nlassert (otherPrimitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedCylinder);
00787
00788
00789 /* Cylinder0 center equ:
00790 * p(t) = p0 + v0*(t - t0)
00791 *
00792 * Cylinder1 center equ:
00793 * p'(t) = p'0 + v'0*(t - t'0)
00794 *
00795 * Find t for this equation:
00796 * (R + R')² = Norm² (p(t) - p'(t))
00797 * (R + R')² = Norm² ( p0 + v0 ( t - t0 ) - p'0 - v'0 ( t - t'0 ) )
00798 *
00799 * A = p0 - v0*t0 - p'0 + v'0*t'0
00800 * B = (v0 - v'0)
00801 *
00802 * Norm² (B)*t² + 2*(A.B)*t + Norm² (A) - (R + R')² = 0
00803 *
00804 * a = Norm² (B)
00805 * b = 2*(A.B)
00806 * c = Norm² (A) - (R + R')²
00807 *
00808 * a*t² + b*t + c = 0
00809 */
00810
00811 // Let's go
00812 const double _Ax = _3dInitPosition.x - other._3dInitPosition.x;
00813 const double _Ay = _3dInitPosition.y - other._3dInitPosition.y;
00814 const double _Bx = _Speed.x - other._Speed.x;
00815 const double _By = _Speed.y - other._Speed.y;
00816
00817 // Eval system
00818 double s0, s1;
00819 double radiusSquare=primitive.getRadiusInternal()+otherPrimitive.getRadiusInternal();
00820 radiusSquare*=radiusSquare;
00821 uint numSolution=secondDegree (_Bx*_Bx+_By*_By, 2.f*(_Ax*_Bx+_Ay*_By), _Ax*_Ax+_Ay*_Ay-radiusSquare, s0, s1);
00822 if (numSolution!=0)
00823 {
00824 // time
00825 double _timeMin, _timeMax;
00826
00827 // Collision time
00828 if (numSolution==1)
00829 {
00830 _timeMin=s0;
00831 _timeMax=s0;
00832 }
00833 else
00834 {
00835 // Time min and max
00836 if (s0>s1)
00837 {
00838 _timeMin=s1;
00839 _timeMax=s0;
00840 }
00841 else
00842 {
00843 _timeMin=s0;
00844 _timeMax=s1;
00845 }
00846 }
00847
00848 // half time
00849 //const double halfTime=(_timeMin+_timeMax)/2.0;
00850
00851 // Conatct time
00852 firstContactTime=_timeMin;
00853 lastContactTime=_timeMax;
00854
00855 // Clip time
00856 if ((timeMin<_timeMax)&&(_timeMin<timeMax))
00857 {
00858 // Some constants
00859 const double cyl0Time= _timeMin;
00860 const double pointCyl0Z=_3dInitPosition.z;
00861 const double cyl0PosZ= pointCyl0Z + _Speed.z*cyl0Time;
00862
00863 // Pos Z
00864 const double cyl1Time= _timeMin;
00865 const double pointCyl1Z=other._3dInitPosition.z;
00866 const double cyl1PosZ= pointCyl1Z + other._Speed.z * cyl1Time;
00867
00868 // Z Included ?
00869 if ( (cyl0PosZ <= cyl1PosZ + otherPrimitive.getHeightInternal() ) && (cyl0PosZ + primitive.getHeightInternal() >= cyl1PosZ) )
00870 {
00871 // Ok Collision, fill the result
00872
00873 // Time
00874 desc.ContactTime=std::max (_timeMin, timeMin);
00875
00876 // Cylinder 0 position
00877 const double cyl0PosX= _3dInitPosition.x + _Speed.x*cyl0Time;
00878 const double cyl0PosY= _3dInitPosition.y + _Speed.y*cyl0Time;
00879
00880 // Cylinder 1 position
00881 const double cyl1PosX= other._3dInitPosition.x + other._Speed.x*cyl1Time;
00882 const double cyl1PosY= other._3dInitPosition.y + other._Speed.y*cyl1Time;
00883
00884 // First cylinder normal
00885 desc.ContactNormal0.x= cyl1PosX - cyl0PosX;
00886 desc.ContactNormal0.y= cyl1PosY - cyl0PosY;
00887 desc.ContactNormal0.z= 0;
00888 desc.ContactNormal0.normalize ();
00889
00890 // Contact position
00891 desc.ContactPosition.x= desc.ContactNormal0.x*primitive.getRadiusInternal() + cyl0PosX;
00892 desc.ContactPosition.y= desc.ContactNormal0.y*primitive.getRadiusInternal() + cyl0PosY;
00893 desc.ContactPosition.z= std::max (cyl0PosZ, cyl1PosZ);
00894
00895 // Second cylinder normal
00896 desc.ContactNormal1.x= -desc.ContactNormal0.x;
00897 desc.ContactNormal1.y= -desc.ContactNormal0.y;
00898 desc.ContactNormal1.z= 0;
00899
00900 // End
00901 return true;
00902 }
00903 }
00904 }
00905
00906 // No collision
00907 return false;
00908 }
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 573 of file primitive_world_image.cpp. References _3dInitPosition, _OBData, _Speed, NLPACS::UCollisionDesc::ContactNormal0, NLPACS::UCollisionDesc::ContactNormal1, NLPACS::UCollisionDesc::ContactPosition, NLPACS::UCollisionDesc::ContactTime, NLPACS::CMovePrimitive::getHeightInternal(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), NLPACS::CMovePrimitive::getRadiusInternal(), nlassert, NLMISC::CVectorD::normalize(), NLPACS::secondDegree(), uint, NLMISC::CVectorD::x, NLMISC::CVectorD::y, and NLMISC::CVectorD::z. Referenced by evalCollisionOBoverOC().
00576 {
00577 // Checks
00578 nlassert (primitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedBox);
00579 nlassert (otherPrimitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedCylinder);
00580
00581 /* Point Equ:
00582 * p(t) = p0 + v0*(t - t0)
00583 *
00584 * Cylinder center Equ:
00585 * p'(t) = p'0 + v'0*(t - t'0)
00586 *
00587 * Find t for this equation:
00588 * R² = Norm² (p(t) - p'(t))
00589 * R² = Norm² ( p0 + v0 ( t - t0 ) - p'0 - v'0 ( t - t'0 ) )
00590 *
00591 * A = p0 - v0*t0 - p'0 + v'0*t'0
00592 * B = (v0 - v'0)
00593 *
00594 * Norm² (B)*t² + 2*(A.B)*t + Norm² (A) - R² = 0
00595 *
00596 * a = Norm² (B)
00597 * b = 2*(A.B)
00598 * c = Norm² (A) - R²
00599 *
00600 * a*t² + b*t + c = 0
00601 */
00602
00603 // Let's go
00604 const double _Ax = _OBData.PointPosX[numPoint] - other._3dInitPosition.x;
00605 const double _Ay = _OBData.PointPosY[numPoint] - other._3dInitPosition.y;
00606 const double _Bx = _Speed.x - other._Speed.x;
00607 const double _By = _Speed.y - other._Speed.y;
00608
00609 // Eval system
00610 double s0, s1;
00611 double squareRadius=otherPrimitive.getRadiusInternal()*otherPrimitive.getRadiusInternal();
00612 uint numSolution=secondDegree (_Bx*_Bx+_By*_By, 2.f*(_Ax*_Bx+_Ay*_By), _Ax*_Ax+_Ay*_Ay-squareRadius, s0, s1);
00613 if (numSolution!=0)
00614 {
00615 // time
00616 double time;
00617
00618 // Collision time
00619 if (numSolution==1)
00620 {
00621 firstContactTime=s0;
00622 lastContactTime=s0;
00623 }
00624 else
00625 {
00626 // First and last time
00627 if (s0<s1)
00628 {
00629 firstContactTime=s0;
00630 lastContactTime=s1;
00631 }
00632 else
00633 {
00634 firstContactTime=s1;
00635 lastContactTime=s0;
00636 }
00637 }
00638 time=firstContactTime;
00639
00640 // Pos Z
00641 const double pointCylZ=other._3dInitPosition.z;
00642 const double cylPosZ= pointCylZ + other._Speed.z*time;
00643
00644 // Some constants
00645 const double pointZ=_3dInitPosition.z;
00646 const double ptPosZ= pointZ + _Speed.z*time;
00647
00648 // Z Included ?
00649 if ( (ptPosZ <= cylPosZ + otherPrimitive.getHeightInternal()) && (ptPosZ + primitive.getHeightInternal() >= cylPosZ) )
00650 {
00651 // Ok Collision, fill the result
00652
00653 // Time
00654 desc.ContactTime=time;
00655
00656 // Point position
00657 const double ptPosX= _OBData.PointPosX[numPoint] + _Speed.x*time;
00658 const double ptPosY= _OBData.PointPosY[numPoint] + _Speed.y*time;
00659
00660 // Cylinder position
00661 const double cylPosX= other._3dInitPosition.x + other._Speed.x*time;
00662 const double cylPosY= other._3dInitPosition.y + other._Speed.y*time;
00663
00664 // Position
00665 desc.ContactPosition.x=ptPosX;
00666 desc.ContactPosition.y=ptPosY;
00667 desc.ContactPosition.z=std::max (cylPosZ, ptPosZ);
00668
00669 // Cylinder normal
00670 desc.ContactNormal1.x=ptPosX-cylPosX;
00671 desc.ContactNormal1.y=ptPosY-cylPosY;
00672 desc.ContactNormal1.z=0;
00673 desc.ContactNormal1.normalize ();
00674 desc.ContactNormal0.x=-desc.ContactNormal1.x;
00675 desc.ContactNormal0.y=-desc.ContactNormal1.y;
00676 desc.ContactNormal0.z=0;
00677
00678 // End
00679 return true;
00680 }
00681 }
00682
00683 // No collision
00684 return false;
00685 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 455 of file primitive_world_image.cpp. References _3dInitPosition, _OBData, _Speed, NLPACS::UCollisionDesc::ContactNormal0, NLPACS::UCollisionDesc::ContactNormal1, NLPACS::UCollisionDesc::ContactPosition, NLPACS::UCollisionDesc::ContactTime, NLPACS::CMovePrimitive::getHeightInternal(), NLPACS::CMovePrimitive::getLength(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), nlassert, uint, NLMISC::CVectorD::x, NLMISC::CVectorD::y, and NLMISC::CVectorD::z. Referenced by evalCollisionOBoverOB().
00457 {
00458 // Checks
00459 nlassert (primitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedBox);
00460 nlassert (otherPrimitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedBox);
00461
00462 // Some constants
00463 const double normalSegX=other._OBData.EdgeDirectionY[numSeg];
00464 const double normalSegY=-other._OBData.EdgeDirectionX[numSeg];
00465
00466 // Relative speed
00467 const double speedX=other._Speed.x-_Speed.x;
00468 const double speedY=other._Speed.y-_Speed.y;
00469
00470 // Dot product with the plan tangeante
00471 double dotProd= speedX*normalSegX + speedY*normalSegY;
00472 //if ( dotProd > 0 )
00473 if ( dotProd != 0 )
00474 {
00475 // Time of the collision
00476 double time= (normalSegX*(_OBData.PointPosX[numPoint] - other._OBData.PointPosX[numSeg]) +
00477 normalSegY*(_OBData.PointPosY[numPoint] - other._OBData.PointPosY[numSeg])) / dotProd;
00478
00479 // Position of segment point at collision time
00480 const double segPosX= other._OBData.PointPosX[numSeg] + other._Speed.x*time;
00481 const double segPosY= other._OBData.PointPosY[numSeg] + other._Speed.y*time;
00482
00483 // Position of the point at collision time
00484 const double ptPosX= _OBData.PointPosX[numPoint] + _Speed.x*time;
00485 const double ptPosY= _OBData.PointPosY[numPoint] + _Speed.y*time;
00486
00487 // Direction of the collision on the segment
00488 const double dirX= ptPosX - segPosX;
00489 const double dirY= ptPosY - segPosY;
00490
00491 // Length of this vector
00492 const double length= dirY*normalSegX - dirX*normalSegY;
00493
00494 // Included ?
00495 if ( ( length >= 0 ) && ( length <= otherPrimitive.getLength(numSeg&1) ) )
00496 {
00497 // 2d Collid checked... Now check height
00498
00499 // Pos Z
00500 const double pointSegZ=other._3dInitPosition.z;
00501 const double segPosZ= pointSegZ + other._Speed.z*time;
00502
00503 // Some constants
00504 const double pointZ=_3dInitPosition.z;
00505 const double ptPosZ= pointZ + _Speed.z*time;
00506
00507 // Included ?
00508 if ( (ptPosZ <= segPosZ + otherPrimitive.getHeightInternal()) && (ptPosZ + primitive.getHeightInternal() >= segPosZ) )
00509 {
00510 // Ok Collision, fill the result
00511
00512 // Time
00513 desc.ContactTime=time;
00514
00515 // Position
00516 desc.ContactPosition.x=ptPosX;
00517 desc.ContactPosition.y=ptPosY;
00518 desc.ContactPosition.z=std::max (segPosZ, ptPosZ);
00519
00520 // Seg box normal
00521 desc.ContactNormal1.x=normalSegX;
00522 desc.ContactNormal1.y=normalSegY;
00523 desc.ContactNormal1.z=0;
00524 desc.ContactNormal0.x=-desc.ContactNormal1.x;
00525 desc.ContactNormal0.y=-desc.ContactNormal1.y;
00526 desc.ContactNormal0.z=0;
00527
00528 // End
00529 return true;
00530 }
00531 }
00532 }
00533
00534 // No collision
00535 return false;
00536 }
|
|
||||||||||||||||||||||||
|
Definition at line 689 of file primitive_world_image.cpp. References _3dInitPosition, _OBData, _Speed, NLPACS::UCollisionDesc::ContactNormal0, NLPACS::UCollisionDesc::ContactNormal1, NLPACS::UCollisionDesc::ContactPosition, NLPACS::UCollisionDesc::ContactTime, NLPACS::CMovePrimitive::getHeightInternal(), NLPACS::CMovePrimitive::getLength(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), NLPACS::CMovePrimitive::getRadiusInternal(), nlassert, NLMISC::CVectorD::normalize(), uint, NLMISC::CVectorD::x, NLMISC::CVectorD::y, and NLMISC::CVectorD::z. Referenced by evalCollisionOBoverOC().
00691 {
00692 // Checks
00693 nlassert (primitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedBox);
00694 nlassert (otherPrimitive.getPrimitiveTypeInternal()==UMovePrimitive::_2DOrientedCylinder);
00695
00696 // Some constants
00697 const double normalSegX=_OBData.EdgeDirectionY[numSeg];
00698 const double normalSegY=-_OBData.EdgeDirectionX[numSeg];
00699
00700 // Relative speed
00701 const double speedX=other._Speed.x-_Speed.x;
00702 const double speedY=other._Speed.y-_Speed.y;
00703
00704 // Dot product with the plan tangeante
00705 double dotProd= speedX*normalSegX + speedY*normalSegY;
00706 //if ( dotProd < 0 )
00707 if ( dotProd !=0 )
00708 {
00709 // Time of the collision
00710 double time= (otherPrimitive.getRadiusInternal() + normalSegX*(_OBData.PointPosX[numSeg] - other._3dInitPosition.x ) +
00711 normalSegY*(_OBData.PointPosY[numSeg] - other._3dInitPosition.y ) ) / dotProd;
00712
00713 // Position of segment point at collision time
00714 const double segPosX= _OBData.PointPosX[numSeg] + _Speed.x*time;
00715 const double segPosY= _OBData.PointPosY[numSeg] + _Speed.y*time;
00716
00717 // Position of the cylinder at collision time
00718 const double cylPosX= other._3dInitPosition.x + _Speed.x*time;
00719 const double cylPosY= other._3dInitPosition.y + _Speed.y*time;
00720
00721 // Position de contact
00722 const double contactX= cylPosX - normalSegX*otherPrimitive.getRadiusInternal();
00723 const double contactY= cylPosY - normalSegY*otherPrimitive.getRadiusInternal();
00724
00725 // Direction of the collision on the segment
00726 const double dirX= contactX - segPosX;
00727 const double dirY= contactY - segPosY;
00728
00729 // Length of this vector
00730 const double length= dirY*normalSegX - dirX*normalSegY;
00731
00732 // Included ?
00733 if ( ( length >= 0 ) && ( length <= primitive.getLength (numSeg&1) ) )
00734 {
00735 // 2d Collid checked... Now check height
00736
00737 // Pos Z
00738 const double segPosZ= _3dInitPosition.z + _Speed.z*time;
00739
00740 // Some constants
00741 const double cylPosZ= other._3dInitPosition.z + other._Speed.z*time;
00742
00743 // Included ?
00744 if ( (cylPosZ <= segPosZ + primitive.getHeightInternal() ) && (cylPosZ + otherPrimitive.getHeightInternal() >= segPosZ) )
00745 {
00746 // Ok Collision, fill the result
00747
00748 // Time
00749 desc.ContactTime=time;
00750
00751 // Position
00752 desc.ContactPosition.x=contactX;
00753 desc.ContactPosition.y=contactY;
00754 desc.ContactPosition.z=std::max (segPosZ, cylPosZ);
00755
00756 // Segment normal
00757 desc.ContactNormal0.x=normalSegX;
00758 desc.ContactNormal0.y=normalSegY;
00759 desc.ContactNormal0.z=0;
00760
00761 // Seg box normal
00762 desc.ContactNormal1.x=contactX-cylPosX;
00763 desc.ContactNormal1.y=contactY-cylPosY;
00764 desc.ContactNormal1.z=0;
00765 desc.ContactNormal1.normalize ();
00766
00767 // End
00768 return true;
00769 }
00770 }
00771 }
00772
00773 // No collision
00774 return false;
00775 }
|
|
|
Return max of the bounding box in X. Definition at line 192 of file primitive_world_image.h. References _BBXMax.
00193 {
00194 return _BBXMax;
00195 }
|
|
|
Return min of the bounding box in X. Definition at line 176 of file primitive_world_image.h. References _BBXMin. Referenced by NLPACS::CMoveCell::updateSortedLists().
00177 {
00178 return _BBXMin;
00179 }
|
|
|
Return max of the bounding box in Y. Definition at line 200 of file primitive_world_image.h. References _BBYMax.
00201 {
00202 return _BBYMax;
00203 }
|
|
|
Return min of the bounding box in Y. Definition at line 184 of file primitive_world_image.h. References _BBYMin.
00185 {
00186 return _BBYMin;
00187 }
|
|
|
Return the delta position Definition at line 208 of file primitive_world_image.h. References _DeltaPosition.
00209 {
00210 return _DeltaPosition;
00211 }
|
|
|
Get the position of the move primitive at the end of the movement.
Definition at line 78 of file primitive_world_image.h. References NLPACS::CPrimitiveWorldImage::CPosition::getPos().
|
|
|
Definition at line 258 of file primitive_world_image.h. References NLPACS::CPrimitiveWorldImage::CPosition::getGlobalPos().
00259 {
00260 return _Position.getGlobalPos();
00261 }
|
|
|
Definition at line 286 of file primitive_world_image.h.
00287 {
00288 return _InitTime;
00289 }
|
|
|
Return the nieme MoveElement. The primitive can have 4 move elements. Can be NULL if the ineme elment is not in a list.
Definition at line 214 of file primitive_world_image.h. References _MoveElement, and uint.
00215 {
00216 return _MoveElement[i];
00217 }
|
|
|
Get next modified primitive.
Definition at line 168 of file primitive_world_image.h. References _NextModified.
00169 {
00170 return _NextModified;
00171 }
|
|
|
Definition at line 264 of file primitive_world_image.h. References _OBData.
00265 {
00266 return _OBData.Orientation;
00267 }
|
|
|
Get the speed vector for this primitive. the new speed vector. Definition at line 125 of file primitive_world_image.h.
00126 {
00127 // New time
00128 return _Speed;
00129 }
|
|
|
Is in modified list ?
Definition at line 132 of file primitive_world_image.h. References _DynamicFlags, and InModifiedListFlag. Referenced by NLPACS::CMoveContainer::changed().
00133 {
00134 return (_DynamicFlags&InModifiedListFlag) != 0;
00135 }
|
|
|
Is in modified list ?
Definition at line 153 of file primitive_world_image.h. References _DynamicFlags, and InWorldImageFlag. Referenced by NLPACS::CMovePrimitive::isInserted().
00154 {
00155 return (_DynamicFlags&InWorldImageFlag) != 0;
00156 }
|
|
|
Definition at line 147 of file primitive_world_image.h. References _NextModified. Referenced by NLPACS::CMoveContainer::changed().
00148 {
00149 _NextModified=next;
00150 }
|
|
||||||||||||||||||||
|
Set the speed vector for this primitive. Only for movable primitives.
Definition at line 1480 of file primitive_world_image.cpp. References _3dInitPosition, dirtPos(), NLPACS::CPrimitiveWorldImage::CPosition::getPos(), setSpeed(), and uint8.
01481 {
01482 // New speed
01483 setSpeed (speed, &container, &primitive, worldImage);
01484
01485 // Set initial position
01486 _3dInitPosition = _Position.getPos ();
01487
01488 // Set initial time
01489 _InitTime = 0;
01490
01491 // Dirt BB
01492 dirtPos (&container, &primitive, worldImage);
01493 }
|
|
||||||||||||||||
|
Definition at line 971 of file primitive_world_image.cpp. References _3dInitPosition, _BBXMax, _BBXMin, _BBYMax, _BBYMin, _DeltaPosition, _OBData, NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), NLPACS::CMovePrimitive::getRadiusInternal(), min, nlassert, sint, type, uint, NLMISC::CVectorD::x, and NLMISC::CVectorD::y. Referenced by update().
00972 {
00973 // Type of the primitive
00974 uint type=primitive.getPrimitiveTypeInternal();
00975
00976 // Box ?
00977 if (type==UMovePrimitive::_2DOrientedBox)
00978 {
00979 // Orientation index
00980 sint orient= (sint)(256.f*_OBData.Orientation/(2.f*NLMISC::Pi));
00981 orient&=0xff;
00982 orient>>=6;
00983 nlassert (orient>=0);
00984 nlassert (orient<4);
00985
00986 // Compute coordinates
00987 _BBXMin=FLT_MAX;
00988 _BBYMin=FLT_MAX;
00989 _BBXMax=-FLT_MAX;
00990 _BBYMax=-FLT_MAX;
00991
00992 for (uint i=0; i<4; i++)
00993 {
00994 if (_OBData.PointPosX[i]<_BBXMin)
00995 _BBXMin=_OBData.PointPosX[i];
00996 if (_OBData.PointPosX[i]>_BBXMax)
00997 _BBXMax=_OBData.PointPosX[i];
00998 if (_OBData.PointPosY[i]<_BBYMin)
00999 _BBYMin=_OBData.PointPosY[i];
01000 if (_OBData.PointPosY[i]>_BBYMax)
01001 _BBYMax=_OBData.PointPosY[i];
01002 }
01003 _BBXMin=std::min (std::min (_BBXMin, _BBXMin+endTime*_Speed.x), _BBXMin+beginTime*_Speed.x);
01004 _BBXMax=std::max (std::max (_BBXMax, _BBXMax+endTime*_Speed.x), _BBXMax+beginTime*_Speed.x);
01005 _BBYMin=std::min (std::min (_BBYMin, _BBYMin+endTime*_Speed.y), _BBYMin+beginTime*_Speed.y);
01006 _BBYMax=std::max (std::max (_BBYMax, _BBYMax+endTime*_Speed.y), _BBYMax+beginTime*_Speed.y);
01007
01008 /*
01009 // This code is faster but buggy..
01010 _BBXMin= _OBData.PointPosX[minX[orient]] + _Speed.x*beginTime;
01011 _BBXMin= std::min (_BBXMin, _OBData.PointPosX[minX[orient]] + _Speed.x*endTime);
01012
01013 _BBYMin= _OBData.PointPosY[minY[orient]] + _Speed.y*beginTime;
01014 _BBYMin= std::min (_BBYMin, _OBData.PointPosY[minY[orient]] + _Speed.y*endTime);
01015
01016 _BBXMax= _OBData.PointPosX[maxX[orient]] + _Speed.x*beginTime;
01017 _BBXMax= std::max (_BBXMax, _OBData.PointPosX[maxX[orient]] + _Speed.x*endTime);
01018
01019 _BBYMax= _OBData.PointPosY[maxY[orient]] + _Speed.y*beginTime;
01020 _BBYMax= std::max (_BBYMax, _OBData.PointPosY[maxY[orient]] + _Speed.y*endTime);*/
01021 }
01022 else
01023 {
01024 // Should be a cylinder
01025 nlassert (type==UMovePrimitive::_2DOrientedCylinder);
01026
01027 // Compute X coordinates
01028 _BBXMin= _3dInitPosition.x + _Speed.x*beginTime;
01029 _BBXMax= _3dInitPosition.x + _Speed.x*endTime;
01030 if (_BBXMin>_BBXMax)
01031 {
01032 double tmp=_BBXMin;
01033 _BBXMin=_BBXMax;
01034 _BBXMax=tmp;
01035 }
01036 _BBXMin-=primitive.getRadiusInternal();
01037 _BBXMax+=primitive.getRadiusInternal();
01038
01039 // Compute Y coordinates
01040 _BBYMin= _3dInitPosition.y + _Speed.y*beginTime;
01041 _BBYMax= _3dInitPosition.y + _Speed.y*endTime;
01042 if (_BBYMin>_BBYMax)
01043 {
01044 double tmp=_BBYMin;
01045 _BBYMin=_BBYMax;
01046 _BBYMax=tmp;
01047 }
01048 _BBYMin-=primitive.getRadiusInternal();
01049 _BBYMax+=primitive.getRadiusInternal();
01050 }
01051
01052 // Delta position
01053 _DeltaPosition=_Speed*(endTime-beginTime);
01054 }
|
|
|
Definition at line 912 of file primitive_world_image.cpp. References _3dInitPosition, _OBData, NLPACS::CMovePrimitive::getLength(), NLPACS::CMovePrimitive::getPrimitiveTypeInternal(), nlassert, type, uint, NLMISC::CVectorD::x, and NLMISC::CVectorD::y. Referenced by update().
00913 {
00914 // Type of the primitive
00915 uint type=primitive.getPrimitiveTypeInternal();
00916
00917 // Box ?
00918 if (type==UMovePrimitive::_2DOrientedBox)
00919 {
00920 // Calc cosinus and sinus
00921 double cosinus=(double)cos(_OBData.Orientation);
00922 double sinus=(double)sin(_OBData.Orientation);
00923
00924 // Size
00925 double halfWidth=primitive.getLength (0)/2;
00926 double halfDepth=primitive.getLength (1)/2;
00927
00928 // First point
00929 _OBData.PointPosX[0]=cosinus*(-halfWidth)-sinus*(-halfDepth)+_3dInitPosition.x;
00930 _OBData.PointPosY[0]=sinus*(-halfWidth)+cosinus*(-halfDepth)+_3dInitPosition.y;
00931
00932 // Second point
00933 _OBData.PointPosX[1]=cosinus*halfWidth-sinus*(-halfDepth)+_3dInitPosition.x;
00934 _OBData.PointPosY[1]=sinus*halfWidth+cosinus*(-halfDepth)+_3dInitPosition.y;
00935
00936 // Third point
00937 _OBData.PointPosX[2]=cosinus*halfWidth-sinus*halfDepth+_3dInitPosition.x;
00938 _OBData.PointPosY[2]=sinus*halfWidth+cosinus*halfDepth+_3dInitPosition.y;
00939
00940 // Fourth point
00941 _OBData.PointPosX[3]=cosinus*(-halfWidth)-sinus*halfDepth+_3dInitPosition.x;
00942 _OBData.PointPosY[3]=sinus*(-halfWidth)+cosinus*halfDepth+_3dInitPosition.y;
00943
00944 // Direction
00945 double length0 = (primitive.getLength(0)==0)? 0.001 : primitive.getLength(0);
00946 double length1 = (primitive.getLength(1)==0)? 0.001 : primitive.getLength(1);
00947 double oneOverLength[2]= { 1 / length0, 1 / length1 };
00948
00949 // Direction
00950 uint i;
00951 for (i=0; i<4; i++)
00952 {
00953 // Next index
00954 uint next=(i+1)&3;
00955 double oneOver=oneOverLength[i&1];
00956
00957 // New direction
00958 _OBData.EdgeDirectionX[i]=(_OBData.PointPosX[next] - _OBData.PointPosX[i])*oneOver;
00959 _OBData.EdgeDirectionY[i]=(_OBData.PointPosY[next] - _OBData.PointPosY[i])*oneOver;
00960 }
00961 }
00962 else
00963 {
00964 // Should be a cylinder
00965 nlassert (type==UMovePrimitive::_2DOrientedCylinder);
00966 }
00967 }
|
|
|
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 1350 of file primitive_world_image.cpp. References _3dInitPosition, NLPACS::CCollisionSurfaceDesc::ContactNormal, NLPACS::CCollisionSurfaceDesc::ContactTime, dirtPos(), NLPACS::CMovePrimitive::getAttenuation(), NLPACS::CPrimitiveWorldImage::CPosition::getPos(), NLPACS::CMovePrimitive::getReactionTypeInternal(), NELPACS_DIST_BACK, NLMISC::CVectorD::set(), NLPACS::CPrimitiveWorldImage::CPosition::setGlobalPos(), type, uint32, and uint8.
01353 {
01354 // H_AUTO(PACS_PWI_reaction_short);
01355
01356 // Reaction type
01357 uint32 type=primitive.getReactionTypeInternal();
01358
01359 // Reaction to the collision: copy the CGlobalRetriever::CGlobalPosition
01360 _Position.setGlobalPos (globalPosition, retriever);
01361
01362 // Relfexion or slide ?
01363 if ((type==UMovePrimitive::Reflexion)||(type==UMovePrimitive::Slide))
01364 {
01365 // Slide ?
01366 if (type==UMovePrimitive::Slide)
01367 {
01368 // Project last delta on plane of collision.
01369 _Speed-= surfaceDesc.ContactNormal*(surfaceDesc.ContactNormal*_Speed-NELPACS_DIST_BACK/(dt-surfaceDesc.ContactTime));
01370 }
01371
01372 // Reflexion ?
01373 if (type==UMovePrimitive::Reflexion)
01374 {
01375 // Project last delta on plane of collision.
01376 double speedProj=surfaceDesc.ContactNormal*_Speed;
01377 _Speed-=surfaceDesc.ContactNormal*(speedProj+speedProj*primitive.getAttenuation()-NELPACS_DIST_BACK/(dt-surfaceDesc.ContactTime));
01378 }
01379 }
01380 else
01381 {
01382 // Stop ?
01383 if (type==UMovePrimitive::Stop)
01384 {
01385 _Speed.set (0,0,0);
01386 }
01387 }
01388
01389 // Contact time
01390 double contactTime=surfaceDesc.ContactTime;
01391
01392 // Init position
01393 _3dInitPosition = _Position.getPos() - _Speed * contactTime;
01394
01395 // Set contactTime
01396 _InitTime=contactTime;
01397
01398 // Dirt pos
01399 dirtPos (&container, &primitive, worldImage);
01400 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 1167 of file primitive_world_image.cpp. References _3dInitPosition, _DeltaPosition, _InitTime, _Position, _Speed, NLMISC::clamp(), NLPACS::UCollisionDesc::ContactNormal0, NLPACS::UCollisionDesc::ContactNormal1, NLPACS::UCollisionDesc::ContactTime, dirtPos(), NLPACS::CGlobalRetriever::doMove(), NLPACS::CMovePrimitive::getAttenuation(), NLPACS::CPrimitiveWorldImage::CPosition::getGlobalPos(), NLPACS::CMovePrimitive::getMass(), NLPACS::CPrimitiveWorldImage::CPosition::getPos(), NLPACS::CMovePrimitive::getReactionTypeInternal(), NLPACS::CMovePrimitive::isObstacle(), nlassert, NLMISC::CVectorD::norm(), NLMISC::CVectorD::set(), NLPACS::CPrimitiveWorldImage::CPosition::setGlobalPos(), NLPACS::CPrimitiveWorldImage::CPosition::setPos(), setSpeed(), and uint8.
01171 {
01172 // H_AUTO(PACS_PWI_reaction_long);
01173
01174 // Get the two reaction codes
01175 UMovePrimitive::TReaction firstReaction=primitive.getReactionTypeInternal();
01176 UMovePrimitive::TReaction secondReaction=otherPrimitive.getReactionTypeInternal();
01177
01178 // Overide collsion
01179 collision = collision && (primitive.isObstacle ()) && (otherPrimitive.isObstacle ());
01180
01181 // Get the two mass
01182 float mass0 = primitive.getMass ();
01183 float mass1 = otherPrimitive.getMass ();
01184
01185 // Energy sum
01186 double projSpeed0 = desc.ContactNormal1 * _Speed;
01187 double projSpeed1 = desc.ContactNormal0 * second._Speed;
01188 double energySum = (- mass0 * projSpeed0 - mass1 * projSpeed1 ) / 2.0;
01189
01190 // Old position
01191 CVectorD collisionPosition=_3dInitPosition;
01192 collisionPosition+=_Speed*desc.ContactTime;
01193
01194 // Calc new speed
01195 CVectorD newSpeed;
01196
01197 // Obstacle ?
01198 if (collision)
01199 {
01200 switch (firstReaction)
01201 {
01202 case UMovePrimitive::Slide:
01203 // Remove projected speed
01204 newSpeed=_Speed - projSpeed0 * desc.ContactNormal1;
01205
01206 // Reflexion speed
01207 newSpeed+=( primitive.getAttenuation()*energySum / mass0 ) * desc.ContactNormal1;
01208 break;
01209 case UMovePrimitive::Reflexion:
01210 // Remove projected speed
01211 newSpeed=_Speed - projSpeed0 * desc.ContactNormal1;
01212
01213 // Reflexion speed
01214 newSpeed+=( primitive.getAttenuation()*energySum / mass0 ) * desc.ContactNormal1;
01215 break;
01216 case UMovePrimitive::Stop:
01217 newSpeed.set (0,0,0);
01218 break;
01219 case UMovePrimitive::DoNothing:
01220 newSpeed=_Speed;
01221 break;
01222 default: break;
01223 }
01224
01225 // Set new speed
01226 setSpeed (newSpeed, container, &primitive, worldImage);
01227
01228 // New position at t=0
01229 if (retriever)
01230 {
01231 // Make a domove in the Ben data
01232 double deltaDist= _DeltaPosition.norm();
01233 double deltaTime;
01234 if(deltaDist<0.000001)
01235 deltaTime= 0;
01236 else
01237 deltaTime=(collisionPosition-_Position.getPos ()).norm()/deltaDist;
01238 nlassert (deltaTime>=0);
01239 nlassert (deltaTime<=1);
01240
01241 UGlobalPosition newPosition = retriever->doMove (_Position.getGlobalPos (), _DeltaPosition,
01242 (float)deltaTime, surfaceTemp, true);
01243
01244 // Set the new position
01245 _Position.setGlobalPos (newPosition, *retriever);
01246
01247 // Position at t=0
01248 _3dInitPosition = _Position.getPos() - newSpeed * desc.ContactTime;
01249
01250 // New init time
01251 _InitTime = desc.ContactTime;
01252 }
01253 else
01254 {
01255 // No retriever used
01256 _Position.setPos (collisionPosition);
01257
01258 // Position at t=0
01259 _3dInitPosition = collisionPosition - newSpeed * desc.ContactTime;
01260
01261 // New init time
01262 _InitTime = desc.ContactTime;
01263 }
01264
01265 // Dirt pos
01266 dirtPos (container, &primitive, worldImage);
01267
01268 // ****** Second object
01269
01270 // Is second object in a static world ?
01271 if (!secondConst)
01272 {
01273 // Old position
01274 collisionPosition=second._3dInitPosition;
01275 collisionPosition+=second._Speed * desc.ContactTime;
01276
01277 // Obstacle ?
01278 switch (secondReaction)
01279 {
01280 case UMovePrimitive::Slide:
01281 // Remove projected speed
01282 newSpeed=second._Speed - projSpeed1 * desc.ContactNormal0;
01283
01284 // Reflexion speed
01285 newSpeed+=( otherPrimitive.getAttenuation()*energySum / mass1 ) * desc.ContactNormal1;
01286 break;
01287 case UMovePrimitive::Reflexion:
01288 // Remove projected speed
01289 newSpeed=second._Speed - projSpeed1 * desc.ContactNormal0;
01290
01291 // Reflexion speed
01292 newSpeed+=( otherPrimitive.getAttenuation()*energySum / mass1 ) * desc.ContactNormal0;
01293 break;
01294 case UMovePrimitive::Stop:
01295 newSpeed.set (0,0,0);
01296 break;
01297 case UMovePrimitive::DoNothing:
01298 newSpeed=second._Speed;
01299 break;
01300 default: break;
01301 }
01302
01303 // Set new speed
01304 second.setSpeed (newSpeed, container, &otherPrimitive, secondWorldImage);
01305
01306 // New position at t=0
01307 if (retriever)
01308 {
01309 // Make a domove in the Ben data
01310 double deltaDist= second._DeltaPosition.norm();
01311 double deltaTime;
01312 if(deltaDist==0)
01313 deltaTime= 0;
01314 else
01315 deltaTime=(collisionPosition-second._Position.getPos ()).norm()/deltaDist;
01316 clamp (deltaTime, 0.0, 1.0);
01317
01318 UGlobalPosition newPosition = retriever->doMove (second._Position.getGlobalPos (), second._DeltaPosition,
01319 (float)deltaTime, surfaceTemp, true);
01320
01321 // Set the new position
01322 second._Position.setGlobalPos (newPosition, *retriever);
01323
01324 // Position at t=0
01325 second._3dInitPosition = second._Position.getPos() - newSpeed * desc.ContactTime;
01326
01327 // New init time
01328 second._InitTime = desc.ContactTime;
01329 }
01330 else
01331 {
01332 // No retriever used
01333 second._Position.setPos (collisionPosition);
01334
01335 // Position at t=0
01336 second._3dInitPosition = collisionPosition - newSpeed * desc.ContactTime;
01337
01338 // New init time
01339 second._InitTime = desc.ContactTime;
01340 }
01341
01342 // Dirt pos
01343 second.dirtPos (container, &otherPrimitive, secondWorldImage);
01344 }
01345 }
01346 }
|
|
||||||||||||||||
|
Remove the nieme MoveElement.
Definition at line 1131 of file primitive_world_image.cpp. References _MoveElement, NLPACS::CMoveContainer::freeMoveElement(), nlassert, uint, uint8, and NLPACS::CMoveContainer::unlinkMoveElement(). Referenced by deleteIt().
01132 {
01133 // Check
01134 nlassert ((i>=0)||(i<4));
01135 nlassert (_MoveElement[i]!=NULL);
01136
01137 // Unlink the element
01138 container.unlinkMoveElement (_MoveElement[i], worldImage);
01139
01140 // Free the move element
01141 container.freeMoveElement (_MoveElement[i]);
01142
01143 // Set to NULL
01144 _MoveElement[i]=NULL;
01145 }
|
|
||||||||||||||||||||||||||||
|
Set the global position of the move primitive. Setting the global position can take a long time if you use a UGlobalRetriever. Set the position with this method only the first time or for teleporting.
Definition at line 1429 of file primitive_world_image.cpp. References _3dInitPosition, dirtPos(), NLPACS::CMoveContainer::getGlobalRetriever(), NLPACS::CPrimitiveWorldImage::CPosition::getPos(), nlassert, NLPACS::CGlobalRetriever::retrievePosition(), NLPACS::CPrimitiveWorldImage::CPosition::setGlobalPos(), NLPACS::CPrimitiveWorldImage::CPosition::setGlobalPosKeepZ(), NLPACS::CPrimitiveWorldImage::CPosition::setPos(), type, and uint8.
01430 {
01431 // Cast type
01432 nlassert (dynamic_cast<const CMoveContainer*>(&container));
01433 const CMoveContainer *cont=(const CMoveContainer*)&container;
01434
01435 // Get the retriever
01436 CGlobalRetriever *retriever=cont->getGlobalRetriever();
01437
01438 // Use a global retriever
01439 if (retriever)
01440 {
01441 // Get a cvector
01442 // CVector vect=pos; // better with CVectorD
01443
01444 // Get global position
01445 UGlobalPosition globalPosition=retriever->retrievePosition (pos, 1.0e10, type);
01446
01447 if (keepZ)
01448 {
01449 // Set the position
01450 _Position.setPos (pos);
01451
01452 // Set global position
01453 _Position.setGlobalPosKeepZ (globalPosition, *retriever);
01454 }
01455 else
01456 {
01457 // Set global position
01458 _Position.setGlobalPos (globalPosition, *retriever);
01459 }
01460 }
01461 else
01462 {
01463 // Set the position
01464 _Position.setPos (pos);
01465 }
01466
01467 // Precalc some values
01468 _3dInitPosition = _Position.getPos ();
01469 _InitTime = 0;
01470
01471 // Speed NULL
01472 _Speed=CVector::Null;
01473
01474 // Dirt BB
01475 dirtPos (&container, &primitive, worldImage);
01476 }
|
|
||||||||||||||||||||
|
Set the global position of the move primitive.
Definition at line 1404 of file primitive_world_image.cpp. References _3dInitPosition, dirtPos(), NLPACS::CMoveContainer::getGlobalRetriever(), NLPACS::CPrimitiveWorldImage::CPosition::getPos(), nlassert, NLPACS::CPrimitiveWorldImage::CPosition::setGlobalPos(), and uint8.
01405 {
01406 // Cast type
01407 nlassert (dynamic_cast<const CMoveContainer*>(&container));
01408 const CMoveContainer *cont=(const CMoveContainer*)&container;
01409
01410 // Use the global retriever ?
01411 nlassert (cont->getGlobalRetriever());
01412
01413 // Get the pos
01414 _Position.setGlobalPos (pos, *cont->getGlobalRetriever());
01415
01416 // Precalc some values
01417 _3dInitPosition = _Position.getPos ();
01418 _InitTime = 0;
01419
01420 // Speed NULL
01421 _Speed=CVector::Null;
01422
01423 // Dirt BB
01424 dirtPos (&container, &primitive, worldImage);
01425 }
|
|
|
Clear the inModifiedList flag.
Definition at line 138 of file primitive_world_image.h. References _DynamicFlags, and InModifiedListFlag. Referenced by NLPACS::CMoveContainer::changed().
00139 {
00140 if (itis)
00141 _DynamicFlags|=InModifiedListFlag;
00142 else
00143 _DynamicFlags&=~InModifiedListFlag;
00144 }
|
|
|
Clear the inModifiedList flag.
Definition at line 159 of file primitive_world_image.h. References _DynamicFlags, and InWorldImageFlag.
00160 {
00161 if (itis)
00162 _DynamicFlags|=InWorldImageFlag;
00163 else
00164 _DynamicFlags&=~InWorldImageFlag;
00165 }
|
|
||||||||||||||||||||
|
Set the new orientation of the move primitive. Only for the box primitives.
Definition at line 89 of file primitive_world_image.h. References _OBData, dirtPos(), and uint8.
|
|
||||||||||||||||||||
|
Set the speed vector for this primitive.
Definition at line 111 of file primitive_world_image.h. References dirtPos(), and uint8. Referenced by move(), and reaction().
|
|
||||||||||||||||
|
Update precalculated data.
Definition at line 231 of file primitive_world_image.h. References _DynamicFlags, DirtBBFlag, DirtPosFlag, precalcBB(), and precalcPos().
00232 {
00233 // Pos dirt ?
00234 if (_DynamicFlags&DirtPosFlag)
00235 {
00236 // Compute precalculated data
00237 precalcPos (primitive);
00238
00239 // Clean
00240 _DynamicFlags&=~DirtPosFlag;
00241 }
00242
00243 // Bounding box dirt ?
00244 if (_DynamicFlags&DirtBBFlag)
00245 {
00246 // Compute precalculated data
00247 precalcBB (beginTime, endTime, primitive);
00248
00249 // Clean
00250 _DynamicFlags&=~DirtBBFlag;
00251 }
00252 }
|
|
|
Definition at line 463 of file primitive_world_image.h. Referenced by evalCollisionOCoverOC(), evalCollisionPoverOC(), evalCollisionPoverS(), evalCollisionSoverOC(), move(), precalcBB(), precalcPos(), reaction(), and setGlobalPosition(). |
|
|
Definition at line 474 of file primitive_world_image.h. Referenced by addMoveElement(), CPrimitiveWorldImage(), getBBXMax(), and precalcBB(). |
|
|
Definition at line 472 of file primitive_world_image.h. Referenced by addMoveElement(), checkSortedList(), CPrimitiveWorldImage(), getBBXMin(), and precalcBB(). |
|
|
Definition at line 475 of file primitive_world_image.h. Referenced by CPrimitiveWorldImage(), getBBYMax(), and precalcBB(). |
|
|
Definition at line 473 of file primitive_world_image.h. Referenced by CPrimitiveWorldImage(), getBBYMin(), and precalcBB(). |
|
|
Definition at line 466 of file primitive_world_image.h. Referenced by doMove(), evalCollision(), getDeltaPosition(), precalcBB(), and reaction(). |
|
|
Definition at line 404 of file primitive_world_image.h. Referenced by copy(), CPrimitiveWorldImage(), dirtBB(), dirtPos(), isInModifiedListFlag(), isInWorldImageFlag(), setInModifiedListFlag(), setInWorldImageFlag(), and update(). |
|
|
Definition at line 460 of file primitive_world_image.h. Referenced by reaction(). |
|
|
Definition at line 500 of file primitive_world_image.h. Referenced by addMoveElement(), checkSortedList(), copy(), CPrimitiveWorldImage(), deleteIt(), getMoveElement(), and removeMoveElement(). |
|
|
Definition at line 497 of file primitive_world_image.h. Referenced by getNextModified(), and linkInModifiedList(). |
|
|
Referenced by evalCollision(), evalCollisionPoverOC(), evalCollisionPoverS(), evalCollisionSoverOC(), getOrientation(), precalcBB(), precalcPos(), and setOrientation(). |
|
|
Definition at line 457 of file primitive_world_image.h. Referenced by reaction(). |
|
|
Definition at line 469 of file primitive_world_image.h. Referenced by evalCollisionOCoverOC(), evalCollisionPoverOC(), evalCollisionPoverS(), evalCollisionSoverOC(), and reaction(). |
|
|
Definition at line 488 of file primitive_world_image.h. |
|
|
Definition at line 489 of file primitive_world_image.h. |
|
|
Definition at line 492 of file primitive_world_image.h. |
|
|
Definition at line 484 of file primitive_world_image.h. |
|
|
Definition at line 485 of file primitive_world_image.h. |
1.3.6