Changeset 2056 for code/branches/physics/src/orxonox
- Timestamp:
- Oct 29, 2008, 3:58:18 PM (16 years ago)
- Location:
- code/branches/physics/src/orxonox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/CMakeLists.txt
r1995 r2056 107 107 tinyxml_orxonox 108 108 tolualib_orxonox 109 ogreode_orxonox110 109 LibLinearMath 111 110 LibBulletCollision -
code/branches/physics/src/orxonox/objects/HelloBullet.cc
r2047 r2056 42 42 #include "GraphicsEngine.h" 43 43 44 #include "util/Sleep.h" 45 46 44 47 namespace orxonox 45 48 { … … 50 53 RegisterObject(HelloBullet); 51 54 COUT(0) << "HelloBullet loaded" << std::endl ; 52 int maxProxies = 1024 55 int maxProxies = 1024; 53 56 54 57 55 56 57 58 btVector3 worldAabbMin(-10000,-10000,-10000); 59 btVector3 worldAabbMax(10000,10000,10000); 60 btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies); 58 61 59 // Set up the collision configuration and dispatcher 60 btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); 61 btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); 62 btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); 63 btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); 62 64 63 // The actual physics solver 64 btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; 65 btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; 65 66 66 // The world. 67 btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration); 67 dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration); 68 69 dynamicsWorld->setGravity(btVector3(0,-10,0)); 70 71 72 btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),10); 73 74 btCollisionShape* fallShape = new btSphereShape(1); 75 76 77 btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0))); 78 btRigidBody::btRigidBodyConstructionInfo 79 groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0)); 80 btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI); 81 dynamicsWorld->addRigidBody(groundRigidBody); 82 83 84 btDefaultMotionState* fallMotionState = 85 new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,100,0))); 86 btScalar mass = 1000; 87 btVector3 fallInertia(0,0,0); 88 fallShape->calculateLocalInertia(mass,fallInertia); 89 btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia); 90 fallRigidBody = new btRigidBody(fallRigidBodyCI); 91 dynamicsWorld->addRigidBody(fallRigidBody); 92 93 94 95 //load floor mash 96 Ogre::SceneManager* sceneMgr = GraphicsEngine::getInstance().getLevelSceneManager(); 97 98 int i = 0; 99 Ogre::StaticGeometry* floor; 100 floor = sceneMgr->createStaticGeometry("StaticFloor"); 101 floor->setRegionDimensions(Ogre::Vector3(160.0, 100.0, 160.0)); 102 // Set the region origin so the center is at 0 world 103 floor->setOrigin(Ogre::Vector3::ZERO); 104 for (Real z = -80.0; z <= 80.0; z += 20.0) 105 { 106 for (Real x = -80.0; x <= 80.0; x += 20.0) 107 { 108 std::string name = std::string("Ground") + convertToString(i++); 109 Ogre::Entity* entity = sceneMgr->createEntity(name, "plane.mesh"); 110 entity->setQueryFlags (1<<4); 111 entity->setCastShadows(false); 112 floor->addEntity(entity, Ogre::Vector3(x,0,z)); 113 } 114 } 115 116 floor->build(); 117 118 119 // crate 120 121 entity_ = sceneMgr->createEntity("crate","crate.mesh"); 122 entity_->setQueryFlags (1<<2); 123 sceneNode_ = sceneMgr->getRootSceneNode()->createChildSceneNode("crate"); 124 sceneNode_->attachObject(entity_); 125 entity_->setNormaliseNormals(true); 126 entity_->setCastShadows(true); 127 sceneNode_ -> setPosition(Vector3(0,100,0)); 128 129 130 131 132 68 133 } 69 134 70 135 HelloBullet::~HelloBullet() 71 136 { 72 // empty 137 // dynamicsWorld->removeRigidBody(fallRigidBody); 138 // delete fallRigidBody->getMotionState(); 139 // delete fallRigidBody; 140 141 // dynamicsWorld->removeRigidBody(groundRigidBody); 142 // delete groundRigidBody->getMotionState(); 143 // delete groundRigidBody; 144 145 146 // delete fallShape; 147 148 // delete groundShape; 149 150 151 // delete dynamicsWorld; 152 // delete solver; 153 // delete collisionConfiguration; 154 // delete dispatcher; 155 // delete broadphase; 156 73 157 } 74 158 … … 95 179 void HelloBullet::tick(float dt) 96 180 { 97 // only update physics in a certain interval 181 dynamicsWorld->stepSimulation(1/60.f,10); 182 btTransform trans; 183 fallRigidBody->getMotionState()->getWorldTransform(trans); 184 COUT(0) << "sphere height: " << trans.getOrigin().getY() << std::endl; 185 sceneNode_ -> setPosition(Vector3(0,trans.getOrigin().getY(),0)); 186 // msleep(20); 187 188 98 189 } 99 190 -
code/branches/physics/src/orxonox/objects/HelloBullet.h
r1995 r2056 51 51 52 52 private: 53 53 Ogre::SceneNode* sceneNode_; 54 Ogre::Entity* entity_; 55 btRigidBody* fallRigidBody; 56 btDiscreteDynamicsWorld* dynamicsWorld; 54 57 }; 55 58
Note: See TracChangeset
for help on using the changeset viewer.