From 67a8baa3b2ebf5866836361a9bbbc1111e6ed6e2 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Tue, 16 Jun 2015 14:52:43 +0200 Subject: [PATCH] removed scaling fom Normals fixed not every point was loaded --- Weave/Graphix/Model/IMesh.cpp | 32 ++++++++++++++++---------------- Weave/Graphix/Model/Model.cpp | 6 +++--- Weave/Graphix/ViewPort.h | 2 ++ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp index 7c31d93..2058da7 100644 --- a/Weave/Graphix/Model/IMesh.cpp +++ b/Weave/Graphix/Model/IMesh.cpp @@ -55,27 +55,27 @@ IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale) : modelpath("IMesh") import(_mesh, numvertices, numfaces, vertex, uvs, normals, index, _scale); btConvexHullShape* tmp_shape = new btConvexHullShape(); + btTriangleMesh* tmp_mesh = new btTriangleMesh(); - for (uint i = 0; i < numvertices; i += 3) - tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2])); - - //tmp_shape->recalcLocalAabb(); - bt_collision_shape = tmp_shape; + for (uint i = 0; i < numfaces * 3; i += 3) + { + tmp_mesh->addTriangle( + btVector3(vertex[index[i]], vertex[index[i] + 1], vertex[index[i] + 2]), + btVector3(vertex[index[i + 1]], vertex[index[i + 1] + 1], vertex[index[i + 1] + 2]), + btVector3(vertex[index[i + 2]], vertex[index[i + 2] + 1], vertex[index[i + 2] + 2]), + false); - btVector3 minB,maxB; - btTransform t; - t.setIdentity(); + } - tmp_shape->getAabb(t, minB, maxB); + //Message::info(std::to_string(tmp_mesh->getNumTriangles())); - //minB = t(minB); - //maxB = t(maxB); - - vec3 min = (vec3)(vec4(minB.getX(), minB.getY(), minB.getZ(), 0.f)); - vec3 max = (vec3)(vec4(maxB.getX(), maxB.getY(), maxB.getZ(), 0.f)); + for (uint i = 0; i < numvertices*3; i += 3) + tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2])); - vec3 size = (max - min) * .5f; - vec3 center = (max + min) * .5f; + //tmp_shape->recalcLocalAabb(); + //bt_collision_shape = new btBvhTriangleMeshShape(tmp_mesh,true); + bt_collision_shape = new btConvexTriangleMeshShape(tmp_mesh,true); + //bt_collision_shape = tmp_shape; setBB(numvertices, vertex); diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index 7608e9c..e010a4a 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -428,9 +428,9 @@ bool Model::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float* //load normals from Mesh for (uint i = 0; i < numvertices; i++) { - normals[3 * i] = mesh->mNormals[i].x / _scale.x; - normals[3 * i + 1] = mesh->mNormals[i].y / _scale.y; - normals[3 * i + 2] = mesh->mNormals[i].z / _scale.z; + normals[3 * i] = mesh->mNormals[i].x;// / _scale.x; + normals[3 * i + 1] = mesh->mNormals[i].y;// / _scale.y; + normals[3 * i + 2] = mesh->mNormals[i].z;// / _scale.z; } return true; diff --git a/Weave/Graphix/ViewPort.h b/Weave/Graphix/ViewPort.h index a4c28f4..02c4a9a 100644 --- a/Weave/Graphix/ViewPort.h +++ b/Weave/Graphix/ViewPort.h @@ -13,6 +13,8 @@ public: void useViewPort() const; + void setView(unsigned int width, unsigned int height); + void bindView(Shader* shader) const; void bindView(Shader* shader, vec3 lookat) const; -- 2.47.3