[1995] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Martin Stypinski |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "HelloBullet.h" |
---|
| 31 | |
---|
| 32 | #include <OgreStaticGeometry.h> |
---|
| 33 | #include <OgreSceneManager.h> |
---|
| 34 | #include <OgreEntity.h> |
---|
| 35 | |
---|
| 36 | #include "ogreode/OgreOde_Core.h" |
---|
| 37 | #include "ogreode/OgreOdeGeometry.h" |
---|
| 38 | #include "util/Convert.h" |
---|
| 39 | #include "core/CoreIncludes.h" |
---|
| 40 | #include "core/ConfigValueIncludes.h" |
---|
| 41 | #include "core/XMLPort.h" |
---|
[2124] | 42 | #include "objects/Scene.h" |
---|
[1995] | 43 | |
---|
[2056] | 44 | #include "util/Sleep.h" |
---|
| 45 | |
---|
| 46 | |
---|
[1995] | 47 | namespace orxonox |
---|
| 48 | { |
---|
| 49 | CreateFactory(HelloBullet); |
---|
| 50 | |
---|
[2124] | 51 | HelloBullet::HelloBullet(BaseObject* creator) |
---|
| 52 | : BaseObject(creator) |
---|
[1995] | 53 | { |
---|
| 54 | RegisterObject(HelloBullet); |
---|
| 55 | COUT(0) << "HelloBullet loaded" << std::endl ; |
---|
[2056] | 56 | int maxProxies = 1024; |
---|
[2047] | 57 | |
---|
| 58 | |
---|
[2150] | 59 | // btVector3 worldAabbMin(-10000,-10000,-10000); |
---|
| 60 | // btVector3 worldAabbMax(10000,10000,10000); |
---|
| 61 | // btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies); |
---|
[2047] | 62 | |
---|
[2150] | 63 | // btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); |
---|
| 64 | // btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); |
---|
[2047] | 65 | |
---|
[2150] | 66 | // btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; |
---|
[2047] | 67 | |
---|
[2150] | 68 | // dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration); |
---|
[2056] | 69 | |
---|
[2150] | 70 | dynamicsWorld = creator->getScene()->getPhysicalWorld(); |
---|
| 71 | dynamicsWorld-> setGravity(btVector3(0,-10,0)); |
---|
[2056] | 72 | |
---|
| 73 | |
---|
| 74 | btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),10); |
---|
| 75 | |
---|
| 76 | btCollisionShape* fallShape = new btSphereShape(1); |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0))); |
---|
| 80 | btRigidBody::btRigidBodyConstructionInfo |
---|
| 81 | groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0)); |
---|
| 82 | btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI); |
---|
| 83 | dynamicsWorld->addRigidBody(groundRigidBody); |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | btDefaultMotionState* fallMotionState = |
---|
| 87 | new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,100,0))); |
---|
| 88 | btScalar mass = 1000; |
---|
| 89 | btVector3 fallInertia(0,0,0); |
---|
| 90 | fallShape->calculateLocalInertia(mass,fallInertia); |
---|
| 91 | btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia); |
---|
| 92 | fallRigidBody = new btRigidBody(fallRigidBodyCI); |
---|
| 93 | dynamicsWorld->addRigidBody(fallRigidBody); |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | //load floor mash |
---|
[2124] | 98 | Ogre::SceneManager* sceneMgr = creator->getScene()->getSceneManager(); |
---|
[2056] | 99 | |
---|
| 100 | int i = 0; |
---|
| 101 | Ogre::StaticGeometry* floor; |
---|
| 102 | floor = sceneMgr->createStaticGeometry("StaticFloor"); |
---|
| 103 | floor->setRegionDimensions(Ogre::Vector3(160.0, 100.0, 160.0)); |
---|
| 104 | // Set the region origin so the center is at 0 world |
---|
| 105 | floor->setOrigin(Ogre::Vector3::ZERO); |
---|
| 106 | for (Real z = -80.0; z <= 80.0; z += 20.0) |
---|
| 107 | { |
---|
| 108 | for (Real x = -80.0; x <= 80.0; x += 20.0) |
---|
| 109 | { |
---|
| 110 | std::string name = std::string("Ground") + convertToString(i++); |
---|
| 111 | Ogre::Entity* entity = sceneMgr->createEntity(name, "plane.mesh"); |
---|
| 112 | entity->setQueryFlags (1<<4); |
---|
| 113 | entity->setCastShadows(false); |
---|
| 114 | floor->addEntity(entity, Ogre::Vector3(x,0,z)); |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | floor->build(); |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | // crate |
---|
| 122 | |
---|
| 123 | entity_ = sceneMgr->createEntity("crate","crate.mesh"); |
---|
| 124 | entity_->setQueryFlags (1<<2); |
---|
| 125 | sceneNode_ = sceneMgr->getRootSceneNode()->createChildSceneNode("crate"); |
---|
| 126 | sceneNode_->attachObject(entity_); |
---|
| 127 | entity_->setNormaliseNormals(true); |
---|
| 128 | entity_->setCastShadows(true); |
---|
| 129 | sceneNode_ -> setPosition(Vector3(0,100,0)); |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | |
---|
[1995] | 135 | } |
---|
| 136 | |
---|
| 137 | HelloBullet::~HelloBullet() |
---|
| 138 | { |
---|
[2056] | 139 | // dynamicsWorld->removeRigidBody(fallRigidBody); |
---|
| 140 | // delete fallRigidBody->getMotionState(); |
---|
| 141 | // delete fallRigidBody; |
---|
| 142 | |
---|
| 143 | // dynamicsWorld->removeRigidBody(groundRigidBody); |
---|
| 144 | // delete groundRigidBody->getMotionState(); |
---|
| 145 | // delete groundRigidBody; |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | // delete fallShape; |
---|
| 149 | |
---|
| 150 | // delete groundShape; |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | // delete dynamicsWorld; |
---|
| 154 | // delete solver; |
---|
| 155 | // delete collisionConfiguration; |
---|
| 156 | // delete dispatcher; |
---|
| 157 | // delete broadphase; |
---|
| 158 | |
---|
[1995] | 159 | } |
---|
| 160 | |
---|
| 161 | void HelloBullet::setConfigValues() |
---|
| 162 | { |
---|
| 163 | |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | @brief |
---|
| 168 | XML loading and saving. |
---|
| 169 | @param |
---|
| 170 | xmlelement The XML-element |
---|
| 171 | @param |
---|
| 172 | loading Loading (true) or saving (false) |
---|
| 173 | @return |
---|
| 174 | The XML-element |
---|
| 175 | */ |
---|
| 176 | void HelloBullet::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 177 | { |
---|
| 178 | SUPER(HelloBullet, XMLPort, xmlelement, mode); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | void HelloBullet::tick(float dt) |
---|
| 182 | { |
---|
[2150] | 183 | dynamicsWorld->stepSimulation(dt,10); |
---|
[2056] | 184 | btTransform trans; |
---|
| 185 | fallRigidBody->getMotionState()->getWorldTransform(trans); |
---|
[2150] | 186 | // COUT(0) << "sphere height: " << trans.getOrigin().getY() << std::endl; |
---|
[2056] | 187 | sceneNode_ -> setPosition(Vector3(0,trans.getOrigin().getY(),0)); |
---|
| 188 | // msleep(20); |
---|
| 189 | |
---|
| 190 | |
---|
[1995] | 191 | } |
---|
| 192 | |
---|
| 193 | } |
---|