Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics_new/src/orxonox/objects/HelloBullet.cc @ 2119

Last change on this file since 2119 was 2119, checked in by rgrieder, 15 years ago

Merged physics branch into physics_new branch.

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 "GraphicsEngine.h"
43
44#include "util/Sleep.h"
45
46
47namespace orxonox
48{
49    CreateFactory(HelloBullet);
50   
51    HelloBullet::HelloBullet()
52    {
53           RegisterObject(HelloBullet);
54           COUT(0) << "HelloBullet loaded" << std::endl ;
55           int maxProxies = 1024;
56
57
58        btVector3 worldAabbMin(-10000,-10000,-10000);
59        btVector3 worldAabbMax(10000,10000,10000);
60        btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
61
62        btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
63        btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
64
65        btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
66
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
133    }
134
135    HelloBullet::~HelloBullet()
136    {
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
157    }
158
159    void HelloBullet::setConfigValues()
160    {
161
162    }
163
164    /**
165    @brief
166        XML loading and saving.
167    @param
168        xmlelement The XML-element
169    @param     
170        loading Loading (true) or saving (false)
171    @return
172        The XML-element
173    */
174    void HelloBullet::XMLPort(Element& xmlelement, XMLPort::Mode mode)
175    {
176      SUPER(HelloBullet, XMLPort, xmlelement, mode);
177    }
178
179    void HelloBullet::tick(float dt)
180    {
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               
189    }
190
191}
Note: See TracBrowser for help on using the repository browser.