Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/orxonox/objects/HelloBullet.cc @ 2124

Last change on this file since 2124 was 2124, checked in by rgrieder, 16 years ago

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

File size: 5.8 KB
Line 
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"
42#include "objects/Scene.h"
43
44#include "util/Sleep.h"
45
46
47namespace orxonox
48{
49    CreateFactory(HelloBullet);
50   
51    HelloBullet::HelloBullet(BaseObject* creator)
52        : BaseObject(creator)
53    {
54           RegisterObject(HelloBullet);
55           COUT(0) << "HelloBullet loaded" << std::endl ;
56           int maxProxies = 1024;
57
58
59        btVector3 worldAabbMin(-10000,-10000,-10000);
60        btVector3 worldAabbMax(10000,10000,10000);
61        btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
62
63        btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
64        btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
65
66        btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
67
68        dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
69
70        dynamicsWorld->setGravity(btVector3(0,-10,0));
71
72
73        btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),10);
74
75        btCollisionShape* fallShape = new btSphereShape(1);
76
77
78        btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
79        btRigidBody::btRigidBodyConstructionInfo
80                groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
81        btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
82        dynamicsWorld->addRigidBody(groundRigidBody);
83
84
85        btDefaultMotionState* fallMotionState =
86                new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,100,0)));
87        btScalar mass = 1000;
88        btVector3 fallInertia(0,0,0);
89        fallShape->calculateLocalInertia(mass,fallInertia);
90        btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
91        fallRigidBody = new btRigidBody(fallRigidBodyCI);
92        dynamicsWorld->addRigidBody(fallRigidBody);
93
94 
95
96//load floor mash
97        Ogre::SceneManager* sceneMgr = creator->getScene()->getSceneManager();
98
99        int i = 0;
100        Ogre::StaticGeometry* floor;
101        floor = sceneMgr->createStaticGeometry("StaticFloor");
102        floor->setRegionDimensions(Ogre::Vector3(160.0, 100.0, 160.0));
103        // Set the region origin so the center is at 0 world
104        floor->setOrigin(Ogre::Vector3::ZERO);
105        for (Real z = -80.0; z <= 80.0; z += 20.0)
106        {
107            for (Real x = -80.0; x <= 80.0; x += 20.0)
108            {
109                std::string name = std::string("Ground") + convertToString(i++);
110                Ogre::Entity* entity = sceneMgr->createEntity(name, "plane.mesh");
111                entity->setQueryFlags (1<<4);
112                entity->setCastShadows(false);
113                floor->addEntity(entity, Ogre::Vector3(x,0,z));
114            }
115        }       
116
117        floor->build();
118
119
120// crate
121
122        entity_ = sceneMgr->createEntity("crate","crate.mesh");
123        entity_->setQueryFlags (1<<2);
124        sceneNode_ = sceneMgr->getRootSceneNode()->createChildSceneNode("crate");
125        sceneNode_->attachObject(entity_);
126        entity_->setNormaliseNormals(true);
127        entity_->setCastShadows(true);
128        sceneNode_ -> setPosition(Vector3(0,100,0));
129
130
131     
132
133
134    }
135
136    HelloBullet::~HelloBullet()
137    {
138     //  dynamicsWorld->removeRigidBody(fallRigidBody);
139     //   delete fallRigidBody->getMotionState();
140     //   delete fallRigidBody;
141
142     //   dynamicsWorld->removeRigidBody(groundRigidBody);
143     //   delete groundRigidBody->getMotionState();
144     //   delete groundRigidBody;
145
146
147     //   delete fallShape;
148
149     //   delete groundShape;
150
151
152     //   delete dynamicsWorld;
153     //   delete solver;
154     //   delete collisionConfiguration;
155     //   delete dispatcher;
156     //   delete broadphase;
157
158    }
159
160    void HelloBullet::setConfigValues()
161    {
162
163    }
164
165    /**
166    @brief
167        XML loading and saving.
168    @param
169        xmlelement The XML-element
170    @param     
171        loading Loading (true) or saving (false)
172    @return
173        The XML-element
174    */
175    void HelloBullet::XMLPort(Element& xmlelement, XMLPort::Mode mode)
176    {
177      SUPER(HelloBullet, XMLPort, xmlelement, mode);
178    }
179
180    void HelloBullet::tick(float dt)
181    {
182                dynamicsWorld->stepSimulation(1/60.f,10);
183                btTransform trans;
184                fallRigidBody->getMotionState()->getWorldTransform(trans);
185                COUT(0) << "sphere height: " << trans.getOrigin().getY() << std::endl;
186                sceneNode_ -> setPosition(Vector3(0,trans.getOrigin().getY(),0));
187        //      msleep(20);
188               
189               
190    }
191
192}
Note: See TracBrowser for help on using the repository browser.