00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_MOVE_PRIMITIVE_H
00027 #define NL_MOVE_PRIMITIVE_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/vector.h"
00031
00032 #include "nel/pacs/u_move_primitive.h"
00033
00034 #include "pacs/move_container.h"
00035 #include "pacs/primitive_world_image.h"
00036 #include "pacs/global_retriever.h"
00037
00038 #define NELPACS_DIST_BACK 0.01
00039
00040 namespace NLPACS
00041 {
00042
00052 class CMovePrimitive: public UMovePrimitive
00053 {
00054 private:
00055 friend class CMoveContainer;
00056
00057
00058 enum TStaticFlags
00059 {
00060
00061 PrimitiveMask =0x000f,
00062
00063
00064 ReactionMask =0x00f0,
00065
00066
00067 TriggerMask =0x0f00,
00068
00069
00070 ObstacleFlag =0x1000,
00071
00072
00073 NonCollisionableFlag =0x2000,
00074
00076 DontSnapToGroundFlag = 0x4000,
00077
00078
00079 ForceSize =0xffff
00080 };
00081
00082 public:
00083
00085 CMovePrimitive (CMoveContainer* container, uint8 firstWorldImage, uint8 numWorldImage);
00086
00088 virtual ~CMovePrimitive ();
00089
00090 virtual void setDontSnapToGround(bool dont)
00091 {
00092 if (dont) _StaticFlags |= DontSnapToGroundFlag;
00093 else _StaticFlags &= ~DontSnapToGroundFlag;
00094 }
00095
00096 bool getDontSnapToGround() const
00097 {
00098 return (_StaticFlags & DontSnapToGroundFlag) != 0;
00099 }
00100
00101 bool isNonCollisionable () const
00102 {
00103 return (_StaticFlags&NonCollisionableFlag)!=0;
00104 }
00105
00106
00107 void setNonCollisionable (bool nonCollisionable)
00108 {
00109 if (nonCollisionable)
00110 _StaticFlags|=NonCollisionableFlag;
00111 else
00112 _StaticFlags&=~NonCollisionableFlag;
00113 }
00114
00115
00116 CPrimitiveWorldImage *getWorldImage (uint i) const
00117 {
00118
00119 nlassert ((i>=(uint)_FirstWorldImage)&&(i<(uint)_FirstWorldImage+(uint)_NumWorldImage));
00120
00121
00122 return _WorldImages[i-_FirstWorldImage];
00123 }
00124
00125
00126 bool isInserted (uint i) const
00127 {
00128
00129 if ((i>=(uint)_FirstWorldImage)&&(i<(uint)_FirstWorldImage+(uint)_NumWorldImage))
00130 {
00131
00132 return getWorldImage (i)->isInWorldImageFlag ();
00133 }
00134 else
00135 return false;
00136 }
00137
00138 virtual uint8 getFirstWorldImageV () const;
00139 virtual uint8 getNumWorldImageV () const;
00140
00141
00142 uint8 getFirstWorldImage () const
00143 {
00144 return _FirstWorldImage;
00145 }
00146
00147
00148 uint8 getNumWorldImage () const
00149 {
00150 return _NumWorldImage;
00151 }
00152
00153
00154 void dirtAllPos ()
00155 {
00156 for (uint i=0; i<_NumWorldImage; i++)
00157 {
00158
00159 CPrimitiveWorldImage *worldImage=_WorldImages[i];
00160
00161
00162 worldImage->dirtPos (_Container, this, i+_FirstWorldImage);
00163 }
00164 }
00165
00171 void setPrimitiveType (TType type)
00172 {
00173
00174 _StaticFlags&=~(uint32)PrimitiveMask;
00175 _StaticFlags|=type;
00176 }
00177
00183 void setReactionType (TReaction type)
00184 {
00185
00186 _StaticFlags&=~(uint32)ReactionMask;
00187 _StaticFlags|=type;
00188 }
00189
00195 void setTriggerType (TTrigger type)
00196 {
00197
00198 _StaticFlags&=~(uint32)TriggerMask;
00199 _StaticFlags|=type;
00200 }
00201
00207 void setCollisionMask (TCollisionMask mask)
00208 {
00209 _CollisionMask=mask;
00210 }
00211
00217 void setOcclusionMask (TCollisionMask mask)
00218 {
00219 _OcclusionMask=mask;
00220 }
00221
00227 void setObstacle (bool obstacle)
00228 {
00229
00230 if (obstacle)
00231 _StaticFlags|=ObstacleFlag;
00232 else
00233 _StaticFlags&=~(uint32)ObstacleFlag;
00234 }
00235
00242 void setSize (float width, float depth)
00243 {
00244
00245 nlassert ((((uint32)_StaticFlags)&PrimitiveMask)==_2DOrientedBox);
00246
00247
00248 _Length[0]=width;
00249 _Length[1]=depth;
00250 }
00251
00257 void setHeight (float height)
00258 {
00259
00260 _Height=height;
00261 }
00262
00268 void setRadius (float radius)
00269 {
00270
00271 nlassert ((((uint32)_StaticFlags)&PrimitiveMask)==_2DOrientedCylinder);
00272
00273
00274 _Length[0]=radius;
00275 }
00276
00278 TType getPrimitiveTypeInternal () const
00279 {
00280
00281 return (TType)(_StaticFlags&(uint32)PrimitiveMask);
00282 }
00283
00285 TReaction getReactionTypeInternal () const
00286 {
00287
00288 return (TReaction)(_StaticFlags&(uint32)ReactionMask);
00289 }
00290
00292 TTrigger getTriggerTypeInternal () const
00293 {
00294
00295 return (TTrigger)(_StaticFlags&(uint32)TriggerMask);
00296 }
00297
00299 TCollisionMask getCollisionMaskInternal () const
00300 {
00301
00302 return _CollisionMask;
00303 }
00304
00306 TCollisionMask getOcclusionMaskInternal () const
00307 {
00308
00309 return _OcclusionMask;
00310 }
00311
00313 float getAttenuation() const
00314 {
00315 return _Attenuation;
00316 }
00317
00319 float getLength (uint where) const
00320 {
00321 return _Length[where];
00322 }
00323
00325 float getHeightInternal () const
00326 {
00327 return _Height;
00328 }
00329
00331 float getRadiusInternal () const
00332 {
00333 return _Length[0];
00334 }
00335
00337 bool isObstacle () const
00338 {
00339 return (_StaticFlags&ObstacleFlag)!=0;
00340 }
00341
00343 bool isCollisionable() const
00344 {
00345 return !isNonCollisionable();
00346 }
00347
00349 void addCollisionOTInfo (CCollisionOTInfo *info)
00350 {
00351
00352 info->primitiveLink (this, _RootOTInfo);
00353 _RootOTInfo=info;
00354 }
00355
00357 void removeCollisionOTInfo (CCollisionOTInfo *toRemove);
00358
00360 void removeCollisionOTInfo ();
00361
00363 void checkSortedList ();
00364
00366 bool isTriggered (CMovePrimitive& second, bool enter, bool exit);
00367
00369
00370 void setAbsorbtion (float attenuation);
00371 void setOrientation (double rot, uint8 worldImage);
00372 void setGlobalPosition (const NLMISC::CVectorD& pos, uint8 worldImage);
00373 void setGlobalPosition (const UGlobalPosition& pos, uint8 worldImage);
00374 void move (const NLMISC::CVectorD& speed, uint8 worldImage);
00375 NLMISC::CVectorD getFinalPosition (uint8 worldImage) const;
00376 const NLMISC::CVectorD& getSpeed (uint8 worldImage) const;
00377 void insertInWorldImage (uint8 worldImage);
00378 void removeFromWorldImage (uint8 worldImage);
00379 TType getPrimitiveType () const;
00380 TReaction getReactionType () const;
00381 TTrigger getTriggerType () const;
00382 TCollisionMask getCollisionMask () const;
00383 TCollisionMask getOcclusionMask () const;
00384 bool getObstacle () const;
00385 float getAbsorbtion () const;
00386 void getSize (float& width, float& depth) const;
00387 float getHeight () const;
00388 float getRadius () const;
00389 double getOrientation (uint8 worldImage) const;
00390 void getGlobalPosition (UGlobalPosition& pos, uint8 worldImage) const;
00391
00392
00393 bool checkTestTime (uint32 testTime, uint32 maxTestIteration)
00394 {
00395
00396 if (testTime!=_LastTestTime)
00397 {
00398
00399 _LastTestTime=testTime;
00400
00401
00402 _IterationCount=maxTestIteration;
00403 }
00404 else
00405 {
00406
00407 if (_IterationCount<=0)
00408 {
00409
00410 return false;
00411 }
00412 else
00413 _IterationCount--;
00414 }
00415
00416 return true;
00417 }
00418
00419
00420
00421 float getMass () const
00422 {
00423
00424 if ( (_StaticFlags&PrimitiveMask) == _2DOrientedBox )
00425 return _Length[0]*_Length[1]*_Height;
00426
00427 else
00428 {
00429 nlassert ( (_StaticFlags&PrimitiveMask) == _2DOrientedCylinder );
00430 return _Length[0]*(float)NLMISC::Pi*_Height;
00431 }
00432 }
00433
00434
00435
00436 private:
00437
00438
00439 float _Length[2];
00440
00441
00442 float _Height;
00443
00444
00445 float _Attenuation;
00446
00447
00448 uint16 _StaticFlags;
00449
00450
00451 uint8 _NumWorldImage;
00452
00453
00454 uint8 _FirstWorldImage;
00455
00456
00457 TCollisionMask _OcclusionMask;
00458
00459
00460 TCollisionMask _CollisionMask;
00461
00462
00463 CMoveContainer *_Container;
00464
00465
00466 CCollisionOTInfo *_RootOTInfo;
00467
00468
00469 CPrimitiveWorldImage **_WorldImages;
00470
00471
00472 uint32 _LastTestTime;
00473
00474
00475 sint32 _IterationCount;
00476 };
00477
00478 }
00479
00480 #include "pacs/move_container_inline.h"
00481
00482 #endif // NL_MOVE_PRIMITIVE_H
00483
00484