_vec[i] *= _scale[i];
}
+//#include <assimp/Importer.hpp>
+#include <assimp/scene.h>
+//#include <assimp/postprocess.h>
+
+mat4 aiMat2mat4(const aiMatrix4x4 * aimat)
+{
+ return mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
+}
+
using glm::min;
using glm::max;
+//#include <assimp/scene.h>
+template<typename TReal>
+class aiMatrix4x4t;
+typedef aiMatrix4x4t<float> aiMatrix4x4;
+
#define M_PI 3.14159265358979323846264338327950288 /* pi */
#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
#define M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
void scaleVec3(vec3& _vec, const vec3& _scale);
+
+mat4 aiMat2mat4(const aiMatrix4x4*);
\ No newline at end of file
//import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);\r
\r
bindModel();\r
+ bt_init();\r
\r
name = "BBox";\r
\r
- bt_collision_shape = new btBoxShape(btVector3(.5f,.5f,.5f));\r
-\r
}\r
\r
BBox::~BBox()\r
glBindVertexArray(0);\r
}\r
\r
+void BBox::bt_init(bool isConvex)\r
+{\r
+ if(bt_collision_shape==nullptr)\r
+ bt_collision_shape = new btBoxShape(btVector3(.5f, .5f, .5f));\r
+}\r
+\r
\r
std::string BBox::type2str() const\r
{\r
\r
void drawModel() const override;\r
\r
+ void bt_init(bool isConvex = true) override;\r
+\r
std::string type2str() const override;\r
};\r
\r
#include "IAnimMesh.h"
-IAnimMesh::IAnimMesh(const aiMesh* mesh, const vec3& scale, bool isConvex) : IMesh(mesh, scale, isConvex)
+IAnimMesh::IAnimMesh(const aiMesh* mesh, const vec3& scale, bool isConvex) : IMesh(mesh, scale)
{
}
//\r
//}\r
\r
-IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale, bool _isConvex) : modelpath("IMesh")\r
+IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale) : modelpath("IMesh")\r
{\r
loadMesh(_mesh, numvertices, numfaces, vertex, uvs, normals, index, name, _scale);\r
- btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();\r
- btIndexedMesh part;\r
- part.m_vertexBase = (const unsigned char*)vertex;\r
- part.m_vertexStride = sizeof(float) * 3;\r
- part.m_numVertices = numvertices;\r
- part.m_triangleIndexBase = (const unsigned char*)index;\r
- part.m_triangleIndexStride = sizeof(uint) * 3;\r
- part.m_numTriangles = numfaces;\r
- part.m_indexType = PHY_INTEGER;\r
- meshInterface->addIndexedMesh(part, PHY_INTEGER);\r
-\r
- if (_isConvex)\r
- bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true);\r
- else\r
- bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true);\r
\r
bindModel();\r
\r
-\r
}\r
\r
IMesh::~IMesh()\r
//}\r
\r
\r
-void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
-{\r
- Model::drawBBox(_modelMat, _color);\r
-}\r
+//void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
+//{\r
+// Model::drawBBox(_modelMat, _color);\r
+//}\r
\r
\r
string IMesh::type2str() const\r
#include <string>\r
#include <list>\r
#include "../../GLM.h"\r
-#include "../../Overlap.h"\r
\r
#include "Model.h"\r
\r
// class Node;\r
\r
// IMesh(const std::string& modelpath, uint index=0);\r
- IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f), bool isConvex=true);\r
+ IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f));\r
\r
virtual ~IMesh();\r
\r
//void useModelMat(const mat4& model, Shader* shader) const override;\r
\r
- void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
+ //void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
\r
std::string type2str() const override;\r
\r
\r
if (scene->HasMeshes())// && scene->mNumMeshes > mindex)\r
{\r
- aiMatrix4x4* aimat;\r
mat4 tmpModelMat, tmpModelMatClean;\r
- btTransform tmpModelMatBT;\r
//vec3 BBmin, BBmax, tmpMin, tmpMax;\r
+ IMesh* tmpIMesh;\r
\r
- btCompoundShape* tmp_shape = new btCompoundShape();\r
-\r
- aimat = &(root->mChildren[0]->mTransformation);\r
-\r
- tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);\r
- tmpModelMatClean = removeScale(tmpModelMat);\r
- tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));\r
-\r
+ \r
\r
//if (!scene->HasAnimations())\r
{\r
\r
- IMesh* tmpIMesh;\r
- tmpIMesh = new IMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat), _isConvex);\r
- models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));\r
- tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);\r
\r
- for (uint i = 1; i < scene->mNumMeshes; i++)\r
+ for (uint i = 0; i < scene->mNumMeshes; i++)\r
{\r
- aimat = &(root->mChildren[i]->mTransformation);\r
-\r
- tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);\r
+ tmpModelMat = aiMat2mat4(&(root->mChildren[i]->mTransformation));\r
tmpModelMatClean = removeScale(tmpModelMat);\r
- tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));\r
- tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat), _isConvex);\r
+ tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat));\r
models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));\r
\r
- tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);\r
+ \r
}\r
\r
- bt_collision_shape = tmp_shape;\r
+ \r
\r
}\r
/*\r
\r
IMetaMesh::~IMetaMesh()\r
{\r
+ if (bt_collision_shape != nullptr)\r
+ delete bt_collision_shape;\r
+\r
for (auto i = models.begin(); i != models.end(); ++i)\r
{\r
delete i->first;\r
}\r
}\r
\r
+void IMetaMesh::bt_init(bool _isConvex)\r
+{\r
+ if (bt_collision_shape == nullptr)\r
+ {\r
+ if (models.size() == 1)\r
+ {\r
+ auto tmp = models.front().first;\r
+ tmp->bt_init(_isConvex);\r
+ bt_collision_shape = *tmp;\r
+ }\r
+ else\r
+ {\r
+ btCompoundShape* tmp_shape = new btCompoundShape();\r
+ btTransform tmpModelMatBT;\r
+\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ tmpModelMatBT.setFromOpenGLMatrix(value_ptr(i->second));\r
+ i->first->bt_init(_isConvex);\r
+ tmp_shape->addChildShape(tmpModelMatBT, *(i->first));\r
+ }\r
+\r
+ bt_collision_shape = tmp_shape;\r
+ }\r
+ }\r
+}\r
+\r
\r
void IMetaMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
{\r
{\r
return "IMetaMesh";\r
}\r
-\r
-void IMetaMesh::setMargin(btScalar _margin)\r
-{\r
- for (auto i = models.begin(); i != models.end(); ++i)\r
- {\r
- i->first->setMargin(_margin);\r
- }\r
-}
\ No newline at end of file
+//\r
+//void IMetaMesh::setMargin(btScalar _margin)\r
+//{\r
+// for (auto i = models.begin(); i != models.end(); ++i)\r
+// {\r
+// i->first->setMargin(_margin);\r
+// }\r
+//}
\ No newline at end of file
#include <string>\r
#include <list>\r
#include "../../GLM.h"\r
-#include "../../Overlap.h"\r
\r
class IMesh;\r
class Shader;\r
\r
void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
\r
- std::string type2str() const override;\r
+ virtual void bt_init(bool isConvex = true) override;\r
\r
- void setMargin(btScalar margin) override;\r
+ std::string type2str() const override;\r
\r
protected:\r
\r
\r
Model::~Model()\r
{\r
- if (bt_collision_shape!=nullptr)\r
+ if (bt_collision_shape != nullptr)\r
delete bt_collision_shape;\r
for (auto i = shader_map.begin(); i != shader_map.end(); ++i) {\r
glDeleteVertexArrays(1, &(i->second));\r
getBBoxModel()->drawModel(Graphix::shader_BBox, NULL, _modelMat*translate(center)*glm::scale(size)); //\r
}\r
\r
-void Model::getBBcs(vec3& _center, vec3& _size) const\r
-{\r
- btVector3 minB, maxB;\r
- btTransform trans;\r
- trans.setIdentity();\r
- bt_collision_shape->getAabb(trans, minB, maxB);\r
-\r
- vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ());\r
- vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ());\r
-\r
- _size = (max - min) * .5f;\r
- _center = (max + min) * .5f;\r
-}\r
+//void Model::getBBcs(vec3& _center, vec3& _size) const\r
+//{\r
+// btVector3 minB, maxB;\r
+// btTransform trans;\r
+// trans.setIdentity();\r
+// bt_collision_shape->getAabb(trans, minB, maxB);\r
+//\r
+// vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ());\r
+// vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ());\r
+//\r
+// _size = (max - min) * .5f;\r
+// _center = (max + min) * .5f;\r
+//}\r
\r
void Model::genBuffer(uint &buffer, uint size, void* value)\r
{\r
glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));\r
}\r
\r
-Model::operator btCollisionShape*() const\r
-{\r
- return bt_collision_shape;\r
-}\r
-\r
vec3 Model::rotateSize(const vec3& _size, const mat4& _modelMat)\r
{\r
vec3 newSize(0.f);\r
}\r
\r
\r
-float Model::getPDistHit(const vec3& _P, const vec3& _direction) const\r
-{\r
-\r
- vec3 posA, sizeA;\r
- getBBcs(posA, sizeA);\r
-\r
- //vec3 posAR = (vec3)(modelAR*vec4(posA, 1.f));\r
- //vec3 posBR = (vec3)(modelBR*vec4(posB, 1.f));\r
-\r
-\r
- return 1;\r
-}\r
+//float Model::getPDistHit(const vec3& _P, const vec3& _direction) const\r
+//{\r
+//\r
+// vec3 posA, sizeA;\r
+// getBBcs(posA, sizeA);\r
+//\r
+// //vec3 posAR = (vec3)(modelAR*vec4(posA, 1.f));\r
+// //vec3 posBR = (vec3)(modelBR*vec4(posB, 1.f));\r
+//\r
+//\r
+// return 1;\r
+//}\r
\r
\r
bool Model::loadMesh(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, uint _mindex)\r
return true;\r
}\r
\r
-void Model::setMargin(btScalar _margin)\r
+Model::operator btCollisionShape*() const\r
{\r
- bt_collision_shape->setMargin(_margin);\r
+ return bt_collision_shape;\r
+}\r
+\r
+void Model::bt_setMargin(btScalar _margin)\r
+{\r
+ if(bt_collision_shape!=nullptr)\r
+ bt_collision_shape->setMargin(_margin);\r
+}\r
+\r
+void Model::bt_init(bool _isConvex)\r
+{\r
+ if (bt_collision_shape == nullptr)\r
+ {\r
+ btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();\r
+ btIndexedMesh part;\r
+ part.m_vertexBase = (const unsigned char*)vertex;\r
+ part.m_vertexStride = sizeof(float) * 3;\r
+ part.m_numVertices = numvertices;\r
+ part.m_triangleIndexBase = (const unsigned char*)index;\r
+ part.m_triangleIndexStride = sizeof(uint) * 3;\r
+ part.m_numTriangles = numfaces;\r
+ part.m_indexType = PHY_INTEGER;\r
+ meshInterface->addIndexedMesh(part, PHY_INTEGER);\r
+\r
+ if (_isConvex)\r
+ bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true);\r
+ else\r
+ bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true);\r
+ }\r
}\r
\r
\r
#include <unordered_map>\r
#include <string>\r
\r
-#include "../../Overlap.h"\r
-\r
#include <btBulletDynamicsCommon.h>\r
\r
class Shader;\r
/* Get min&max from BBox */\r
// virtual void getBBmm(vec3& min, vec3& max) const;\r
/* Get size&position from BBox */\r
- void getBBcs(vec3& center, vec3& size) const;\r
-\r
- virtual void setMargin(btScalar margin);\r
+ //void getBBcs(vec3& center, vec3& size) const;\r
\r
static Model* getBBoxModel();\r
static Model* getSkyBoxModel();\r
static void deleteSkyBoxModel();\r
static void deleteIMetaModel(const std::string& modelpath);\r
\r
- virtual float getPDistHit(const vec3& P, const vec3& direction) const;\r
+ //virtual float getPDistHit(const vec3& P, const vec3& direction) const;\r
\r
virtual operator std::string() const;\r
virtual std::string type2str() const = 0;\r
\r
+ \r
virtual operator btCollisionShape*() const;\r
+ virtual void bt_init(bool _convex = true);\r
+ virtual void bt_setMargin(btScalar margin);\r
\r
// Mesh Speichern?\r
static bool loadMesh(const std::string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, std::string& name, uint mindex = 0);\r
static vec3 rotateSize(const vec3& size, const mat4& modelMat);\r
static float directSize(const vec3& size, const vec3& direction);\r
\r
- //Bullet\r
btCollisionShape* bt_collision_shape;\r
\r
private:\r
//{\r
//}\r
\r
-void SkyBox::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
-{\r
-}\r
+//void SkyBox::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
+//{\r
+//}\r
\r
std::string SkyBox::type2str() const\r
{\r
//void useModelMat(const mat4& model, Shader* shader) const override;\r
//void useTexture(Texture* texture, Shader* shader) const override;\r
\r
- void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.f)) const override;\r
+ //void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.f)) const override;\r
\r
std::string type2str() const override;\r
\r
collide_group = COL_EVENT;
collide_with = COL_MARVIN;
+ collision = model;
+ collision->bt_init();
+ bt_collision_object->setCollisionShape(*collision);
+ bt_collision_object->setUserPointer(this);
+
+
btTransform btModelMat;
btModelMat.setFromOpenGLMatrix(value_ptr(modelMat));
btDefaultMotionState* MotionState =
new btDefaultMotionState(btModelMat);
- btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(0, MotionState, *model, btVector3(0, 0, 0));
+ btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(0, MotionState, *collision, btVector3(0, 0, 0));
bt_rigid_body = new btRigidBody(RigidBodyCI);
void EventBox::draw() const
{
- if (Events::isKToggleActive(SDLK_F6))
- model->drawBBox(modelMat,vec4(.3f,.9f,.9f,1.f));
+if (Events::isKToggleActive(SDLK_F6))
+ collision->drawBBox(modelMat,vec4(.3f,.9f,.9f,1.f));
}
void EventBox::collides(SceneObject* _other, btPersistentManifold* _contactManifold, float _deltaT)
#include "../GLM.h"
-Level::Level(Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), Model::newIMetaModel(_modelpath,false), _texturepath)
+Level::Level(Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), Model::newIMetaModel(_modelpath), _texturepath)
{
collide_group = COL_LEVEL;
collide_with = COL_MARVIN | COL_ENEMY;
+ collision = model;
+ collision->bt_init(false);
+ bt_collision_object->setCollisionShape(*collision);
+ bt_collision_object->setUserPointer(this);
+
btTransform btModelMat;
btModelMat.setFromOpenGLMatrix(value_ptr(modelMat));
SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath) :
model(nullptr),
+collision(nullptr),
modelMat(_modelMat),
shader(_shader),
mainScene(NULL),
if (_modelpath != "")
{
model = Model::newIMetaModel(_modelpath);
+ model->bindModel();
model->bindShader(shader);
+
+ /* BADHACK */
+ collision = model;
+ collision->bt_init();
}
new btDefaultMotionState(btModelMat);
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
- model->operator btCollisionShape *()->calculateLocalInertia(mass, fallInertia);
- btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(mass, MotionState, *model, fallInertia);
+ collision->operator btCollisionShape *()->calculateLocalInertia(mass, fallInertia);
+ btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(mass, MotionState, *collision, fallInertia);
bt_rigid_body = new btRigidBody(RigidBodyCI);
- bt_collision_object->setCollisionShape(*model);
+ bt_collision_object->setCollisionShape(*collision);
bt_collision_object->setUserPointer(this);
// bt_rigid_body
SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath) :
model(_model),
+collision(nullptr),
modelMat(_modelMat),
shader(_shader),
mainScene(NULL),
collide_group = COL_ENEMY;
}
+ model->bindModel();
model->bindShader(shader);
//Message::info("Binding Shader");
//Graphix::getGlError();
//Message::info("Done");
//TypeCast btCollisionShape
- bt_collision_object->setCollisionShape(*model);
- bt_collision_object->setUserPointer(this);
+ if (collision != nullptr)
+ {
+ bt_collision_object->setCollisionShape(*collision);
+ bt_collision_object->setUserPointer(this);
+ }
+
}
SceneObject::~SceneObject()
if (texture!=nullptr)
Texture::deleteTexture(*texture);
if (newModel)
+ {
Model::deleteIMetaModel(*model);
+ Model::deleteIMetaModel(*collision);
+ }
+
}
void SceneObject::setMargin(btScalar _margin)
{
- model->setMargin(_margin);
+ collision->bt_setMargin(_margin);
}
void SceneObject::draw() const
// drawModel();
model->drawModel(shader, texture, modelMat);
- if (Events::isKToggleActive(SDLK_F6))
- model->drawBBox(modelMat);
+ if (Events::isKToggleActive(SDLK_F6)&&collision!=nullptr)
+ collision->drawBBox(modelMat);
}
Shader* shader;
Texture* texture;
Model* model;
+ Model* collision;
bool newModel;
Scene* mainScene;
<ClCompile Include="Graphix\Model\IMetaMesh.cpp" />\r
<ClCompile Include="Graphix\Model\Model.cpp" />\r
<ClCompile Include="Graphix\Model\SkyBox.cpp" />\r
- <ClCompile Include="Overlap.cpp" />\r
<ClCompile Include="Scene\EventBox.cpp" />\r
<ClCompile Include="Scene\Level.cpp" />\r
<ClCompile Include="Scene\Marvin.cpp" />\r
<ClInclude Include="Graphix\Model\IMetaMesh.h" />\r
<ClInclude Include="Graphix\Model\Model.h" />\r
<ClInclude Include="Graphix\Model\SkyBox.h" />\r
- <ClInclude Include="Overlap.h" />\r
<ClInclude Include="Scene.h" />\r
<ClInclude Include="Scene\EventBox.h" />\r
<ClInclude Include="Scene\Level.h" />\r
<ClCompile Include="Graphix\Model\SkyBox.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
- <ClCompile Include="Overlap.cpp">\r
- <Filter>Source Files</Filter>\r
- </ClCompile>\r
<ClCompile Include="GLM.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
<ClInclude Include="Graphix\Model\SkyBox.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
- <ClInclude Include="Overlap.h">\r
- <Filter>Header Files</Filter>\r
- </ClInclude>\r
<ClInclude Include="GLM.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r