Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added svn:eol-style "native" to HelloBullet.cc and HelloBullet.h to prevent line ending problems.

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