00001 /* 00002 SagaEngine library 00003 Copyright (c) 2002-2006 Skalden Studio AS 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to distribute the library under the terms of the 00010 Q Public License version 1.0. Be sure to read and understand the license 00011 before using the library. It should be included here, or you may read it 00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl 00013 00014 The original version of this library can be located at: 00015 http://www.sagaengine.com/ 00016 00017 Rune Myrland 00018 rune@skalden.com 00019 */ 00020 00021 00022 #ifndef engine_physics_CollisionComponent_hpp 00023 #define engine_physics_CollisionComponent_hpp 00024 00025 #include "sim_react.hpp" 00026 #include "ThingCollide.hpp" 00027 #include "comp/Component.hpp" 00028 #include "comp/Composite.hpp" 00029 #include "comp/node/AreaChildComponent.hpp" 00030 #include "../physics/Move.hpp" 00031 #include "../area/sim_area.hpp" 00032 #include "../custom/sim_custom.hpp" 00033 #include "../stat/sim_stat.hpp" 00034 #include "../thing/sim_thing.hpp" 00035 #include "../pos/PosComponent.hpp" 00036 #include "ContactInfo.hpp" 00037 00038 namespace se_core { 00039 class _SeCoreExport CollisionComponent : public AreaChildComponent { 00040 public: 00041 typedef ComponentPtr<CollisionComponent, sct_COLLISION> Ptr; 00042 00045 CollisionComponent(Composite* owner, const ComponentFactory* factory); 00046 ~CollisionComponent(); 00047 00048 int tag() const; 00049 int substance() const { 00050 return substance_; 00051 } 00052 void setSubstance(int s) { 00053 substance_ = s; 00054 } 00055 void setDoObstructView(bool f) { 00056 doObstructView_ = f; 00057 } 00058 bool shouldIgnore(const CollisionComponent& cc) const; 00059 void resetIgnore() { 00060 ignore_ = 0; 00061 } 00062 void setIgnore(const CollisionComponent& cc) { 00063 ignore_ = &cc; 00064 } 00065 00066 00069 bool isCollideable() const { 00070 return isCollideable_ && !owner()->isDead(); 00071 } 00072 00078 void setCollideable(bool isCollideable); 00079 00080 00081 PosComponent& posComponent() { 00082 return *posComponent_; 00083 } 00084 00085 const PosComponent& posComponent() const { 00086 return *posComponent_; 00087 } 00088 00089 void setCollide(const ThingCollide* collide) { 00090 collide_ = collide; 00091 } 00092 00093 00094 inline bool pushThing(ContactInfo& pusher, ContactInfo& target) { 00095 if(!collide_) 00096 return false; 00097 00098 return collide_->collide(pusher, target); 00099 } 00100 00101 00102 bool isPusher() const { 00103 return collide_ != 0; 00104 } 00105 00106 bool didGeometryCollide(const CollisionComponent& other) const; 00107 bool doesGeometryCollide(const CollisionComponent& other) const; 00108 scale_t whenDoesGeometryCollide(const CollisionComponent& other) const; 00109 00110 void zoneChanged(int zoneType, Composite* newArea, Composite* oldArea); 00111 00112 const BoundingBox& areaCovered() const { return areaCovered_; } 00113 void updateAreaCovered(); 00114 void move(); 00115 00116 enum GeomType { geom_CYLINDER, geom_LONG_CYLINDER }; 00117 00118 enum GeomType geometryType() const { 00119 BoundingBox& b = posComponent_->nextPos().bounds_; 00120 if(b.minX_ == b.minZ_ && b.maxX_ == b.maxZ_) 00121 return geom_CYLINDER; 00122 return geom_LONG_CYLINDER; 00123 } 00124 00125 coor_t bouncePoint(const Point3& c, const Point3& testPoint, Point3& dest) const; 00126 coor_t bouncePoint(scale_t alpha, const Point3& testPoint, Point3& dest) const; 00127 coor_t bouncePoints(scale_t alpha, const CollisionComponent& other, Point3& d1, Point3& d2) const; 00128 coor_t bouncePoints(const Point3& o1, const Point3& o2, Point3& d1, Point3& d2) const; 00129 00130 coor_t penetration(const CollisionComponent& other) const; 00131 00132 bool doObstructView() const; 00133 00134 private: 00135 PosComponent* posComponent_; 00136 BoundingBox areaCovered_; 00137 int substance_; 00138 00143 bool isCollideable_, doObstructView_; 00144 const ThingCollide* collide_; 00145 00146 const CollisionComponent* ignore_; 00147 00148 enum GeomType geometryType_; 00149 Point3 p1_, p2_; 00150 coor_t radius_; 00151 }; 00152 } 00153 00154 #endif
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:11 2007 by Doxygen version 1.3.9.1.