## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# cstool/collider.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 1998-2003 by Jorrit Tyberghein
    00003     Written by Alex Pfaffe.
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public
    00016     License along with this library; if not, write to the Free
    00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00018 */
    00019 #ifndef __CS_COLLIDER_H__
    00020 #define __CS_COLLIDER_H__
    00021
    00026 #include "csextern.h"
    00027
    00028 #include "csgeom/box.h"
    00029 #include "csutil/csobject.h"
    00030 #include "csutil/leakguard.h"
    00031 #include "csutil/array.h"
    00032 #include "csutil/scf_implementation.h"
    00033
    00034 #include "ivaria/collider.h"
    00035
    00036 struct iCamera;
    00037 struct iCollider;
    00038 struct iCollideSystem;
    00039 struct iEngine;
    00040 struct iMeshWrapper;
    00041 struct iMovable;
    00042 struct iObject;
    00043 struct iPolygonMesh;
    00044 struct iRegion;
    00045 struct iSector;
    00046
    00047 struct csCollisionPair;
    00048 class csReversibleTransform;
    00049
    00050 struct csIntersectingTriangle;
    00051
    00052
    00066 class CS_CRYSTALSPACE_EXPORT csColliderWrapper :
    00067   public scfImplementationExt1<csColliderWrapper,
    00068                                csObject,
    00069                                scfFakeInterface<csColliderWrapper> >
    00070 {
    00071 private:
    00072   csRef<iCollideSystem> collide_system;
    00073   csRef<iCollider> collider;
    00074
    00075 public:
    00076   SCF_INTERFACE(csColliderWrapper, 2,0,0);
    00077
    00078   CS_LEAKGUARD_DECLARE (csColliderWrapper);
    00079
    00081   csColliderWrapper (csObject& parent, iCollideSystem* collide_system,
    00082         iPolygonMesh* mesh);
    00083
    00085   csColliderWrapper (iObject* parent, iCollideSystem* collide_system,
    00086         iPolygonMesh* mesh);
    00087
    00093   csColliderWrapper (iObject* parent, iCollideSystem* collide_system,
    00094         iCollider* collider);
    00095
    00097   virtual ~csColliderWrapper ();
    00098
    00100   iCollider* GetCollider () { return collider; }
    00101
    00103   iCollideSystem* GetCollideSystem () { return collide_system; }
    00104
    00112   bool Collide (csColliderWrapper& pOtherCollider,
    00113                 csReversibleTransform* pThisTransform = 0,
    00114                 csReversibleTransform* pOtherTransform = 0);
    00119   bool Collide (csObject& otherObject,
    00120                 csReversibleTransform* pThisTransform = 0,
    00121                 csReversibleTransform* pOtherTransform = 0);
    00126   bool Collide (iObject* otherObject,
    00127                 csReversibleTransform* pThisTransform = 0,
    00128                 csReversibleTransform* pOtherTransform = 0);
    00129
    00134   static csColliderWrapper* GetColliderWrapper (csObject& object);
    00135
    00140   static csColliderWrapper* GetColliderWrapper (iObject* object);
    00141 };
    00142
    00146 struct CS_CRYSTALSPACE_EXPORT csTraceBeamResult
    00147 {
    00149
    00153   csIntersectingTriangle closest_tri;
    00158   csVector3 closest_isect;
    00162   iMeshWrapper* closest_mesh;
    00167   float sqdistance;
    00171   iSector* end_sector;
    00172 };
    00173
    00178 class CS_CRYSTALSPACE_EXPORT csColliderHelper
    00179 {
    00180 public:
    00192   static csColliderWrapper* InitializeCollisionWrapper (iCollideSystem* colsys,
    00193         iMeshWrapper* mesh);
    00194
    00200   static void InitializeCollisionWrappers (iCollideSystem* colsys,
    00201         iEngine* engine, iRegion* region = 0);
    00202
    00220   static bool CollideArray (
    00221         iCollideSystem* colsys,
    00222         iCollider* collider,
    00223         const csReversibleTransform* trans,
    00224         int num_colliders,
    00225         iCollider** colliders,
    00226         csReversibleTransform **transforms);
    00227
    00264   static int CollidePath (
    00265         iCollideSystem* colsys,
    00266         iCollider* collider, const csReversibleTransform* trans,
    00267         float nbrsteps,
    00268         csVector3& newpos,
    00269         int num_colliders,
    00270         iCollider** colliders,
    00271         csReversibleTransform** transforms);
    00272
    00296   static float TraceBeam (iCollideSystem* cdsys, iSector* sector,
    00297         const csVector3& start, const csVector3& end,
    00298         bool traverse_portals,
    00299         csIntersectingTriangle& closest_tri,
    00300         csVector3& closest_isect,
    00301         iMeshWrapper** closest_mesh = 0,
    00302         iSector** end_sector = 0);
    00303
    00320   static csTraceBeamResult TraceBeam (iCollideSystem* cdsys, iSector* sector,
    00321         const csVector3& start, const csVector3& end,
    00322         bool traverse_portals);
    00323 };
    00324
    00329 class CS_CRYSTALSPACE_EXPORT csColliderActor
    00330 {
    00331 private:
    00332   bool revertMove;
    00333   bool onground;
    00334   bool cd;
    00335   csArray<csCollisionPair> our_cd_contact;
    00336   float gravity;
    00337   iMeshWrapper* mesh;
    00338   iCamera* camera;
    00339   iMovable* movable;
    00340   iCollideSystem* cdsys;
    00341   iEngine* engine;
    00342   csVector3 velWorld;
    00343
    00345   csVector3 rotation;
    00346
    00347   csRef<iCollider> topCollider;
    00348   csRef<iCollider> bottomCollider;
    00349   csBox3 boundingBox;
    00350   csVector3 shift;
    00351   csVector3 topSize;
    00352   csVector3 bottomSize;
    00353   csVector3 intervalSize;
    00354
    00355   int revertCount;
    00356
    00371   int CollisionDetect (
    00372         iCollider *collider,
    00373         iSector* sector,
    00374         csReversibleTransform* transform,
    00375         csReversibleTransform* old_transform);
    00376
    00386   int CollisionDetectIterative (
    00387         iCollider *collider,
    00388         iSector* sector,
    00389         csReversibleTransform* transform,
    00390         csReversibleTransform* old_transform, csVector3& maxmove);
    00391   bool MoveV (float delta, const csVector3& velBody);
    00392   bool RotateV (float delta, const csVector3& angularVelocity);
    00393   void InitializeColliders (const csVector3& legs,
    00394         const csVector3& body, const csVector3& shift);
    00395
    00396 public:
    00398   csColliderActor ();
    00399
    00401   void SetCollideSystem (iCollideSystem* cdsys)
    00402   {
    00403     csColliderActor::cdsys = cdsys;
    00404   }
    00405
    00407   void SetEngine (iEngine* engine)
    00408   {
    00409     csColliderActor::engine = engine;
    00410   }
    00411
    00421   void InitializeColliders (iMeshWrapper* mesh, const csVector3& legs,
    00422         const csVector3& body, const csVector3& shift);
    00423
    00435   void InitializeColliders (iCamera* camera, const csVector3& legs,
    00436         const csVector3& body, const csVector3& shift);
    00437
    00444   void SetCamera (iCamera* camera, bool adjustRotation = true);
    00445
    00449   void SetGravity (float g)
    00450   {
    00451     gravity = g;
    00452     velWorld.y = 0;
    00453   }
    00454
    00458   float GetGravity () const { return gravity; }
    00459
    00463   bool IsOnGround () const { return onground; }
    00464
    00468   void SetOnGround (bool og) { onground = og; }
    00469
    00473   bool HasCD () const { return cd; }
    00474
    00478   void SetCD (bool c) { cd = c; }
    00479
    00483   bool CheckRevertMove () const { return revertMove; }
    00484
    00496   bool Move (float delta, float speed, const csVector3& velBody,
    00497         const csVector3& angularVelocity);
    00498
    00503   const csVector3& GetRotation () { return rotation; }
    00504
    00509   void SetRotation (const csVector3& rot);
    00510
    00516   bool AdjustForCollisions (const csVector3& oldpos,
    00517         csVector3& newpos,
    00518         const csVector3& vel,
    00519         float delta);
    00520 };
    00521
    00522 #endif // __CS_COLLIDER_H__