]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
creation of Bullet objects in Scene,SceneObject,Model
authorPeter Schaefer <schaeferpm@gmail.com>
Mon, 1 Jun 2015 10:48:09 +0000 (12:48 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Mon, 1 Jun 2015 10:48:09 +0000 (12:48 +0200)
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Model.h
Weave/Scene/Scene.cpp
Weave/Scene/Scene.h
Weave/Scene/SceneObject.cpp
Weave/Scene/SceneObject.h

index bee81ca066abe4369f974ef514b71a79b9b37a9e..32528851f6235bf63f331c12f51162fc0bb159fb 100644 (file)
@@ -251,6 +251,10 @@ void Model::useModelMat(const mat4& _model, Shader* _shader) const
                glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));
 }
 
+Model::operator btCollisionShape*() const
+{
+       return bt_collision_shape;
+}
 
 Overlap Model::isColliding(const Model* _modelThis, const Model* _modelOther, const mat4& _modelMatThis, const mat4& _modelMatOther)
 {
index 0d8db9aa7682cc5669978ebd422d7965b6ab6d68..9802bf57c62422f1cc4eb03ba0a5ea5b9ef6387a 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "../../Overlap.h"
 
+#include <btBulletDynamicsCommon.h>
+
 class Shader;
 class Texture;
 class Overlap;
@@ -59,6 +61,8 @@ public:
 
        virtual operator std::string() const = 0;
 
+       virtual operator btCollisionShape*() const;
+
        class SplitMat
        {
        public:
@@ -160,6 +164,9 @@ protected:
        static vec3 rotateSize(const vec3& size, const mat4& modelMat);
        static float directSize(const vec3& size, const vec3& direction);
 
+       //Bullet
+       btCollisionShape* bt_collision_shape;
+
 private:
 //     vec3 BBmin, BBmax;
 //     vec3 BBsize, BBposition;
index aa7dabb74e6edb07c8a45ee6803be2a0de42c95c..f7d59ea36b7c04aaddd769802828a870a59033b6 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <iostream>
 
+#include <btBulletDynamicsCommon.h>
+
 using std::list;
 using std::set;
 using std::stack;
@@ -28,6 +30,10 @@ using std::stack;
 
 #define timestep 0.01f
 
+#define SCENE_SIZE 500.0
+#define MAX_OBJECTS 16000
+
+
 
 Scene::Scene(unsigned int x, unsigned int y, unsigned int width, unsigned int height, float fovy, float zNear, float zFar, vec3 pos, SceneObject* _lookat) :
 viewPort(x, y, width, height, fovy, zNear, zFar),
@@ -35,6 +41,17 @@ lookat(_lookat),
 move_delta(0)
 {
        currenttime = 0;
+
+       bt_collision_configuration = new btDefaultCollisionConfiguration();
+       bt_dispatcher = new btCollisionDispatcher(bt_collision_configuration);
+
+       btScalar sscene_size = (btScalar)SCENE_SIZE;
+       btVector3 worldAabbMin(-sscene_size, -sscene_size, -sscene_size);
+       btVector3 worldAabbMax(sscene_size, sscene_size, sscene_size);
+
+       bt_broadphase = new bt32BitAxisSweep3(worldAabbMin, worldAabbMax, MAX_OBJECTS, 0, true);
+
+       bt_collision_world = new btCollisionWorld(bt_dispatcher, bt_broadphase, bt_collision_configuration);
 }
 
 
@@ -46,8 +63,12 @@ Scene::~Scene()
                delete (*i);
        }
 
-
-
+       //Bullet
+       delete bt_collision_world;
+       delete bt_broadphase;
+       delete bt_dispatcher;
+       delete bt_collision_configuration;
+       
 
        //if (viewPort != nullptr)
        //      delete viewPort;
index d84571cb10c93ebd043aa90935c1e5f6a19e0fe0..7950188c5b7025a8c4415f0b23cda30fbbd91184 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <list>
 #include <set>
+#include <btBulletDynamicsCommon.h>
 #include <stack>
 
 class SceneObject;
@@ -45,4 +46,16 @@ protected:
        float currenttime;
        std::stack<mat4> PlayerModels;
        //std::stack<vec3> PlayerDirections;
+
+       //class btDefaultCollisionConfiguration;
+       //class btCollisionDispatcher;
+       //class btDbvtBroadphase;
+       //class btSequentialImpulseConstraintSolver;
+       //class btDiscreteDynamicsWorld;
+
+       //Bullet
+       btCollisionConfiguration* bt_collision_configuration;
+       btCollisionDispatcher* bt_dispatcher;
+       btBroadphaseInterface* bt_broadphase;
+       btCollisionWorld* bt_collision_world;
 };
index e8429399807ffc5b35175a3534ebb5c1ecd55c1e..5cb5e979b4c3179867d3e6ca9f1a10df9ed0a50d 100644 (file)
@@ -21,6 +21,8 @@ using std::string;
 
 #define YFALL_SPEED 9.8f
 
+#define BIT(x) 1<<(X)
+
 SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath) :
 model(nullptr),
 modelMat(_modelMat),
@@ -31,7 +33,8 @@ texture(nullptr),
 ySpeed(0),
 yStatic(true),
 ignore(false),
-newModel(true)
+newModel(true),
+bt_collision_object(new btCollisionObject())
 {
        //Message::info("Error from befor?");
        //Graphix::getGlError();
@@ -55,6 +58,7 @@ newModel(true)
        //Graphix::getGlError();
        //Message::info("Done");
 
+       bt_collision_object->setCollisionShape(*model);
 }
 
 SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath) :
@@ -67,7 +71,8 @@ texture(nullptr),
 ySpeed(0),
 yStatic(true),
 ignore(false),
-newModel(false)
+newModel(false),
+bt_collision_object(new btCollisionObject())
 {
        //Message::info("Error from befor?");
        //Graphix::getGlError();
@@ -84,7 +89,9 @@ newModel(false)
        //Message::info("Binding Shader");
        //Graphix::getGlError();
        //Message::info("Done");
-
+       
+       //TypeCast btCollisionShape
+       bt_collision_object->setCollisionShape(*model);
 }
 
 SceneObject::~SceneObject()
@@ -93,6 +100,8 @@ SceneObject::~SceneObject()
                Texture::deleteTexture(*texture);
        if (newModel)
                Model::deleteIMetaModel(*model);
+
+       delete bt_collision_object;
 }
 
 float SceneObject::getFloor() const
index 7ee69a1eb82db4a45cd813d20ef0cf22c7b4db4e..77db4528f3bde0c3233faf3bf387292f48152c0a 100644 (file)
@@ -3,6 +3,8 @@
 #include "../GLM.h"
 #include <string>
 
+#include <btBulletDynamicsCommon.h>
+
 using std::string;
 
 class Scene;
@@ -80,5 +82,8 @@ protected:
 
        bool collision_ignore;
 
+       //Bullet
+       btCollisionObject* bt_collision_object;
+
 };