aboutsummaryrefslogtreecommitdiff
path: root/src/client/main.cpp
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-07-15 11:35:44 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-07-15 11:35:44 -0400
commitfa49161fe2d7e0a025c9fd8559815d56dfd1f427 (patch)
treecb3a64e2d45ff9f675c256a94f5c1ccb01ec5a09 /src/client/main.cpp
parentb98dbac4ed2f755ce71bd9be17f26a3f86c1e3cc (diff)
downloadbrokengine-fa49161fe2d7e0a025c9fd8559815d56dfd1f427.tar.gz
brokengine-fa49161fe2d7e0a025c9fd8559815d56dfd1f427.tar.bz2
brokengine-fa49161fe2d7e0a025c9fd8559815d56dfd1f427.zip
Added static physics things
Added some phyics stuff! woo! * Added physics models from file * Added physics boxes * Added a maya camera * Added lights * Various refactoring
Diffstat (limited to 'src/client/main.cpp')
-rw-r--r--src/client/main.cpp178
1 files changed, 95 insertions, 83 deletions
diff --git a/src/client/main.cpp b/src/client/main.cpp
index 65dd99c..52de76f 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -55,93 +55,98 @@ void ClearObjects() {
for(list<btRigidBody *>::Iterator Iterator = Objects.begin(); Iterator != Objects.end(); ++Iterator) {
btRigidBody *Object = *Iterator;
+ printf("Found an object to clean:%p\n",Object);
+
// Delete irrlicht node
ISceneNode *Node = static_cast<ISceneNode *>(Object->getUserPointer());
+ printf("got node\n");
Node->remove();
-
+ printf("removed node\n");
// Remove the object from the world
World->removeRigidBody(Object);
-
+ printf("removed rigidbody\n");
+ printf("right before delete, object is %p\n",Object);
delete Object;
+ printf("deleted object\n");
}
Objects.clear();
}
// Create a box rigid body
-void CreateBox(ISceneManager* irrScene, const btVector3 &TPosition, const core::vector3df &TScale, btScalar TMass) {
-
- // Create an Irrlicht cube
- scene::ISceneNode *Node = irrScene->addCubeSceneNode(1.0f);
- Node->setScale(TScale);
-
- Node->setMaterialFlag(video::EMF_LIGHTING, 1);
- Node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
- //Node->setMaterialTexture(0, irrDriver->getTexture("rust0.jpg"));
-
- // Set the initial position of the object
- btTransform Transform;
- Transform.setIdentity();
- Transform.setOrigin(TPosition);
-
- // Give it a default MotionState
- btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
-
- // Create the shape
- btVector3 HalfExtents(TScale.X * 0.5f, TScale.Y * 0.5f, TScale.Z * 0.5f);
- btCollisionShape *Shape = new btBoxShape(HalfExtents);
-
- // Add mass
- btVector3 LocalInertia;
- Shape->calculateLocalInertia(TMass, LocalInertia);
-
- // Create the rigid body object
- btRigidBody *RigidBody = new btRigidBody(TMass, MotionState, Shape, LocalInertia);
-
- // Store a pointer to the irrlicht node so we can update it later
- RigidBody->setUserPointer((void *)(Node));
-
- // Add it to the world
- World->addRigidBody(RigidBody);
- Objects.push_back(RigidBody);
-}
-
-// Create a sphere rigid body
-void CreateSphere(ISceneManager* irrScene, const btVector3 &TPosition, btScalar TRadius, btScalar TMass) {
-
- // Create an Irrlicht sphere
- scene::ISceneNode *Node = irrScene->addSphereSceneNode(TRadius, 32);
- Node->setMaterialFlag(video::EMF_LIGHTING, 1);
- Node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
- //Node->setMaterialTexture(0, irrDriver->getTexture("ice0.jpg"));
-
- // Set the initial position of the object
- btTransform Transform;
- Transform.setIdentity();
- Transform.setOrigin(TPosition);
-
- // Give it a default MotionState
- btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
-
- // Create the shape
- btCollisionShape *Shape = new btSphereShape(TRadius);
-
- // Add mass
- btVector3 LocalInertia;
- Shape->calculateLocalInertia(TMass, LocalInertia);
-
- // Create the rigid body object
- btRigidBody *RigidBody = new btRigidBody(TMass, MotionState, Shape, LocalInertia);
-
- // Store a pointer to the irrlicht node so we can update it later
- RigidBody->setUserPointer((void *)(Node));
-
- // Add it to the world
- World->addRigidBody(RigidBody);
- Objects.push_back(RigidBody);
-}
-
-// Converts a quaternion to an euler angle
+// void CreateBox(ISceneManager* irrScene, const btVector3 &TPosition, const core::vector3df &TScale, btScalar TMass) {
+//
+// // Create an Irrlicht cube
+// scene::ISceneNode *Node = irrScene->addCubeSceneNode(1.0f);
+// Node->setScale(TScale);
+//
+// Node->setMaterialFlag(video::EMF_LIGHTING, 1);
+// Node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
+// //Node->setMaterialTexture(0, irrDriver->getTexture("rust0.jpg"));
+//
+// // Set the initial position of the object
+// btTransform Transform;
+// Transform.setIdentity();
+// Transform.setOrigin(TPosition);
+//
+// // Give it a default MotionState
+// btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
+//
+// // Create the shape
+// btVector3 HalfExtents(TScale.X * 0.5f, TScale.Y * 0.5f, TScale.Z * 0.5f);
+// btCollisionShape *Shape = new btBoxShape(HalfExtents);
+//
+// // Add mass
+// btVector3 LocalInertia;
+// Shape->calculateLocalInertia(TMass, LocalInertia);
+//
+// // Create the rigid body object
+// btRigidBody *RigidBody = new btRigidBody(TMass, MotionState, Shape, LocalInertia);
+//
+// // Store a pointer to the irrlicht node so we can update it later
+// RigidBody->setUserPointer((void *)(Node));
+//
+// // Add it to the world
+// World->addRigidBody(RigidBody);
+// Objects.push_back(RigidBody);
+// }
+//
+// // Create a sphere rigid body
+// void CreateSphere(ISceneManager* irrScene, const btVector3 &TPosition, btScalar TRadius, btScalar TMass) {
+//
+// // Create an Irrlicht sphere
+// scene::ISceneNode *Node = irrScene->addSphereSceneNode(TRadius, 32);
+// Node->setMaterialFlag(video::EMF_LIGHTING, 1);
+// Node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
+// //Node->setMaterialTexture(0, irrDriver->getTexture("ice0.jpg"));
+//
+// // Set the initial position of the object
+// btTransform Transform;
+// Transform.setIdentity();
+// Transform.setOrigin(TPosition);
+//
+// // Give it a default MotionState
+// btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
+//
+// // Create the shape
+// btCollisionShape *Shape = new btSphereShape(TRadius);
+//
+// // Add mass
+// btVector3 LocalInertia;
+// Shape->calculateLocalInertia(TMass, LocalInertia);
+//
+// // Create the rigid body object
+// btRigidBody *RigidBody = new btRigidBody(TMass, MotionState, Shape, LocalInertia);
+//
+// // Store a pointer to the irrlicht node so we can update it later
+// RigidBody->setUserPointer((void *)(Node));
+//
+// // Add it to the world
+// World->addRigidBody(RigidBody);
+// Objects.push_back(RigidBody);
+// }
+//
+// // Converts a quaternion to an euler angle
void QuaternionToEuler(const btQuaternion &TQuat, btVector3 &TEuler) {
btScalar W = TQuat.getW();
btScalar X = TQuat.getX();
@@ -162,7 +167,7 @@ void QuaternionToEuler(const btQuaternion &TQuat, btVector3 &TEuler) {
// - TDeltaTime tells the simulation how much time has passed since the last frame so the simulation can run independently of the frame rate.
void UpdatePhysics(u32 TDeltaTime) {
- World->stepSimulation(TDeltaTime * 0.001f, 60);
+ World->stepSimulation(TDeltaTime * 0.002f, 60);
btRigidBody *TObject;
// Relay the object's orientation to irrlicht
@@ -188,17 +193,22 @@ void UpdatePhysics(u32 TDeltaTime) {
void CreateStartScene(ISceneManager* smgr) {
ClearObjects();
- CreateBox(smgr,btVector3(0.0f, 0.0f, 0.0f), core::vector3df(10.0f, 0.5f, 10.0f), 0.0f);
+ //CreateBox(smgr,btVector3(0.0f, 0.0f, 0.0f), core::vector3df(10.0f, 0.5f, 10.0f), 0.0f);
}
int main(int argc, char *argv[]){
+ printf("Brok[en]gine");
// Initialize bullet
btBroadphaseInterface *BroadPhase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000));
+ printf("Broadphase\n");
btDefaultCollisionConfiguration *CollisionConfiguration = new btDefaultCollisionConfiguration();
+ printf("Collision config\n");
btCollisionDispatcher *Dispatcher = new btCollisionDispatcher(CollisionConfiguration);
+ printf("Dispatcher\n");
btSequentialImpulseConstraintSolver *Solver = new btSequentialImpulseConstraintSolver();
+ printf("Solver\n");
World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);
-
+ printf("Physics world init ok.\n");
//Create a new lua state, this gets shared everywhere
lua_State *state = luaL_newstate();
L = state;
@@ -253,10 +263,11 @@ int main(int argc, char *argv[]){
GetRandInt(5) / 5.0f + 0.2f, 1.0f);
*/
- guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
- rect<s32>(10,10,260,22), true);
-
- smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
+ //guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
+ // rect<s32>(10,10,260,22), true);
+ printf("Abbout to add camera\n");
+ //smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
+ //smgr->addCameraSceneNodeMaya();
printf("Everything registered, about to start running device!\n");
@@ -281,11 +292,12 @@ int main(int argc, char *argv[]){
lua_getfield(state,-1,"tick");
if(!lua_isnil(state,-1))
lua_call(state,0,0);
+ lua_pop(state,2);
}
printf("Claoseing lua state...\n");
//lua_close(state);
printf("clearing objects...\n");
- ClearObjects();
+ ClearObjects(); //Clearing objects must be done after we droped the device.
printf("cleared objects\n");
delete BroadPhase;
printf("deleted broadphase\n");