# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

collision_ot.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
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         // The next cell
00110         CCollisionOT    *_Next;
00111 
00112         // The previous cell
00113         CCollisionOT    *_Previous;
00114 
00115 protected:
00116         // Is a CCollisionOTInfo
00117         bool                    _Info;
00118 };
00119 
00127 class CCollisionOTInfo : public CCollisionOT
00128 {
00129 public:
00130         CCollisionOTInfo ()
00131         {
00132                 _Info=true;
00133         }
00134 
00135         // Link in the primitive
00136         virtual void primitiveLink (CMovePrimitive *primitive, CCollisionOTInfo *other) =0;
00137 
00138         // Link in the primitive
00139         virtual CCollisionOTInfo        *getNext (CMovePrimitive *primitive) const =0;
00140 
00141         // Return false for dynamic collision, true for static collision
00142         virtual bool                            isCollisionAgainstStatic () const=0;
00143 
00144         // Return collision time
00145         virtual double                          getCollisionTime () const=0;
00146 
00147         // Remove the collision from the primitives
00148         virtual void                            removeFromPrimitives ()=0;
00149 
00150         // Get second primitive
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         // Get the first primitive in the collision
00170         CMovePrimitive          *getFirstPrimitive () const
00171         {
00172                 return _FirstPrimitive;
00173         }
00174 
00175         // Get the second primitive in the collision
00176         CMovePrimitive          *getSecondPrimitive () const
00177         {
00178                 return _SecondPrimitive;
00179         }
00180 
00181         // Get the collision descriptor
00182         const CCollisionDesc    &getCollisionDesc () const
00183         {
00184                 return _Desc;
00185         }
00186 
00187         // Is a collision
00188         bool                            isCollision() const
00189         {
00190                 return _Collision;
00191         }
00192 
00193         // Is enter
00194         bool                            isEnter() const
00195         {
00196                 return _Enter;
00197         }
00198 
00199         // Is exit
00200         bool                            isExit() const
00201         {
00202                 return _Exit;
00203         }
00204 
00205         // Is second primitive is static ?
00206         bool                            isSecondStatic () const
00207         {
00208                 return _SecondStatic;
00209         }
00210 
00211         // Get the world image
00212         uint8 getFirstWorldImage () const
00213         {
00214                 return _FirstWorldImage;
00215         }
00216 
00217         // Get the world image
00218         uint8 getSecondWorldImage () const
00219         {
00220                 return _SecondWorldImage;
00221         }
00222 
00223         // Init the info
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         // Link in the primitive
00239         void                            primitiveLink (CMovePrimitive *primitive, CCollisionOTInfo *other)
00240         {
00241                 // First primitive ?
00242                 if (primitive==_FirstPrimitive)
00243                 {
00244                         // Check
00245                         nlassert  (primitive!=_SecondPrimitive);
00246 
00247                         // Link
00248                         _FirstNext=other;
00249                 }
00250                 else // second
00251                 {
00252                         // Check
00253                         nlassert  (primitive==_SecondPrimitive);
00254 
00255                         // Link
00256                         _SecondNext=other;
00257                 }
00258         }
00259 
00260         // Link in the primitive
00261         CCollisionOTInfo        *getNext (CMovePrimitive *primitive) const
00262         {
00263                 // First primitive ?
00264                 if (primitive==_FirstPrimitive)
00265                 {
00266                         // Check
00267                         nlassert  (primitive!=_SecondPrimitive);
00268 
00269                         // return next
00270                         return _FirstNext;
00271                 }
00272                 else // second
00273                 {
00274                         // Check
00275                         nlassert  (primitive==_SecondPrimitive);
00276 
00277                         // Link
00278                         return _SecondNext;
00279                 }
00280         }
00281 
00282         // Return false for dynamic collision, true for static collision
00283         bool                            isCollisionAgainstStatic () const
00284         {
00285                 return false;
00286         }
00287 
00288         // Return collision time
00289         double                          getCollisionTime () const
00290         {
00291                 return _Desc.ContactTime;
00292         }
00293 
00294         // Remove the collision from the primitives
00295         void                            removeFromPrimitives ();
00296 
00297         // Get second primitive
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         // The first primitive
00312         CMovePrimitive          *_FirstPrimitive;
00313 
00314         // The second primitive
00315         CMovePrimitive          *_SecondPrimitive;
00316 
00317         // Descriptor
00318         CCollisionDesc          _Desc;
00319 
00320         // Collision or only trigger ?
00321         bool                            _Collision;
00322         bool                            _Enter;
00323         bool                            _Exit;
00324         bool                            _SecondStatic;
00325 
00326         // World images
00327         uint8 _FirstWorldImage;
00328         uint8 _SecondWorldImage;
00329 
00330         // First primitive linked list
00331         CCollisionOTInfo        *_FirstNext;
00332 
00333         // Second primitive linked list
00334         CCollisionOTInfo        *_SecondNext;
00335 };
00336 
00344 class CCollisionOTStaticInfo : public CCollisionOTInfo
00345 {
00346 public:
00347         CCollisionOTStaticInfo ()
00348         {
00349                 _Info=true;
00350         }
00351 
00352         // Get the first primitive in the collision
00353         CMovePrimitive          *getPrimitive () const
00354         {
00355                 return _Primitive;
00356         }
00357 
00358         // Get the collision descriptor
00359         const CCollisionSurfaceDesc     &getCollisionDesc () const
00360         {
00361                 return _StaticDesc;
00362         }
00363 
00364         // Get the collision descriptor
00365         const UGlobalPosition &getGlobalPosition () const
00366         {
00367                 return _GlobalPosition;
00368         }
00369 
00370         // Get delta time
00371         double getDeltaTime () const
00372         {
00373                 return _DeltaTime;
00374         }
00375 
00376         // Get the world image
00377         uint8 getWorldImage () const
00378         {
00379                 return _WorldImage;
00380         }
00381 
00382         // Init the info
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         // Link in the primitive
00394         void                            primitiveLink (CMovePrimitive *primitive, CCollisionOTInfo *other)
00395         {
00396                 // Link
00397                 _Next=other;
00398         }
00399 
00400         // Link in the primitive
00401         CCollisionOTInfo        *getNext (CMovePrimitive *primitive) const
00402         {
00403                 // return next
00404                 return _Next;
00405         }
00406 
00407         // Return false for dynamic collision, true for static collision
00408         bool                            isCollisionAgainstStatic () const
00409         {
00410                 return true;
00411         }
00412 
00413         // Return collision time
00414         double                          getCollisionTime () const
00415         {
00416                 return _StaticDesc.ContactTime;
00417         }
00418 
00419         // Remove the collision from the primitives
00420         void                            removeFromPrimitives ();
00421 
00422         CMovePrimitive          *getOtherPrimitive (CMovePrimitive *primitive) const
00423         {
00424                 return NULL;
00425         }
00426 private:
00427         // The first primitive
00428         CMovePrimitive          *_Primitive;
00429 
00430         // The static descriptor
00431         CCollisionSurfaceDesc   _StaticDesc;
00432 
00433         // The next global position
00434         UGlobalPosition _GlobalPosition;
00435 
00436         // Delta time for this collid
00437         double                          _DeltaTime;
00438 
00439         // World image
00440         uint8                           _WorldImage;
00441 
00442         // Next primitive in the linked list
00443         CCollisionOTInfo        *_Next;
00444 };
00445 
00446 // ***************************************************************************
00447 
00448 inline CCollisionOTInfo *CCollisionOT::getNextInfo () const
00449 {
00450         // Get next
00451         CCollisionOT *next=_Next;
00452 
00453         // Is an info ?
00454         while ( next && (!next->isInfo ()) )
00455                 next=next->getNextInfo ();
00456 
00457         // Return an info
00458         return (CCollisionOTInfo*)next;
00459 }
00460 
00461 
00462 
00463 } // NLPACS
00464 
00465 
00466 #endif // NL_COLLISION_OT_H
00467 
00468 /* End of collision_ot.h */