00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_PRIMITIVE_WORLD_IMAGE_H
00027 #define NL_PRIMITIVE_WORLD_IMAGE_H
00028
00029 #include "nel/misc/types_nl.h"
00030
00031 #include "pacs/move_container.h"
00032
00033
00034 namespace NLPACS {
00035
00036
00043 class CPrimitiveWorldImage
00044 {
00045 public:
00046
00047
00048 CPrimitiveWorldImage ();
00049
00050
00051 void deleteIt (CMoveContainer &container, uint8 worldImage);
00052
00053
00054 void copy (const CPrimitiveWorldImage& source);
00055
00061 void setGlobalPosition (const UGlobalPosition& pos, CMoveContainer& container, CMovePrimitive &primitive, uint8 worldImage);
00062
00070 void setGlobalPosition (const NLMISC::CVectorD& pos, CMoveContainer& container, CMovePrimitive &primitive,
00071 uint8 worldImage, bool keepZ = false);
00072
00078 NLMISC::CVectorD getFinalPosition () const
00079 {
00080
00081 return _Position.getPos();
00082 }
00083
00089 void setOrientation (double rot, CMoveContainer *container, CMovePrimitive *primitive, uint8 worldImage)
00090 {
00091
00092 _OBData.Orientation=rot;
00093
00094
00095 dirtPos (container, primitive, worldImage);
00096 }
00097
00103 void move (const NLMISC::CVectorD& speed, CMoveContainer& container, CMovePrimitive &primitive,
00104 uint8 worldImage);
00105
00111 void setSpeed (const NLMISC::CVectorD& speed, CMoveContainer *container, CMovePrimitive *primitive, uint8 worldImage)
00112 {
00113
00114 _Speed=speed;
00115
00116
00117 dirtPos (container, primitive, worldImage);
00118 }
00119
00125 const NLMISC::CVectorD& getSpeed () const
00126 {
00127
00128 return _Speed;
00129 }
00130
00132 bool isInModifiedListFlag ()
00133 {
00134 return (_DynamicFlags&InModifiedListFlag) != 0;
00135 }
00136
00138 void setInModifiedListFlag (bool itis)
00139 {
00140 if (itis)
00141 _DynamicFlags|=InModifiedListFlag;
00142 else
00143 _DynamicFlags&=~InModifiedListFlag;
00144 }
00145
00146
00147 void linkInModifiedList (CMovePrimitive* next)
00148 {
00149 _NextModified=next;
00150 }
00151
00153 bool isInWorldImageFlag ()
00154 {
00155 return (_DynamicFlags&InWorldImageFlag) != 0;
00156 }
00157
00159 void setInWorldImageFlag (bool itis)
00160 {
00161 if (itis)
00162 _DynamicFlags|=InWorldImageFlag;
00163 else
00164 _DynamicFlags&=~InWorldImageFlag;
00165 }
00166
00168 CMovePrimitive *getNextModified () const
00169 {
00170 return _NextModified;
00171 }
00172
00176 double getBBXMin () const
00177 {
00178 return _BBXMin;
00179 }
00180
00184 double getBBYMin () const
00185 {
00186 return _BBYMin;
00187 }
00188
00192 double getBBXMax () const
00193 {
00194 return _BBXMax;
00195 }
00196
00200 double getBBYMax () const
00201 {
00202 return _BBYMax;
00203 }
00204
00208 const NLMISC::CVectorD& getDeltaPosition () const
00209 {
00210 return _DeltaPosition;
00211 }
00212
00214 CMoveElement *getMoveElement (uint i)
00215 {
00216 return _MoveElement[i];
00217 }
00218
00220 void removeMoveElement (uint i, CMoveContainer &container, uint8 worldImage);
00221
00223 void addMoveElement (CMoveCell& cell, uint16 x, uint16 y, double centerX, double centerY, CMovePrimitive *primitive,
00224 CMoveContainer &container, uint8 worldImage);
00225
00227 void CPrimitiveWorldImage::addMoveElementendOfList (CMoveCell& cell, uint16 x, uint16 y, CMovePrimitive *primitive,
00228 CMoveContainer &container);
00229
00231 void update (double beginTime, double endTime, CMovePrimitive &primitive)
00232 {
00233
00234 if (_DynamicFlags&DirtPosFlag)
00235 {
00236
00237 precalcPos (primitive);
00238
00239
00240 _DynamicFlags&=~DirtPosFlag;
00241 }
00242
00243
00244 if (_DynamicFlags&DirtBBFlag)
00245 {
00246
00247 precalcBB (beginTime, endTime, primitive);
00248
00249
00250 _DynamicFlags&=~DirtBBFlag;
00251 }
00252 }
00253
00255 void checkSortedList (uint8 worldImage);
00256
00257
00258 const UGlobalPosition& getGlobalPosition()
00259 {
00260 return _Position.getGlobalPos();
00261 }
00262
00263
00264 double getOrientation () const
00265 {
00266 return _OBData.Orientation;
00267 }
00268
00269
00270 void dirtPos (CMoveContainer *container, CMovePrimitive *primitive, uint8 worldImage)
00271 {
00272 _DynamicFlags|=DirtPosFlag;
00273 dirtBB (container, primitive, worldImage);
00274 }
00275
00276
00277 void dirtBB (CMoveContainer *container, CMovePrimitive *primitive, uint8 worldImage)
00278 {
00279
00280 container->changed (primitive, worldImage);
00281
00282 _DynamicFlags|=DirtBBFlag;
00283 }
00284
00285
00286 double getInitTime() const
00287 {
00288 return _InitTime;
00289 }
00290
00291
00292 void precalcPos (CMovePrimitive &primitive);
00293
00294
00295 void precalcSpeed ();
00296
00297
00298 void precalcBB (double beginTime, double endTime, CMovePrimitive &primitive);
00299
00300
00301
00302
00303
00304
00305
00306
00307
00319 bool evalCollision (CPrimitiveWorldImage& other, class CCollisionDesc& desc, double timeMin,
00320 double timeMax, uint32 testTime, uint32 maxTestIteration,
00321 double &firstContactTime, double &lastContactTime,
00322 CMovePrimitive& primitive, CMovePrimitive& otherPrimitive);
00323
00324
00325 bool evalCollisionOBoverOB (CPrimitiveWorldImage& other, CCollisionDesc& desc, double timeMin,
00326 double timeMax, double &firstContactTime, double &lastContactTime,
00327 CMovePrimitive& primitive, CMovePrimitive& otherPrimitive);
00328
00329
00330 bool evalCollisionOBoverOC (CPrimitiveWorldImage& other, CCollisionDesc& desc, double timeMin,
00331 double timeMax, double &firstContactTime, double &lastContactTime,
00332 CMovePrimitive& primitive, CMovePrimitive& otherPrimitive);
00333
00334
00335 bool evalCollisionOCoverOC (CPrimitiveWorldImage& other, CCollisionDesc& desc, double timeMin,
00336 double timeMax, double &firstContactTime, double &lastContactTime,
00337 CMovePrimitive& primitive, CMovePrimitive& otherPrimitive);
00338
00339
00340
00341
00342 bool evalCollisionPoverS (CPrimitiveWorldImage& other, CCollisionDesc& desc, uint numPoint, uint numSeg,
00343 CMovePrimitive& primitive, CMovePrimitive& otherPrimitive);
00344
00345
00346 bool evalCollisionPoverOC (CPrimitiveWorldImage& other, CCollisionDesc& desc, uint numPoint,
00347 double &firstContactTime, double &lastContactTime, CMovePrimitive& primitive,
00348 CMovePrimitive& otherPrimitive);
00349
00350
00351 bool evalCollisionSoverOC (CPrimitiveWorldImage& other, CCollisionDesc& desc, uint numPoint,
00352 CMovePrimitive& primitive, CMovePrimitive& otherPrimitive);
00353
00363 const TCollisionSurfaceDescVector *evalCollision (CGlobalRetriever &retriever, CCollisionSurfaceTemp& surfaceTemp,
00364 uint32 testTime, uint32 maxTestIteration, CMovePrimitive& primitive);
00365
00366
00367 void doMove (CGlobalRetriever &retriever, CCollisionSurfaceTemp& surfaceTemp, double originalMax, double finalMax, bool keepZ = false);
00368
00369
00370 void doMove (double timeMax);
00371
00372
00373 void reaction (CPrimitiveWorldImage& second, const CCollisionDesc& desc, CGlobalRetriever* retriver,
00374 CCollisionSurfaceTemp& surfaceTemp, bool collision, CMovePrimitive &primitive,
00375 CMovePrimitive &otherPrimitive, CMoveContainer *container, uint8 worldImage,
00376 uint8 secondWorldImage, bool secondConst);
00377
00378
00379 void reaction ( const CCollisionSurfaceDesc& surfaceDesc, const UGlobalPosition& globalPosition,
00380 CGlobalRetriever& retriever, double ratio, double dt, CMovePrimitive &primitive, CMoveContainer &container,
00381 uint8 worldImage);
00382
00383 private:
00384
00385 enum TDynamicFlags
00386 {
00387
00388 DirtPosFlag =0x0001,
00389
00390
00391 DirtBBFlag =0x0002,
00392
00393
00394 InModifiedListFlag =0x0004,
00395
00396
00397 InWorldImageFlag =0x0008,
00398
00399
00400 ForceSize =0xffff
00401 };
00402
00403
00404 uint16 _DynamicFlags;
00405
00406
00407 class CPosition
00408 {
00409 private:
00410
00411 NLMISC::CVectorD _3dPosition;
00412
00413
00414 UGlobalPosition _GlobalPosition;
00415 public:
00416
00417 const NLMISC::CVectorD& getPos () const
00418 {
00419 return _3dPosition;
00420 }
00421
00422
00423 void setPos (const NLMISC::CVectorD& newPos)
00424 {
00425 _3dPosition=newPos;
00426 }
00427
00428
00429 const UGlobalPosition& getGlobalPos () const
00430 {
00431 return _GlobalPosition;
00432 }
00433
00434
00435 void setGlobalPos (const UGlobalPosition& globalPosition,
00436 CGlobalRetriever& globalRetriver)
00437 {
00438
00439 _GlobalPosition=globalPosition;
00440 _GlobalPosition.LocalPosition.Estimation.z = globalRetriver.getMeanHeight(globalPosition);
00441 _3dPosition=globalRetriver.getDoubleGlobalPosition (_GlobalPosition);
00442
00443 }
00444
00445 void setGlobalPosKeepZ(const UGlobalPosition& globalPosition,
00446 CGlobalRetriever& globalRetriver)
00447 {
00448 _GlobalPosition.setKeepZ(globalPosition);
00449 NLMISC::CVectorD dPos = globalRetriver.getDoubleGlobalPosition (globalPosition);
00450 _3dPosition.x = dPos.x;
00451 _3dPosition.y = dPos.y;
00452 }
00453
00454 };
00455
00456
00457 CPosition _Position;
00458
00459
00460 double _InitTime;
00461
00462
00463 NLMISC::CVectorD _3dInitPosition;
00464
00465
00466 NLMISC::CVectorD _DeltaPosition;
00467
00468
00469 NLMISC::CVectorD _Speed;
00470
00471
00472 double _BBXMin;
00473 double _BBYMin;
00474 double _BBXMax;
00475 double _BBYMax;
00476
00477
00478 union
00479 {
00480
00481 struct
00482 {
00483
00484 double PointPosX[4];
00485 double PointPosY[4];
00486
00487
00488 double EdgeDirectionX[4];
00489 double EdgeDirectionY[4];
00490
00491
00492 double Orientation;
00493 } _OBData;
00494 };
00495
00496
00497 CMovePrimitive *_NextModified;
00498
00499
00500 CMoveElement *_MoveElement[4];
00501 };
00502
00503
00504 }
00505
00506
00507 #endif // NL_PRIMITIVE_WORLD_IMAGE_H
00508
00509