00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_COLLISION_OT_H
00027 #define NL_COLLISION_OT_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "pacs/collision_desc.h"
00031 #include "pacs/global_retriever.h"
00032
00033
00034 namespace NLPACS
00035 {
00036
00037 class CMovePrimitive;
00038 class CCollisionOTInfo;
00039
00047 class CCollisionOT
00048 {
00049 public:
00050 CCollisionOT ()
00051 {
00052 _Info=false;
00053 clear ();
00054 }
00055
00057 void clear ()
00058 {
00059 _Next=NULL;
00060 _Previous=NULL;
00061 }
00062
00064 void link (CCollisionOT* newElement)
00065 {
00066 if (newElement)
00067 {
00068 newElement->_Previous=this;
00069 newElement->_Next=_Next;
00070 }
00071 if (_Next)
00072 _Next->_Previous=newElement;
00073 _Next=newElement;
00074 }
00075
00077 void unlink ()
00078 {
00079 if (_Previous)
00080 _Previous->_Next=_Next;
00081 if (_Next)
00082 _Next->_Previous=_Previous;
00083 _Next=NULL;
00084 _Previous=NULL;
00085 }
00086
00088 bool isInfo () const
00089 {
00090 return _Info;
00091 }
00092
00094 CCollisionOT *getPrevious () const
00095 {
00096 return _Previous;
00097 }
00098
00100 CCollisionOT *getNext () const
00101 {
00102 return _Next;
00103 }
00104
00106 CCollisionOTInfo *getNextInfo () const;
00107
00108 private:
00109
00110 CCollisionOT *_Next;
00111
00112
00113 CCollisionOT *_Previous;
00114
00115 protected:
00116
00117 bool _Info;
00118 };
00119
00127 class CCollisionOTInfo : public CCollisionOT
00128 {
00129 public:
00130 CCollisionOTInfo ()
00131 {
00132 _Info=true;
00133 }
00134
00135
00136 virtual void primitiveLink (CMovePrimitive *primitive, CCollisionOTInfo *other) =0;
00137
00138
00139 virtual CCollisionOTInfo *getNext (CMovePrimitive *primitive) const =0;
00140
00141
00142 virtual bool isCollisionAgainstStatic () const=0;
00143
00144
00145 virtual double getCollisionTime () const=0;
00146
00147
00148 virtual void removeFromPrimitives ()=0;
00149
00150
00151 virtual CMovePrimitive *getOtherPrimitive (CMovePrimitive *primitive) const=0;
00152 };
00153
00161 class CCollisionOTDynamicInfo : public CCollisionOTInfo
00162 {
00163 public:
00164 CCollisionOTDynamicInfo ()
00165 {
00166 _Info=true;
00167 }
00168
00169
00170 CMovePrimitive *getFirstPrimitive () const
00171 {
00172 return _FirstPrimitive;
00173 }
00174
00175
00176 CMovePrimitive *getSecondPrimitive () const
00177 {
00178 return _SecondPrimitive;
00179 }
00180
00181
00182 const CCollisionDesc &getCollisionDesc () const
00183 {
00184 return _Desc;
00185 }
00186
00187
00188 bool isCollision() const
00189 {
00190 return _Collision;
00191 }
00192
00193
00194 bool isEnter() const
00195 {
00196 return _Enter;
00197 }
00198
00199
00200 bool isExit() const
00201 {
00202 return _Exit;
00203 }
00204
00205
00206 bool isSecondStatic () const
00207 {
00208 return _SecondStatic;
00209 }
00210
00211
00212 uint8 getFirstWorldImage () const
00213 {
00214 return _FirstWorldImage;
00215 }
00216
00217
00218 uint8 getSecondWorldImage () const
00219 {
00220 return _SecondWorldImage;
00221 }
00222
00223
00224 void init (CMovePrimitive *firstPrimitive, CMovePrimitive *secondPrimitive, const CCollisionDesc& desc, bool collision,
00225 bool enter, bool exit, uint8 firstWorldImage, uint8 secondWorldImage, bool secondStatic)
00226 {
00227 _FirstPrimitive=firstPrimitive;
00228 _SecondPrimitive=secondPrimitive;
00229 _Desc=desc;
00230 _Collision=collision;
00231 _Enter=enter;
00232 _Exit=exit;
00233 _FirstWorldImage=firstWorldImage;
00234 _SecondWorldImage=secondWorldImage;
00235 _SecondStatic=secondStatic;
00236 }
00237
00238
00239 void primitiveLink (CMovePrimitive *primitive, CCollisionOTInfo *other)
00240 {
00241
00242 if (primitive==_FirstPrimitive)
00243 {
00244
00245 nlassert (primitive!=_SecondPrimitive);
00246
00247
00248 _FirstNext=other;
00249 }
00250 else
00251 {
00252
00253 nlassert (primitive==_SecondPrimitive);
00254
00255
00256 _SecondNext=other;
00257 }
00258 }
00259
00260
00261 CCollisionOTInfo *getNext (CMovePrimitive *primitive) const
00262 {
00263
00264 if (primitive==_FirstPrimitive)
00265 {
00266
00267 nlassert (primitive!=_SecondPrimitive);
00268
00269
00270 return _FirstNext;
00271 }
00272 else
00273 {
00274
00275 nlassert (primitive==_SecondPrimitive);
00276
00277
00278 return _SecondNext;
00279 }
00280 }
00281
00282
00283 bool isCollisionAgainstStatic () const
00284 {
00285 return false;
00286 }
00287
00288
00289 double getCollisionTime () const
00290 {
00291 return _Desc.ContactTime;
00292 }
00293
00294
00295 void removeFromPrimitives ();
00296
00297
00298 CMovePrimitive *getOtherPrimitive (CMovePrimitive *primitive) const
00299 {
00300 if (_FirstPrimitive==primitive)
00301 return _SecondPrimitive;
00302 else
00303 {
00304 nlassert (_SecondPrimitive==primitive);
00305 return _FirstPrimitive;
00306 }
00307 }
00308
00309 private:
00310
00311
00312 CMovePrimitive *_FirstPrimitive;
00313
00314
00315 CMovePrimitive *_SecondPrimitive;
00316
00317
00318 CCollisionDesc _Desc;
00319
00320
00321 bool _Collision;
00322 bool _Enter;
00323 bool _Exit;
00324 bool _SecondStatic;
00325
00326
00327 uint8 _FirstWorldImage;
00328 uint8 _SecondWorldImage;
00329
00330
00331 CCollisionOTInfo *_FirstNext;
00332
00333
00334 CCollisionOTInfo *_SecondNext;
00335 };
00336
00344 class CCollisionOTStaticInfo : public CCollisionOTInfo
00345 {
00346 public:
00347 CCollisionOTStaticInfo ()
00348 {
00349 _Info=true;
00350 }
00351
00352
00353 CMovePrimitive *getPrimitive () const
00354 {
00355 return _Primitive;
00356 }
00357
00358
00359 const CCollisionSurfaceDesc &getCollisionDesc () const
00360 {
00361 return _StaticDesc;
00362 }
00363
00364
00365 const UGlobalPosition &getGlobalPosition () const
00366 {
00367 return _GlobalPosition;
00368 }
00369
00370
00371 double getDeltaTime () const
00372 {
00373 return _DeltaTime;
00374 }
00375
00376
00377 uint8 getWorldImage () const
00378 {
00379 return _WorldImage;
00380 }
00381
00382
00383 void init (CMovePrimitive *primitive, const CCollisionSurfaceDesc& desc,
00384 const UGlobalPosition& nextGlobalPosition, double delta, uint8 worldImage)
00385 {
00386 _Primitive=primitive;
00387 _StaticDesc=desc;
00388 _GlobalPosition=nextGlobalPosition;
00389 _DeltaTime=delta;
00390 _WorldImage=worldImage;
00391 }
00392
00393
00394 void primitiveLink (CMovePrimitive *primitive, CCollisionOTInfo *other)
00395 {
00396
00397 _Next=other;
00398 }
00399
00400
00401 CCollisionOTInfo *getNext (CMovePrimitive *primitive) const
00402 {
00403
00404 return _Next;
00405 }
00406
00407
00408 bool isCollisionAgainstStatic () const
00409 {
00410 return true;
00411 }
00412
00413
00414 double getCollisionTime () const
00415 {
00416 return _StaticDesc.ContactTime;
00417 }
00418
00419
00420 void removeFromPrimitives ();
00421
00422 CMovePrimitive *getOtherPrimitive (CMovePrimitive *primitive) const
00423 {
00424 return NULL;
00425 }
00426 private:
00427
00428 CMovePrimitive *_Primitive;
00429
00430
00431 CCollisionSurfaceDesc _StaticDesc;
00432
00433
00434 UGlobalPosition _GlobalPosition;
00435
00436
00437 double _DeltaTime;
00438
00439
00440 uint8 _WorldImage;
00441
00442
00443 CCollisionOTInfo *_Next;
00444 };
00445
00446
00447
00448 inline CCollisionOTInfo *CCollisionOT::getNextInfo () const
00449 {
00450
00451 CCollisionOT *next=_Next;
00452
00453
00454 while ( next && (!next->isInfo ()) )
00455 next=next->getNextInfo ();
00456
00457
00458 return (CCollisionOTInfo*)next;
00459 }
00460
00461
00462
00463 }
00464
00465
00466 #endif // NL_COLLISION_OT_H
00467
00468