[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 | |
---|
[2201] | 32 | #include <OgreSceneNode.h> |
---|
[1995] | 33 | #include <OgreStaticGeometry.h> |
---|
| 34 | #include <OgreSceneManager.h> |
---|
| 35 | #include <OgreEntity.h> |
---|
| 36 | |
---|
| 37 | #include "util/Convert.h" |
---|
| 38 | #include "core/CoreIncludes.h" |
---|
| 39 | #include "core/ConfigValueIncludes.h" |
---|
| 40 | #include "core/XMLPort.h" |
---|
[2124] | 41 | #include "objects/Scene.h" |
---|
[1995] | 42 | |
---|
[2056] | 43 | #include "util/Sleep.h" |
---|
| 44 | |
---|
| 45 | |
---|
[1995] | 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | CreateFactory(HelloBullet); |
---|
| 49 | |
---|
[2124] | 50 | HelloBullet::HelloBullet(BaseObject* creator) |
---|
| 51 | : BaseObject(creator) |
---|
[1995] | 52 | { |
---|
[2178] | 53 | RegisterObject(HelloBullet); |
---|
| 54 | COUT(0) << "HelloBullet loaded" << std::endl ; |
---|
| 55 | int maxProxies = 1024; |
---|
[2047] | 56 | |
---|
| 57 | |
---|
[2150] | 58 | // btVector3 worldAabbMin(-10000,-10000,-10000); |
---|
| 59 | // btVector3 worldAabbMax(10000,10000,10000); |
---|
| 60 | // btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies); |
---|
[2047] | 61 | |
---|
[2150] | 62 | // btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); |
---|
| 63 | // btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); |
---|
[2047] | 64 | |
---|
[2150] | 65 | // btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; |
---|
[2047] | 66 | |
---|
[2150] | 67 | // dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration); |
---|
[2056] | 68 | |
---|
[2178] | 69 | dynamicsWorld = getCreator()->getScene()->getPhysicalWorld(); |
---|
[2056] | 70 | |
---|
| 71 | |
---|
[2177] | 72 | btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1); |
---|
[2056] | 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 | |
---|
[2178] | 94 | //load floor mash |
---|
[2124] | 95 | Ogre::SceneManager* sceneMgr = creator->getScene()->getSceneManager(); |
---|
[2056] | 96 | |
---|
| 97 | int i = 0; |
---|
| 98 | Ogre::StaticGeometry* floor; |
---|
| 99 | floor = sceneMgr->createStaticGeometry("StaticFloor"); |
---|
| 100 | floor->setRegionDimensions(Ogre::Vector3(160.0, 100.0, 160.0)); |
---|
| 101 | // Set the region origin so the center is at 0 world |
---|
| 102 | floor->setOrigin(Ogre::Vector3::ZERO); |
---|
| 103 | for (Real z = -80.0; z <= 80.0; z += 20.0) |
---|
| 104 | { |
---|
| 105 | for (Real x = -80.0; x <= 80.0; x += 20.0) |
---|
| 106 | { |
---|
| 107 | std::string name = std::string("Ground") + convertToString(i++); |
---|
| 108 | Ogre::Entity* entity = sceneMgr->createEntity(name, "plane.mesh"); |
---|
| 109 | entity->setQueryFlags (1<<4); |
---|
| 110 | entity->setCastShadows(false); |
---|
| 111 | floor->addEntity(entity, Ogre::Vector3(x,0,z)); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | floor->build(); |
---|
| 116 | |
---|
| 117 | |
---|
[2178] | 118 | // crate |
---|
[2056] | 119 | |
---|
| 120 | entity_ = sceneMgr->createEntity("crate","crate.mesh"); |
---|
| 121 | entity_->setQueryFlags (1<<2); |
---|
| 122 | sceneNode_ = sceneMgr->getRootSceneNode()->createChildSceneNode("crate"); |
---|
| 123 | sceneNode_->attachObject(entity_); |
---|
| 124 | entity_->setNormaliseNormals(true); |
---|
| 125 | entity_->setCastShadows(true); |
---|
[2178] | 126 | sceneNode_ -> setPosition(Vector3(0,100,0)); |
---|
[1995] | 127 | } |
---|
| 128 | |
---|
| 129 | HelloBullet::~HelloBullet() |
---|
| 130 | { |
---|
[2056] | 131 | // dynamicsWorld->removeRigidBody(fallRigidBody); |
---|
| 132 | // delete fallRigidBody->getMotionState(); |
---|
| 133 | // delete fallRigidBody; |
---|
| 134 | |
---|
| 135 | // dynamicsWorld->removeRigidBody(groundRigidBody); |
---|
| 136 | // delete groundRigidBody->getMotionState(); |
---|
| 137 | // delete groundRigidBody; |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | // delete fallShape; |
---|
| 141 | |
---|
| 142 | // delete groundShape; |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | // delete dynamicsWorld; |
---|
| 146 | // delete solver; |
---|
| 147 | // delete collisionConfiguration; |
---|
| 148 | // delete dispatcher; |
---|
| 149 | // delete broadphase; |
---|
| 150 | |
---|
[1995] | 151 | } |
---|
| 152 | |
---|
| 153 | void HelloBullet::setConfigValues() |
---|
| 154 | { |
---|
| 155 | |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | /** |
---|
| 159 | @brief |
---|
| 160 | XML loading and saving. |
---|
| 161 | @param |
---|
| 162 | xmlelement The XML-element |
---|
| 163 | @param |
---|
| 164 | loading Loading (true) or saving (false) |
---|
| 165 | @return |
---|
| 166 | The XML-element |
---|
| 167 | */ |
---|
| 168 | void HelloBullet::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 169 | { |
---|
| 170 | SUPER(HelloBullet, XMLPort, xmlelement, mode); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | void HelloBullet::tick(float dt) |
---|
| 174 | { |
---|
[2178] | 175 | dynamicsWorld->stepSimulation(dt,10); |
---|
| 176 | btTransform trans; |
---|
| 177 | fallRigidBody->getMotionState()->getWorldTransform(trans); |
---|
| 178 | // COUT(0) << "sphere height: " << trans.getOrigin().getY() << std::endl; |
---|
| 179 | sceneNode_ -> setPosition(Vector3(0,trans.getOrigin().getY(),0)); |
---|
| 180 | // msleep(20); |
---|
[1995] | 181 | } |
---|
| 182 | } |
---|