Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/render/model.cc61
1 files changed, 42 insertions, 19 deletions
diff --git a/src/render/model.cc b/src/render/model.cc
index 5019c7e..81d9ee9 100644
--- a/src/render/model.cc
+++ b/src/render/model.cc
@@ -20,7 +20,7 @@ namespace render
{
const float MAX_BOUNDS = 8192;
-const float delta = 10e-8;
+const float delta = 10e-10;
std::map<std::string, Model*> Model::registry;
@@ -47,7 +47,6 @@ Model::Model(std::string const & name) :
con_warn << "Could not stream " << fn << "!\n";
return;
}
- con_debug << "Reading " << fn << "\n";
// --------- the actual reading
using math::Vector3f;
@@ -161,11 +160,18 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
// check if the face is x-axis oriented
if ( (fabsf(face->normal().x) >= fabsf(face->normal().y) ) && (fabsf(face->normal().x) >= fabsf(face->normal().z)) ) {
//cout << " x oriented" << std::endl;
- vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, -MAX_BOUNDS));
- vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, MAX_BOUNDS));
- vl.push_back(new math::Vector3f(0, MAX_BOUNDS, MAX_BOUNDS));
- vl.push_back(new math::Vector3f(0, MAX_BOUNDS, -MAX_BOUNDS));
-
+
+ if (face->normal().x >= 0) {
+ vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, -MAX_BOUNDS));
+ vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, MAX_BOUNDS));
+ vl.push_back(new math::Vector3f(0, MAX_BOUNDS, MAX_BOUNDS));
+ vl.push_back(new math::Vector3f(0, MAX_BOUNDS, -MAX_BOUNDS));
+ } else {
+ vl.push_back(new math::Vector3f(0, MAX_BOUNDS, -MAX_BOUNDS));
+ vl.push_back(new math::Vector3f(0, MAX_BOUNDS, MAX_BOUNDS));
+ vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, MAX_BOUNDS));
+ vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, -MAX_BOUNDS));
+ }
// calculate the x coordinate of each face vertex
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
(*it)->x = ( -face->d() -
@@ -178,10 +184,18 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
// check if the face is y-axis oriented
else if ( (fabsf(face->normal().y) >= fabsf(face->normal().x) ) && (fabsf(face->normal().y) >= fabsf(face->normal().z)) ) {
//cout << " y oriented" << std::endl;
- vl.push_back(new Vector3f(-MAX_BOUNDS, 0, -MAX_BOUNDS));
- vl.push_back(new Vector3f(-MAX_BOUNDS, 0, MAX_BOUNDS));
- vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS));
- vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS));
+
+ if (face->normal().y >= 0) {
+ vl.push_back(new Vector3f(-MAX_BOUNDS, 0, -MAX_BOUNDS));
+ vl.push_back(new Vector3f(-MAX_BOUNDS, 0, MAX_BOUNDS));
+ vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS));
+ vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS));
+ } else {
+ vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS));
+ vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS));
+ vl.push_back(new Vector3f(-MAX_BOUNDS, 0, MAX_BOUNDS));
+ vl.push_back(new Vector3f(-MAX_BOUNDS, 0, -MAX_BOUNDS));
+ }
// calculate the x coordinate of each face vertex
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
@@ -195,10 +209,17 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
// face must be z-axis oriented
else {
//cout << " z oriented" << std::endl;
- vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0));
- vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0));
- vl.push_back(new Vector3f(MAX_BOUNDS, MAX_BOUNDS, 0));
- vl.push_back(new Vector3f(MAX_BOUNDS, -MAX_BOUNDS, 0));
+ if (face->normal().z >= 0) {
+ vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0));
+ vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0));
+ vl.push_back(new Vector3f(MAX_BOUNDS, MAX_BOUNDS, 0));
+ vl.push_back(new Vector3f(MAX_BOUNDS, -MAX_BOUNDS, 0));
+ } else {
+ vl.push_back(new Vector3f(MAX_BOUNDS, -MAX_BOUNDS, 0));
+ vl.push_back(new Vector3f(MAX_BOUNDS, MAX_BOUNDS, 0));
+ vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0));
+ vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0));
+ }
// calculate the x coordinate of each face vertex
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
@@ -221,7 +242,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
Vector3f pn = crossproduct(plane->point(1)-plane->point(0), plane->point(2)-plane->point(0));
Vector3f t = crossproduct(fn, pn);
- if (t.x == 0 && t.y ==0 && t.z == 0) {
+ if ((t.x == 0) && (t.y == 0) && (t.z == 0) ) {
continue;
}
@@ -252,7 +273,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
}
//cout << " vertex " << i << " prev " << prev << " v " << v << " next " << next << std::endl;
- if ((v.x*plane->normal().x + v.y*plane->normal().y + v.y*plane->normal().y + v.z*plane->normal().z +plane->d()) < -delta ) {
+ if ((v.x*plane->normal().x + v.y*plane->normal().y + v.z*plane->normal().z +plane->d()) < delta ) {
// find current
std::vector<Vector3f *>::iterator vit = vl.begin();
@@ -261,7 +282,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
}
// check if prev - v intersects with plane
- if ((prev.x*plane->normal().x + prev.y*plane->normal().y + prev.y*plane->normal().y + prev.z*plane->normal().z + plane->d()) > delta ) {
+ if ((prev.x*plane->normal().x + prev.y*plane->normal().y + prev.z*plane->normal().z + plane->d()) > -delta ) {
// calculate intersection
float t1 = -plane->normal().x * prev.x - plane->normal().y * prev.y - plane->normal().z * prev.z -plane->d();
@@ -285,7 +306,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
}
// check if next - v intersects with plane
- if ((next.x*plane->normal().x + next.y*plane->normal().y + next.y*plane->normal().y + next.z*plane->normal().z + plane->d()) > delta ) {
+ if ((next.x*plane->normal().x + next.y*plane->normal().y + next.z*plane->normal().z + plane->d()) > -delta ) {
// calculate intersection
// calculate intersection
@@ -329,6 +350,8 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
//con_debug << "adding face\n";
add_face(mf);
+ } else {
+ con_debug << "Unresolved face!\n";
}
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {