Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 28, 2008, 1:25:16 AM (16 years ago)
Author:
rgrieder
Message:

Finally managed to work out some physics. According to my tests, collisions with simple spheres should work with dynamic/kinematic/static objects. There are currently only a limited number of XML parameters, but we're surely going to extend that. Furthermore there is some more thinking to be done concerning changes of btRigidBody properties when it's already added to the world.

File:
1 edited

Legend:

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

    r2192 r2292  
    3939#include "core/XMLPort.h"
    4040
     41#include "BulletCollision/BroadphaseCollision/btAxisSweep3.h"
     42#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
     43#include "BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h"
     44
    4145namespace orxonox
    4246{
     
    7074        }
    7175
    72         /////////////
    73         // Physics //
    74         /////////////
    75 
    76         // create bullet world; bullet solver etc.
    77 
    78         // int maxProxies = 1024;
    79 
    80         btVector3 worldAabbMin(-10000,-10000,-10000);
    81         btVector3 worldAabbMax(10000,10000,10000);
    82         bt32BitAxisSweep3* broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax);
    83 
    84         this -> collisionConfiguration_ = new btDefaultCollisionConfiguration();
    85         this -> dispatcher_ = new btCollisionDispatcher(collisionConfiguration_);
    86 
    87         this -> solver_ = new btSequentialImpulseConstraintSolver;
    88 
    89         this -> dynamicsWorld_ =  new btDiscreteDynamicsWorld(dispatcher_,broadphase,solver_,collisionConfiguration_);
    90 
    91         dynamicsWorld_->setGravity(btVector3(0,-10,0));
    92 
     76        // No physics for default
     77        this->physicalWorld_ = 0;
    9378
    9479        // test test test
     
    130115        XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true);
    131116
     117        const int defaultMaxWorldSize = 100000;
     118        Vector3 worldAabbMin(-defaultMaxWorldSize, -defaultMaxWorldSize, -defaultMaxWorldSize);
     119        Vector3 worldAabbMax( defaultMaxWorldSize,  defaultMaxWorldSize,  defaultMaxWorldSize);
     120        XMLPortParamVariable(Scene, "negativeWorldRange", worldAabbMin, xmlelement, mode);
     121        XMLPortParamVariable(Scene, "positiveWorldRange", worldAabbMax, xmlelement, mode);
     122        XMLPortParam(Scene, "hasPhysics", setPhysicalWorld, hasPhysics, xmlelement, mode).defaultValue(0, true).defaultValue(1, worldAabbMin).defaultValue(2, worldAabbMax);
     123
    132124        XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
    133125    }
     
    137129        REGISTERSTRING(this->skybox_,     network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox));
    138130        REGISTERDATA(this->ambientLight_, network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight));
     131    }
     132
     133    void Scene::setPhysicalWorld(bool wantPhysics, const Vector3& worldAabbMin, const Vector3& worldAabbMax)
     134    {
     135        if (wantPhysics && !hasPhysics())
     136        {
     137            btVector3 worldAabbMin(worldAabbMin.x, worldAabbMin.y, worldAabbMin.z);
     138            btVector3 worldAabbMax(worldAabbMax.x, worldAabbMax.y, worldAabbMax.z);
     139
     140            btDefaultCollisionConfiguration*     collisionConfig = new btDefaultCollisionConfiguration();
     141            btCollisionDispatcher*               dispatcher      = new btCollisionDispatcher(collisionConfig);
     142            bt32BitAxisSweep3*                   broadphase      = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax);
     143            btSequentialImpulseConstraintSolver* solver          = new btSequentialImpulseConstraintSolver;
     144
     145            this->physicalWorld_ =  new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfig);
     146
     147            // test test test
     148            this->physicalWorld_->setGravity(btVector3(0,0,0));
     149            // test test test
     150        }
     151        else
     152        {
     153            // TODO: Destroy Bullet physics
     154        }
     155    }
     156
     157    void Scene::tick(float dt)
     158    {
     159        if (physicalWorld_)
     160            physicalWorld_->stepSimulation(dt,10);
    139161    }
    140162
Note: See TracChangeset for help on using the changeset viewer.