Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
collider.h
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 00022 #include "csextern.h" 00023 00024 #include "csgeom/box.h" 00025 #include "csutil/csobject.h" 00026 #include "csutil/leakguard.h" 00027 #include "csutil/array.h" 00028 00029 #include "ivaria/collider.h" 00030 00031 struct iCamera; 00032 struct iCollider; 00033 struct iCollideSystem; 00034 struct iEngine; 00035 struct iMeshWrapper; 00036 struct iMovable; 00037 struct iObject; 00038 struct iPolygonMesh; 00039 struct iRegion; 00040 struct iSector; 00041 00042 class csCollisionPair; 00043 class csReversibleTransform; 00044 00045 struct csIntersectingTriangle; 00046 00047 /* The 'class csColliderWrapper' is here to work around a VC7.0 issue. It 00048 * seems that, depending on whether VC7.0 sees a compound declared as 00049 * 'struct' or 'class' first, it sometimes generated different decorated 00050 * symbol names. 'csColliderWrapper' is a class, so commonly, in headers 00051 * etc. it would be forward-declared as 'class csColliderWrapper'. However, 00052 * the SCF_VERSION causes a forward declaration as a 'struct', with the 00053 * consequence that when csColliderWrapper was not already forward-declared 00054 * all decorated name will refer to 'struct csColliderWrapper' in some files. 00055 * But possibly, when forward-declaration was used, 'class csColliderWrapper' 00056 * will be used in other objects, causing linking errors. This is worked 00057 * around by having a 'class' forward declaration here. 00058 */ 00059 class csColliderWrapper; 00060 SCF_VERSION (csColliderWrapper, 0, 0, 3); 00061 00075 class CS_CRYSTALSPACE_EXPORT csColliderWrapper : public csObject 00076 { 00077 private: 00078 csRef<iCollideSystem> collide_system; 00079 csRef<iCollider> collider; 00080 00081 public: 00082 CS_LEAKGUARD_DECLARE (csColliderWrapper); 00083 00085 csColliderWrapper (csObject& parent, iCollideSystem* collide_system, 00086 iPolygonMesh* mesh); 00087 00089 csColliderWrapper (iObject* parent, iCollideSystem* collide_system, 00090 iPolygonMesh* mesh); 00091 00097 csColliderWrapper (iObject* parent, iCollideSystem* collide_system, 00098 iCollider* collider); 00099 00101 virtual ~csColliderWrapper (); 00102 00104 iCollider* GetCollider () { return collider; } 00105 00107 iCollideSystem* GetCollideSystem () { return collide_system; } 00108 00116 bool Collide (csColliderWrapper& pOtherCollider, 00117 csReversibleTransform* pThisTransform = 0, 00118 csReversibleTransform* pOtherTransform = 0); 00123 bool Collide (csObject& otherObject, 00124 csReversibleTransform* pThisTransform = 0, 00125 csReversibleTransform* pOtherTransform = 0); 00130 bool Collide (iObject* otherObject, 00131 csReversibleTransform* pThisTransform = 0, 00132 csReversibleTransform* pOtherTransform = 0); 00133 00138 static csColliderWrapper* GetColliderWrapper (csObject& object); 00139 00144 static csColliderWrapper* GetColliderWrapper (iObject* object); 00145 00146 SCF_DECLARE_IBASE_EXT (csObject); 00147 }; 00148 00152 struct CS_CRYSTALSPACE_EXPORT csTraceBeamResult 00153 { 00155 00159 csIntersectingTriangle closest_tri; 00164 csVector3 closest_isect; 00168 iMeshWrapper* closest_mesh; 00173 float sqdistance; 00174 }; 00175 00180 class CS_CRYSTALSPACE_EXPORT csColliderHelper 00181 { 00182 public: 00194 static csColliderWrapper* InitializeCollisionWrapper (iCollideSystem* colsys, 00195 iMeshWrapper* mesh); 00196 00202 static void InitializeCollisionWrappers (iCollideSystem* colsys, 00203 iEngine* engine, iRegion* region = 0); 00204 00222 static bool CollideArray ( 00223 iCollideSystem* colsys, 00224 iCollider* collider, 00225 const csReversibleTransform* trans, 00226 int num_colliders, 00227 iCollider** colliders, 00228 csReversibleTransform **transforms); 00229 00267 static int CollidePath ( 00268 iCollideSystem* colsys, 00269 iCollider* collider, const csReversibleTransform* trans, 00270 float nbrsteps, 00271 csVector3& newpos, 00272 int num_colliders, 00273 iCollider** colliders, 00274 csReversibleTransform** transforms); 00275 00297 static float TraceBeam (iCollideSystem* cdsys, iSector* sector, 00298 const csVector3& start, const csVector3& end, 00299 bool traverse_portals, 00300 csIntersectingTriangle& closest_tri, 00301 csVector3& closest_isect, 00302 iMeshWrapper** closest_mesh = 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 00344 // For rotation. 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 00380 int CollisionDetect ( 00381 iCollider *collider, 00382 iSector* sector, 00383 csReversibleTransform* transform, 00384 csReversibleTransform* old_transform); 00385 00407 int CollisionDetectIterative ( 00408 iCollider *collider, 00409 iSector* sector, 00410 csReversibleTransform* transform, 00411 csReversibleTransform* old_transform, csVector3& maxmove); 00412 bool MoveV (float delta, const csVector3& velBody); 00413 bool RotateV (float delta, const csVector3& angularVelocity); 00414 void InitializeColliders (const csVector3& legs, 00415 const csVector3& body, const csVector3& shift); 00416 00417 public: 00419 csColliderActor (); 00420 00422 void SetCollideSystem (iCollideSystem* cdsys) 00423 { 00424 csColliderActor::cdsys = cdsys; 00425 } 00426 00428 void SetEngine (iEngine* engine) 00429 { 00430 csColliderActor::engine = engine; 00431 } 00432 00442 void InitializeColliders (iMeshWrapper* mesh, const csVector3& legs, 00443 const csVector3& body, const csVector3& shift); 00444 00456 void InitializeColliders (iCamera* camera, const csVector3& legs, 00457 const csVector3& body, const csVector3& shift); 00458 00462 void SetGravity (float g) 00463 { 00464 gravity = g; 00465 velWorld.y = 0; 00466 } 00467 00471 float GetGravity () const { return gravity; } 00472 00476 bool IsOnGround () const { return onground; } 00477 00481 void SetOnGround (bool og) { onground = og; } 00482 00486 bool HasCD () const { return cd; } 00487 00491 void SetCD (bool c) { cd = c; } 00492 00496 bool CheckRevertMove () const { return revertMove; } 00497 00509 bool Move (float delta, float speed, const csVector3& velBody, 00510 const csVector3& angularVelocity); 00511 00516 const csVector3& GetRotation () { return rotation; } 00517 00522 void SetRotation (const csVector3& rot); 00523 00529 bool AdjustForCollisions (const csVector3& oldpos, 00530 csVector3& newpos, 00531 const csVector3& vel, 00532 float delta); 00533 }; 00534 00535 #endif // __CS_COLLIDER_H__
Generated for Crystal Space by doxygen 1.4.4