Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 2, 2008, 8:43:36 PM (16 years ago)
Author:
rgrieder
Message:

Physics: HelloBullet.cc should compile and run again. Testing tardis now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/orxonox/objects/PhysicsTest.cc

    r2119 r2124  
    4040#include "core/XMLPort.h"
    4141#include "GraphicsEngine.h"
     42#include "Scene.h"
    4243
    4344namespace orxonox
     
    4546    CreateFactory(PhysicsTest);
    4647
    47     PhysicsTest::PhysicsTest()
    48         : odeWorld_(0)
     48    PhysicsTest::PhysicsTest(BaseObject* creator)
     49        : BaseObject(creator)
     50        , odeWorld_(0)
    4951        , odeSpace_(0)
    5052        , odeStepper_(0)
     
    8486        SUPER(PhysicsTest, XMLPort, xmlelement, mode);
    8587
    86         Ogre::SceneManager* sceneMgr = GraphicsEngine::getInstance().getLevelSceneManager();
     88        Ogre::SceneManager* sceneMgr = this->getScene()->getSceneManager();
    8789
    8890        // set up OgreOde
     
    103105        const Ogre::Real time_scale = Ogre::Real(1.7);
    104106        const Ogre::Real max_frame_time = Ogre::Real(1.0 / 4);
    105         odeStepper_ = new OgreOde::StepHandler(odeWorld_, OgreOde::StepHandler::QuickStep,_time_step,
     107        odeStepper_ = new OgreOde::StepHandler(odeWorld_, OgreOde::StepHandler::QuickStep, _time_step,
    106108            max_frame_time, time_scale);
    107109
    108110
    109         // Create a hanging crate
     111        // create a plane in x-z dimensions.
    110112
    111113        odeGround_ = new OgreOde::InfinitePlaneGeometry(Ogre::Plane(Ogre::Vector3(0,1,0),0),
    112114            odeWorld_, odeWorld_->getDefaultSpace());
    113115
    114         CollidingObject* collidingObject = new CollidingObject();
    115        
    116         odeGround_->setUserObject(static_cast<CollisionTestedObject*>(collidingObject));
     116        CollidingObject* collidingObject = new CollidingObject();
     117        odeGround_->setUserObject(static_cast<CollisionTestedObject*>(collidingObject));
    117118
    118119        // Use a load of meshes to represent the floor
     
    139140
    140141
    141         // create a plane in x-z dimensions.
     142        // create a hanging crate
    142143
    143144        entity_ = sceneMgr->createEntity("crate","crate.mesh");
     
    147148        entity_->setNormaliseNormals(true);
    148149        entity_->setCastShadows(true);
    149 
    150150
    151151        odeBody_ = new OgreOde::Body(odeWorld_);
     
    178178    }
    179179
    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                
     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 res = true;
     205
    206206        if (g1->getUserObject())
    207                 if (!static_cast<CollisionTestedObject*>(g1->getUserObject())->Collide(true, Contact))
    208                         Return = false;
    209        
     207            if (!static_cast<CollisionTestedObject*>(g1->getUserObject())->collide(true, contact))
     208                res = false;
     209
    210210        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         }
     211            if (!static_cast<CollisionTestedObject*>(g2->getUserObject())->collide(false, contact))
     212                res = false;
     213
     214        return res;
     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    }
    225225
    226226}
Note: See TracChangeset for help on using the changeset viewer.