From 15d41f4c1e0ae38e7327d2b8e67f2bbef1f9c2d3 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Sat, 16 May 2015 17:43:04 +0200 Subject: [PATCH] BBMeshTrees are drawable now (but be carefull with deepLVL) --- Weave/Graphix/Model/IMesh.cpp | 50 +++++++++++++++++++++++++++++++ Weave/Graphix/Model/IMesh.h | 6 ++++ Weave/Graphix/Model/IMetaMesh.cpp | 14 +++++---- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp index 5ea54e6..83dc7f2 100644 --- a/Weave/Graphix/Model/IMesh.cpp +++ b/Weave/Graphix/Model/IMesh.cpp @@ -22,6 +22,9 @@ typedef IMesh::Node Node; // Vergleiche Unterbaum //#define COMPARE_MTREE +//draw BBox of MTREE deep LVL -1 means all lvl's +#define BBOX_MTREE 7 + // Vergleiche auch Triangles #define COMPARE_FACE // Fordere mindestens prozentuelles gleichgewicht .1 = 10% @@ -90,6 +93,38 @@ void IMesh::useModelMat(const mat4& _model, Shader* _shader) const glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model* modelMat)); } + +void drawSubBBox(const mat4& _modelMat, const vec4& _color, Node* _node, int _lvl) +{ + vec3 BBsiz, BBpos; + _node->getBBcs(BBpos, BBsiz); + Graphix::getGlError(); + Graphix::shader_BBox->useShader(); + int tmp = Graphix::shader_BBox->getUniformLocation("uFragmentColor"); + if (tmp >= 0) + glUniform4fv(tmp, 1, value_ptr(_color)); + Graphix::getGlError(); + Model::getBBoxModel()->drawModel(Graphix::shader_BBox, NULL, _modelMat*translate(BBpos)*glm::scale(BBsiz*2.f)); + + if (_lvl == 0) + return; + if (_node->getLNode() != nullptr) + drawSubBBox(_modelMat, _color*.9f, _node->getLNode(), _lvl - 1); + if (_node->getUNode() != nullptr) + drawSubBBox(_modelMat, _color*.9f, _node->getUNode(), _lvl - 1); + + +} + +void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const +{ +#if !defined(COMPARE_MTREE) || !defined(BBOX_MTREE) + Model::drawBBox(_modelMat, _color); +#else + drawSubBBox(_modelMat, _color, root, BBOX_MTREE); +#endif +} + //void IMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const //{ // @@ -322,3 +357,18 @@ vec3 Node::getMean() const return mean; } +Node* Node::getLNode() const +{ + return lNode; +} + +Node* Node::getUNode() const +{ + return uNode; +} + +Model::Triangle* Node::getElement() const +{ + return element; +} + diff --git a/Weave/Graphix/Model/IMesh.h b/Weave/Graphix/Model/IMesh.h index 4a3c6e1..bc29c51 100644 --- a/Weave/Graphix/Model/IMesh.h +++ b/Weave/Graphix/Model/IMesh.h @@ -26,6 +26,8 @@ public: //void bindShader(Shader* shader); + void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override; + Overlap checkColS2O(const mat4& mMat, const Model* model, const mat4& modelMat) const override; Overlap checkColO2SBox(const mat4& mMat, const vec3& pos, const vec3& size, const mat4& modelMat) const override; Overlap checkColO2STriangle(const mat4& mMat, const vec3& pos, const mat3& directions) const override; @@ -52,6 +54,10 @@ public: /* get mean*/ vec3 getMean() const; + Node* getLNode() const; + Node* getUNode() const; + Model::Triangle* getElement() const; + private: vec3 center; vec3 size; diff --git a/Weave/Graphix/Model/IMetaMesh.cpp b/Weave/Graphix/Model/IMetaMesh.cpp index 7e7f14b..5388319 100644 --- a/Weave/Graphix/Model/IMetaMesh.cpp +++ b/Weave/Graphix/Model/IMetaMesh.cpp @@ -90,15 +90,19 @@ void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _model void IMetaMesh::drawBBox(const mat4& _modelMat,const vec4& _color) const { - Model::drawBBox(_modelMat, _color); - if (models.size() > 1) + if (models.size() == 1) + models.front()->drawBBox(_modelMat, _color); + else { - for (auto i = models.begin(); i != models.end(); ++i) + Model::drawBBox(_modelMat, _color); + if (models.size() > 1) { - (*i)->drawBBox(_modelMat, _color*0.8f); + for (auto i = models.begin(); i != models.end(); ++i) + { + (*i)->drawBBox(_modelMat, _color*0.8f); + } } } - } Overlap IMetaMesh::checkColS2O(const mat4& _mMat, const Model* _model, const mat4& _modelMat) const -- 2.47.3