Changeset 1933 for code/branches/physics/src/orxonox/objects
- Timestamp:
- Oct 15, 2008, 3:52:33 PM (16 years ago)
- Location:
- code/branches/physics/src/orxonox/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/PhysicsTest.cc
r1925 r1933 34 34 #include <OgreEntity.h> 35 35 #include "ogreode/OgreOde_Core.h" 36 #include "ogreode/OgreOdeGeometry.h" 36 37 #include "util/Convert.h" 37 38 #include "core/CoreIncludes.h" … … 99 100 // set up stepper 100 101 101 const Ogre::Real _time_step = 0.5; 102 const Ogre::Real _time_step = 0.5;http://isg.ee.ethz.ch/ 102 103 const Ogre::Real time_scale = Ogre::Real(1.7); 103 104 const Ogre::Real max_frame_time = Ogre::Real(1.0 / 4); … … 110 111 odeGround_ = new OgreOde::InfinitePlaneGeometry(Ogre::Plane(Ogre::Vector3(0,1,0),0), 111 112 odeWorld_, odeWorld_->getDefaultSpace()); 113 114 CollidingObject* collidingObject = new CollidingObject(); 115 116 odeGround_->setUserObject(static_cast<CollisionTestedObject*>(collidingObject)); 117 112 118 // Use a load of meshes to represent the floor 113 119 int i = 0; … … 128 134 floor->addEntity(entity, Ogre::Vector3(x,0,z)); 129 135 } 130 } 136 } 137 131 138 floor->build(); 132 139 … … 156 163 odeGeom_->setBody(odeBody_); 157 164 entity_->setUserObject(odeGeom_); 165 odeGeom_->setUserObject(static_cast<CollisionTestedObject*>(this)); 166 158 167 159 168 odeBody_->setOrientation(Quaternion(Degree(30.0), Vector3(0,0,0))); … … 168 177 odeWorld_->synchronise(); 169 178 } 179 180 bool PhysicsTest::collision(OgreOde::Contact *Contact) 181 { 182 // Check for collisions between things that are connected and ignore them 183 OgreOde::Geometry * const g1 = Contact->getFirstGeometry(); 184 OgreOde::Geometry * const g2 = Contact->getSecondGeometry(); 185 186 if (g1 && g2) 187 { 188 const OgreOde::Body * const b1 = g2->getBody(); 189 const OgreOde::Body * const b2 = g1->getBody(); 190 if (b1 && b2 && OgreOde::Joint::areConnected(b1, b2)) 191 return false; 192 } 193 194 //set contact parameters: 195 Contact->setBouncyness(1.0); 196 Contact->setCoulombFriction(OgreOde::Utility::Infinity); 197 Contact->setForceDependentSlip(1.0); 198 Contact->setAdditionalFDS(1.0); 199 200 /*we have 2 collidable objects from our object system, if one of the Collide function returns false, e return false in this method, too, else we return true, so ode computes a normal collision. 201 true means ode will treat this like a normal collison => rigid body behavior 202 false means ode will not treat this collision at all => objects ignore each other*/ 203 204 bool Return = true; 205 206 if (g1->getUserObject()) 207 if (!static_cast<CollisionTestedObject*>(g1->getUserObject())->Collide(true, Contact)) 208 Return = false; 209 210 if (g2->getUserObject()) 211 if (!static_cast<CollisionTestedObject*>(g2->getUserObject())->Collide(false, Contact)) 212 Return = false; 213 214 return Return; 215 } 216 217 bool CollidingObject::Collide(bool MineIsFirst, OgreOde::Contact *Contact) 218 { 219 Contact->setForceDependentSlip(Contact->getForceDependentSlip() * ForceDependentSlip); 220 Contact->setAdditionalFDS(Contact->getForceDependentSlip2() * ForceDependentSlip); 221 Contact->setCoulombFriction(Contact->getCoulombFrictionMu() * Friction); 222 Contact->setBouncyness(Contact->getBouncyness() * Bouncyness, Contact->getBouncynessVelocity() * BounceVelocity); 223 return true; 224 } 225 170 226 } -
code/branches/physics/src/orxonox/objects/PhysicsTest.h
r1924 r1933 64 64 bool bRunning_; 65 65 }; 66 67 68 class _OrxonoxExport CollisionTestedObject 69 { 70 public: 71 CollisionTestedObject(void); 72 virtual ~CollisionTestedObject(void); 73 virtual bool Collide(bool MineIsFirst, OgreOde::Contact *Contact) = 0; 74 }; 75 76 class _OrxonoxExport CollidingObject : public virtual CollisionTestedObject 77 { 78 protected: 79 float Friction; 80 float Bouncyness; 81 float BounceVelocity; 82 float ForceDependentSlip; 83 84 public: 85 CollidingObject(void); 86 virtual ~CollidingObject(void); 87 88 // bool virtual WriteToIni(IniFile& Ini) const; 89 // bool virtual LoadFromIni(const std::basic_string<wchar_t>& ObjectID, IniFile& Ini); 90 91 float GetFriction(void) const {return Friction;} 92 float GetBouncyness(void) const {return Bouncyness;} 93 float GetBounceVelocity(void) const {return BounceVelocity;} 94 float GetFDS(void) const {return ForceDependentSlip;} 95 96 virtual bool Collide(bool MineIsFirst, OgreOde::Contact *Contact); 97 98 private: 99 static const wchar_t* KEY_FRICTION; 100 static const float DEF_FRICTION; 101 static const wchar_t* KEY_BOUNCYNESS; 102 static const float DEF_BOUNCYNESS; 103 static const wchar_t* KEY_FDS; 104 static const float DEF_FDS; 105 static const wchar_t* KEY_BOUNCE_VELO; 106 static const float DEF_BOUNCE_VELO; 107 }; 108 66 109 } 67 110 111 112 68 113 #endif /* _PhysicsTest_H__ */
Note: See TracChangeset
for help on using the changeset viewer.