summaryrefslogtreecommitdiffstats
path: root/src/graphics/common
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-15 19:17:49 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-15 19:17:49 +0200
commit54f4da87923465a5387e2e854b58616647deb7af (patch)
treefc52b1866b29393be7d61a2341f04d430c078fdd /src/graphics/common
parenteca6d26459200d2956d64ccf8a2713d96a82c989 (diff)
downloadcolobot-54f4da87923465a5387e2e854b58616647deb7af.tar.gz
colobot-54f4da87923465a5387e2e854b58616647deb7af.tar.bz2
colobot-54f4da87923465a5387e2e854b58616647deb7af.zip
Fix in model loading; simple model viewer
- fixed model loading code - added simple model viewer (model_test) in src/graphics/opengl/test - added system time stamp code - split the code in app/system modules to separate headers - added debug messages in model loading - minor fixes in OpenGL engine
Diffstat (limited to 'src/graphics/common')
-rw-r--r--src/graphics/common/color.h21
-rw-r--r--src/graphics/common/modelfile.cpp38
-rw-r--r--src/graphics/common/modelfile.h4
-rw-r--r--src/graphics/common/vertex.h34
4 files changed, 90 insertions, 7 deletions
diff --git a/src/graphics/common/color.h b/src/graphics/common/color.h
index 3b19cf2..68421c7 100644
--- a/src/graphics/common/color.h
+++ b/src/graphics/common/color.h
@@ -19,6 +19,9 @@
#pragma once
+#include <sstream>
+
+
namespace Gfx {
/**
@@ -38,6 +41,15 @@ struct Color
{
return (float*)this;
}
+
+ //! Returns a string (r, g, b, a)
+ inline std::string ToString() const
+ {
+ std::stringstream s;
+ s.precision(3);
+ s << "(" << r << ", " << g << ", " << b << ", " << a << ")";
+ return s.str();
+ }
};
/**
@@ -49,6 +61,15 @@ struct ColorHSV
ColorHSV(float aH = 0.0f, float aS = 0.0f, float aV = 0.0f)
: h(aH), s(aS), v(aV) {}
+
+ //! Returns a string "(h, s, v)"
+ inline std::string ToString() const
+ {
+ std::stringstream s;
+ s.precision(3);
+ s << "(" << h << ", " << s << ", " << v << ")";
+ return s.str();
+ }
};
//! Converts a RGB color to HSV color
diff --git a/src/graphics/common/modelfile.cpp b/src/graphics/common/modelfile.cpp
index 8e509fe..22801e8 100644
--- a/src/graphics/common/modelfile.cpp
+++ b/src/graphics/common/modelfile.cpp
@@ -21,6 +21,7 @@
#include "common/iman.h"
#include "common/ioutils.h"
+#include "common/logger.h"
#include "common/stringutils.h"
#include "math/geometry.h"
@@ -205,8 +206,6 @@ Gfx::Material ReadBinaryMaterial(std::istream &stream)
/* power = */ IOUtils::ReadBinaryFloat(stream);
- /* padding? */ IOUtils::ReadBinary<2, unsigned int>(stream);
-
return result;
}
@@ -233,8 +232,6 @@ void WriteBinaryMaterial(Gfx::Material material, std::ostream &stream)
/* emissive.a */ IOUtils::WriteBinaryFloat(0.0f, stream);
/* power */ IOUtils::WriteBinaryFloat(0.0f, stream);
-
- /* padding? */ IOUtils::WriteBinary<2, unsigned int>(0, stream);
}
Gfx::ModelTriangle::ModelTriangle()
@@ -390,6 +387,8 @@ bool Gfx::CModelFile::ReadModel(std::istream &stream, bool edit, bool meta)
t.used = IOUtils::ReadBinary<1, char>(stream);
t.selected = IOUtils::ReadBinary<1, char>(stream);
+ /* padding */ IOUtils::ReadBinary<2, unsigned int>(stream);
+
t.p1 = ReadBinaryVertexTex2(stream);
t.p2 = ReadBinaryVertexTex2(stream);
t.p3 = ReadBinaryVertexTex2(stream);
@@ -422,16 +421,38 @@ bool Gfx::CModelFile::ReadModel(std::istream &stream, bool edit, bool meta)
triangle.min = t.min;
triangle.max = t.max;
triangle.state = t.state;
- sprintf(tex2Name, "dirty%.2d.tga", t.texNum2); // hardcoded as in the original code
+
+ if (t.texNum2 != 0)
+ sprintf(tex2Name, "dirty%.2d.tga", t.texNum2); // hardcoded as in the original code
+
triangle.tex2Name = std::string(tex2Name);
m_triangles.push_back(triangle);
- }
+ }
}
for (int i = 0; i < (int) m_triangles.size(); ++i)
+ {
m_triangles[i].tex1Name = StrUtils::Replace(m_triangles[i].tex1Name, "bmp", "tga");
+ GetLogger()->Info("ModelTriangle %d\n", i+1);
+ std::string s1 = m_triangles[i].p1.ToString();
+ GetLogger()->Info(" p1: %s\n", s1.c_str());
+ std::string s2 = m_triangles[i].p2.ToString();
+ GetLogger()->Info(" p2: %s\n", s2.c_str());
+ std::string s3 = m_triangles[i].p3.ToString();
+ GetLogger()->Info(" p3: %s\n", s3.c_str());
+
+ std::string d = m_triangles[i].material.diffuse.ToString();
+ std::string a = m_triangles[i].material.ambient.ToString();
+ std::string s = m_triangles[i].material.specular.ToString();
+ GetLogger()->Info(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str());
+
+ GetLogger()->Info(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].tex2Name.c_str());
+ GetLogger()->Info(" min: %.2f max: %.2f\n", m_triangles[i].min, m_triangles[i].max);
+ GetLogger()->Info(" state: %ld\n", m_triangles[i].state);
+ }
+
/*
if (! edit)
{
@@ -769,6 +790,11 @@ void Gfx::CModelFile::Mirror()
}
}
+std::vector<Gfx::ModelTriangle>& Gfx::CModelFile::GetTriangles()
+{
+ return m_triangles;
+}
+
int Gfx::CModelFile::GetTriangleCount()
{
return m_triangles.size();
diff --git a/src/graphics/common/modelfile.h b/src/graphics/common/modelfile.h
index 625df50..f8cb022 100644
--- a/src/graphics/common/modelfile.h
+++ b/src/graphics/common/modelfile.h
@@ -91,6 +91,8 @@ public:
//! Returns the number of triangles in model
int GetTriangleCount();
+ //! Returns the triangle vector
+ std::vector<Gfx::ModelTriangle>& GetTriangles();
//! Returns the height of model -- closest point to X and Z coords of \a pos
float GetHeight(Math::Vector pos);
@@ -106,7 +108,7 @@ protected:
protected:
CInstanceManager* m_iMan;
- CEngine* m_engine;
+ Gfx::CEngine* m_engine;
//! Last error
std::string m_error;
diff --git a/src/graphics/common/vertex.h b/src/graphics/common/vertex.h
index c6375b9..0a74587 100644
--- a/src/graphics/common/vertex.h
+++ b/src/graphics/common/vertex.h
@@ -23,6 +23,8 @@
#include "math/vector.h"
#include "math/point.h"
+#include <sstream>
+
namespace Gfx {
/**
@@ -46,6 +48,17 @@ struct Vertex
Math::Vector aNormal = Math::Vector(),
Math::Point aTexCoord = Math::Point())
: coord(aCoord), normal(aNormal), texCoord(aTexCoord) {}
+
+
+ //! Returns a string "(c: [...], n: [...], tc: [...])"
+ inline std::string ToString() const
+ {
+ std::stringstream s;
+ s.precision(3);
+ s << "(c: " << coord.ToString() << ", n: " << normal.ToString()
+ << ", tc: " << texCoord.ToString() << ")";
+ return s.str();
+ }
};
/**
@@ -72,6 +85,16 @@ struct VertexCol
Gfx::Color aSpecular = Gfx::Color(),
Math::Point aTexCoord = Math::Point())
: coord(aCoord), color(aColor), specular(aSpecular), texCoord(aTexCoord) {}
+
+ //! Returns a string "(c: [...], col: [...], sp: [...], tc: [...])"
+ inline std::string ToString() const
+ {
+ std::stringstream s;
+ s.precision(3);
+ s << "(c: " << coord.ToString() << ", col: " << color.ToString() << ", sp: "
+ << specular.ToString() << ", tc: " << texCoord.ToString() << ")";
+ return s.str();
+ }
};
@@ -95,6 +118,7 @@ struct VertexTex2
Math::Point aTexCoord2 = Math::Point())
: coord(aCoord), normal(aNormal), texCoord(aTexCoord), texCoord2(aTexCoord2) {}
+ //! Sets the fields from Gfx::Vertex with texCoord2 = (0,0)
void FromVertex(const Gfx::Vertex &v)
{
coord = v.coord;
@@ -102,6 +126,16 @@ struct VertexTex2
texCoord = v.texCoord;
texCoord2 = Math::Point();
}
+
+ //! Returns a string "(c: [...], n: [...], tc: [...], tc2: [...])"
+ inline std::string ToString() const
+ {
+ std::stringstream s;
+ s.precision(3);
+ s << "(c: " << coord.ToString() << ", n: " << normal.ToString()
+ << ", tc: " << texCoord.ToString() << ", tc2: " << texCoord2.ToString() << ")";
+ return s.str();
+ }
};
}; // namespace Gfx