move_primitive.cpp File Reference


Detailed Description

Description of movables primitives

Id
move_primitive.cpp,v 1.19 2003/10/10 10:08:48 corvazier Exp

Definition in file move_primitive.cpp.

#include "stdpacs.h"
#include "pacs/move_primitive.h"
#include "pacs/collision_desc.h"
#include "pacs/move_element.h"
#include "nel/misc/hierarchical_timer.h"

Go to the source code of this file.

Defines

#define NLPACS_HAUTO_GET_GLOBAL_POSITION   H_AUTO_USE ( NLPACS_Get_Global_Position )
#define NLPACS_HAUTO_MOVE   H_AUTO_USE ( NLPACS_Move )
#define NLPACS_HAUTO_SET_GLOBAL_POSITION   H_AUTO_USE ( NLPACS_Set_Global_Position )
#define NLPACS_HAUTO_SET_UGLOBAL_POSITION   H_AUTO_USE ( NLPACS_Set_UGlobal_Position )

Functions

 H_AUTO_DECL (NLPACS_Get_Global_Position) H_AUTO_DECL(NLPACS_Set_Global_Position) H_AUTO_DECL(NLPACS_Set_UGlobal_Position) H_AUTO_DECL(NLPACS_Move) namespace NLPACS


Define Documentation

#define NLPACS_HAUTO_GET_GLOBAL_POSITION   H_AUTO_USE ( NLPACS_Get_Global_Position )
 

Referenced by H_AUTO_DECL().

#define NLPACS_HAUTO_MOVE   H_AUTO_USE ( NLPACS_Move )
 

Referenced by H_AUTO_DECL().

#define NLPACS_HAUTO_SET_GLOBAL_POSITION   H_AUTO_USE ( NLPACS_Set_Global_Position )
 

Referenced by H_AUTO_DECL().

#define NLPACS_HAUTO_SET_UGLOBAL_POSITION   H_AUTO_USE ( NLPACS_Set_UGlobal_Position )
 

Referenced by H_AUTO_DECL().


Function Documentation

H_AUTO_DECL NLPACS_Get_Global_Position   ) 
 

Definition at line 35 of file move_primitive.cpp.

References depth, nlassert, NLPACS_HAUTO_GET_GLOBAL_POSITION, NLPACS_HAUTO_MOVE, NLPACS_HAUTO_SET_GLOBAL_POSITION, NLPACS_HAUTO_SET_UGLOBAL_POSITION, type, uint, uint8, and width.

00045 {
00046 
00047 // ***************************************************************************
00048 
00049 CMovePrimitive::CMovePrimitive (CMoveContainer* container, uint8 firstWorldImage, uint8 numWorldImage)
00050 {
00051         _FirstWorldImage=firstWorldImage;
00052         _NumWorldImage=numWorldImage;
00053 
00054         _CollisionMask=0xffffffff;
00055         _OcclusionMask=0xffffffff;
00056         _Attenuation=1;
00057         _Container=container;
00058         _StaticFlags=0;
00059         _RootOTInfo=NULL;
00060         _LastTestTime=0xffffffff;
00061 
00062         // Ptr table alloc
00063         _WorldImages=_Container->allocateWorldImagesPtrs (numWorldImage);
00064 
00065         // Alloc world images
00066         for (uint j=0; j<numWorldImage; j++)
00067                 _WorldImages[j]=_Container->allocateWorldImage ();
00068 }
00069 
00070 // ***************************************************************************
00071 
00072 CMovePrimitive::~CMovePrimitive ()
00073 {
00074         // Alloc world images
00075         for (uint j=0; j<(uint)_NumWorldImage; j++)
00076         {
00077                 _WorldImages[j]->deleteIt (*_Container, (uint8)(_FirstWorldImage+j));
00078                 _Container->freeWorldImage (_WorldImages[j]);
00079         }
00080 
00081         // Ptr table alloc
00082         _Container->freeWorldImagesPtrs (_WorldImages);
00083 }
00084 
00085 // ***************************************************************************
00086 
00087 void CMovePrimitive::removeCollisionOTInfo (CCollisionOTInfo *toRemove)
00088 {
00089         // Should be ok
00090         CCollisionOTInfo        *previousElement=NULL;
00091         CCollisionOTInfo        *element=_RootOTInfo;
00092         nlassert (element);
00093 
00094         // Look for it
00095         while (element)
00096         {
00097                 // Good one ?
00098                 if (element==toRemove)
00099                 {
00100                         // If previous element, just link
00101                         if (previousElement)
00102                                 previousElement->primitiveLink (this, element->getNext (this));
00103                         else
00104                                 _RootOTInfo=element->getNext (this);
00105 
00106                         // End
00107                         break;
00108                 }
00109                 
00110                 // Look for next
00111                 previousElement=element;
00112                 element=element->getNext (this);
00113         }
00114 
00115         // Should be found
00116         nlassert (element);
00117 }
00118 
00119 // ***************************************************************************
00120 
00121 void CMovePrimitive::removeCollisionOTInfo ()
00122 {
00123         // For each element in the list
00124         CCollisionOTInfo        *element=_RootOTInfo;
00125         while (element)
00126         {
00127                 // Unlink from ot
00128                 element->unlink ();
00129 
00130                 // Remove collision ot info from other primitive
00131                 CMovePrimitive *other=element->getOtherPrimitive (this);
00132                 if (other)
00133                 {
00134                         // Remove it in the other element
00135                         other->removeCollisionOTInfo (element);
00136                 }
00137 
00138                 // Next element
00139                 element=element->getNext (this);
00140         }
00141 
00142         // Relink element because we keep it
00143         _RootOTInfo=NULL;
00144 }
00145 
00146 // ***************************************************************************
00147 
00148 void CMovePrimitive::checkSortedList ()
00149 {
00150         // Check sorted list for ecah world image
00151         for (uint i=0; i<(uint)_NumWorldImage; i++)
00152                 _WorldImages[i]->checkSortedList (i+_FirstWorldImage);
00153 }
00154 
00155 // ***************************************************************************
00156 
00157 bool CMovePrimitive::isTriggered (CMovePrimitive& second, bool enter, bool exit)
00158 {
00159         // Generate a trigger ?
00160 
00161         // Is the two are not triggers ?
00162         if ( ( (_StaticFlags&TriggerMask) == NotATrigger ) && ( (second._StaticFlags&TriggerMask) == NotATrigger ) )
00163                 return false;
00164 
00165         // Is one of them is an enter trigger ?
00166         if ( enter && ( (_StaticFlags&EnterTrigger) || (second._StaticFlags&EnterTrigger) ) )
00167                 return true;
00168 
00169         // Is one of them is an exit trigger ?
00170         if ( exit && ( (_StaticFlags&ExitTrigger) || (second._StaticFlags&ExitTrigger) ) )
00171                 return true;
00172 
00173         // Is one of them is a trigger ?
00174         if ( (_StaticFlags&OverlapTrigger) || (second._StaticFlags&OverlapTrigger) )
00175                 return true;
00176 
00177         return false;
00178 }
00179 
00180 // ***************************************************************************
00181 
00182 void CMovePrimitive::insertInWorldImage (uint8 worldImage)
00183 {
00184         // Check it is a collisionable primitive
00185         nlassert (!isNonCollisionable());
00186 
00187         // Check ad get the primitive world image
00188         CPrimitiveWorldImage *wI=getWorldImage (worldImage);
00189 
00190         // Set as inserted
00191         wI->setInWorldImageFlag (true);
00192 
00193         // Flag to update this wI
00194         _Container->changed (this, worldImage);
00195 }
00196 
00197 // ***************************************************************************
00198 
00199 void CMovePrimitive::removeFromWorldImage (uint8 worldImage)
00200 {
00201         // Check it is a collisionable primitive
00202         nlassert (!isNonCollisionable());
00203 
00204         // Check ad get the primitive world image
00205         CPrimitiveWorldImage *wI=getWorldImage (worldImage);
00206 
00207         // Remove from cells
00208         wI->deleteIt (*_Container, worldImage);
00209 
00210         // Set as non inserted
00211         wI->setInWorldImageFlag (false);
00212 }
00213 
00214 // ***************************************************************************
00215 
00216 void CMovePrimitive::setAbsorbtion (float attenuation)
00217 {
00218         _Attenuation=attenuation;
00219 }
00220 
00221 // ***************************************************************************
00222 
00223 void CMovePrimitive::setOrientation (double rot, uint8 worldImage)
00224 {
00225         if (isNonCollisionable())
00226                 getWorldImage (0)->setOrientation (rot, _Container, this, worldImage);
00227         else
00228                 getWorldImage (worldImage)->setOrientation (rot, _Container, this, worldImage);
00229 }
00230 
00231 // ***************************************************************************
00232 
00233 void CMovePrimitive::setGlobalPosition (const UGlobalPosition& pos, uint8 worldImage)
00234 {
00235         NLPACS_HAUTO_SET_GLOBAL_POSITION
00236 
00237         if (isNonCollisionable())
00238                 getWorldImage (0)->setGlobalPosition (pos, *_Container, *this, worldImage);
00239         else
00240                 getWorldImage (worldImage)->setGlobalPosition (pos, *_Container, *this, worldImage);
00241 }
00242 
00243 // ***************************************************************************
00244 
00245 void CMovePrimitive::setGlobalPosition (const NLMISC::CVectorD& pos, uint8 worldImage, UGlobalPosition::TType type)
00246 {
00247         NLPACS_HAUTO_SET_UGLOBAL_POSITION
00248 
00249         if (isNonCollisionable())
00250                 getWorldImage (0)->setGlobalPosition (pos, *_Container, *this, worldImage, (_StaticFlags & DontSnapToGroundFlag) != 0);
00251         else
00252                 getWorldImage (worldImage)->setGlobalPosition (pos, *_Container, *this, worldImage, (_StaticFlags & DontSnapToGroundFlag) != 0);
00253 }
00254 
00255 // ***************************************************************************
00256 
00257 void CMovePrimitive::move (const NLMISC::CVectorD& speed, uint8 worldImage)
00258 {
00259         NLPACS_HAUTO_MOVE
00260 
00261         if (isNonCollisionable())
00262                 getWorldImage (0)->move (speed, *_Container, *this, worldImage);
00263         else
00264                 getWorldImage (worldImage)->move (speed, *_Container, *this, worldImage);
00265 }
00266 
00267 // ***************************************************************************
00268 
00269 NLMISC::CVectorD CMovePrimitive::getFinalPosition (uint8 worldImage)  const
00270 {
00271         if (isNonCollisionable())
00272                 return getWorldImage (0)->getFinalPosition ();
00273         else
00274                 return getWorldImage (worldImage)->getFinalPosition ();
00275 }
00276 
00277 // ***************************************************************************
00278 
00279 const NLMISC::CVectorD& CMovePrimitive::getSpeed (uint8 worldImage) const
00280 {
00281         if (isNonCollisionable())
00282                 return getWorldImage (0)->getSpeed ();
00283         else
00284                 return getWorldImage (worldImage)->getSpeed ();
00285 }
00286 
00287 // ***************************************************************************
00288 
00289 CMovePrimitive::TType CMovePrimitive::getPrimitiveType () const
00290 {
00291         return getPrimitiveTypeInternal ();
00292 }
00293 
00294 // ***************************************************************************
00295 
00296 CMovePrimitive::TReaction CMovePrimitive::getReactionType () const
00297 {
00298         return getReactionTypeInternal ();
00299 }
00300 
00301 // ***************************************************************************
00302 
00303 CMovePrimitive::TTrigger CMovePrimitive::getTriggerType () const
00304 {
00305         return getTriggerTypeInternal ();
00306 }
00307 
00308 // ***************************************************************************
00309 
00310 CMovePrimitive::TCollisionMask CMovePrimitive::getCollisionMask () const
00311 {
00312         return getCollisionMaskInternal ();
00313 }
00314 
00315 // ***************************************************************************
00316 
00317 CMovePrimitive::TCollisionMask CMovePrimitive::getOcclusionMask () const
00318 {
00319         return getOcclusionMaskInternal ();
00320 }
00321 
00322 // ***************************************************************************
00323 
00324 bool CMovePrimitive::getObstacle () const
00325 {
00326         return isObstacle ();
00327 }
00328 
00329 // ***************************************************************************
00330 
00331 float CMovePrimitive::getAbsorbtion () const
00332 {
00333         return _Attenuation;
00334 }
00335 
00336 // ***************************************************************************
00337 
00338 void CMovePrimitive::getSize (float& width, float& depth) const
00339 {
00340         width=getLength(0);
00341         depth=getLength(1);
00342 }
00343 
00344 // ***************************************************************************
00345 
00346 float CMovePrimitive::getHeight () const
00347 {
00348         return getHeightInternal ();
00349 }
00350 
00351 // ***************************************************************************
00352 
00353 float CMovePrimitive::getRadius () const
00354 {
00355         return getRadiusInternal ();
00356 }
00357 
00358 // ***************************************************************************
00359 
00360 double CMovePrimitive::getOrientation (uint8 worldImage) const
00361 {
00362         if (isNonCollisionable())
00363                 return getWorldImage (0)->getOrientation ();
00364         else
00365                 return getWorldImage (worldImage)->getOrientation ();
00366 }
00367 
00368 // ***************************************************************************
00369 
00370 void CMovePrimitive::getGlobalPosition (UGlobalPosition& pos, uint8 worldImage) const
00371 {
00372         NLPACS_HAUTO_GET_GLOBAL_POSITION
00373 
00374         if (isNonCollisionable())
00375                 pos=getWorldImage (0)->getGlobalPosition();
00376         else
00377                 pos=getWorldImage (worldImage)->getGlobalPosition();
00378 }
00379 
00380 // ***************************************************************************
00381 
00382 uint8 CMovePrimitive::getFirstWorldImageV () const
00383 {
00384         return getFirstWorldImage ();
00385 }
00386 
00387 // ***************************************************************************
00388 
00389 uint8 CMovePrimitive::getNumWorldImageV () const
00390 {
00391         return getNumWorldImageV ();
00392 }
00393 
00394 // ***************************************************************************
00395 
00396 bool CMovePrimitive::isInCollision (CMovePrimitive *primitive)
00397 {
00398         // Should be ok
00399         CCollisionOTInfo        *element=_RootOTInfo;
00400         
00401         // Look for it
00402         while (element)
00403         {
00404                 // Dynamic collision ?
00405                 if (!element->isCollisionAgainstStatic())
00406                 {
00407                         // Cast
00408                         const CCollisionOTDynamicInfo *dynInfo=static_cast<const CCollisionOTDynamicInfo*> (element);
00409                         
00410                         // Check if the primitive is used
00411                         if ((dynInfo->getFirstPrimitive()== primitive)||(dynInfo->getSecondPrimitive()== primitive))
00412                                 return true;
00413                 }
00414                 
00415                 // Look for next
00416                 element=element->getNext (this);
00417         }
00418         
00419         return false;
00420 }
00421 
00422 } // NLPACS


Generated on Tue Mar 16 06:43:09 2004 for NeL by doxygen 1.3.6