6 Commits

Author SHA1 Message Date
Youssef Assem bab419d197 start 2019-12-18 23:09:56 +02:00
Youssef Assem 733343b18b done
.dae integrated
2019-12-11 21:55:21 +02:00
Youssef Assem 154ed3f058 fixes 2019-12-10 13:54:56 +02:00
Youssef Assem ce94b6a916 try fixing .dae 2019-12-08 22:32:46 +02:00
mo7sen 32cd3c2037 Fixing dependency issues 2019-12-08 21:12:21 +02:00
Youssef Assem c0be7e1680 collada model
Start
2019-12-08 20:49:49 +02:00
18 changed files with 9221 additions and 20 deletions
+9
View File
@@ -0,0 +1,9 @@
#include "COLLADA.h"
COLLADA::COLLADA(const char* filename)
{
tinyxml2::XMLDocument doc;
doc.LoadFile(filename);
tinyxml2::XMLElement* xml = doc.FirstChildElement("COLLADA");
m_GeometryLibrary = GeometryLibrary(xml->FirstChildElement("library_geometries"));
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "GeometryLibrary.h"
class COLLADA
{
private:
GeometryLibrary m_GeometryLibrary;
//ImagesLibrary m_ImagesLibrary;
//EffectsLibrary m_EffectsLibrary;
//MaterialLibrary m_MaterialLibrary;
//ControllerLibrary m_ControllerLibrary;
//AnimationLibrary m_AnimationLibrary;
VisualSceneLibrary m_VisualSceneLibrary;
public:
COLLADA() = default;
COLLADA(const char* filename);
};
+178
View File
@@ -0,0 +1,178 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include "ColladaModel.h"
#define PI 3.14159265358979323846
#define DEG2RAD PI/180
ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normals_()
{
Transform = Matrix::identity();
Rotation = Matrix::identity();
Scale = Matrix::identity();
Translation = Matrix::identity();
tinyxml2::XMLDocument doc;
doc.LoadFile(filename);
///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////faces//////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
face_count = 0;
tinyxml2::XMLElement* xml_face = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("triangles");
xml_face->QueryIntAttribute("count", &face_count); //get count
std::stringstream str_triangle(xml_face->FirstChildElement("p")->GetText()); //get values as a string
for (int i = 0; i < face_count; i++)
{
faces_.push_back(std::vector<Vec3i>());
for (int j = 0; j < 3; j++)
{
Vec3i temp;
str_triangle >> temp.x;
str_triangle >> temp.y;
str_triangle >> temp.z;
faces_[i].push_back(temp);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////vertex/////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
vertex_count = 0;
tinyxml2::XMLElement* xml_vertex = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("source")->FirstChildElement("float_array");
xml_vertex->QueryIntAttribute("count", &vertex_count);
std::stringstream str_vertex(xml_vertex->GetText());
for (int i = 0; i < vertex_count / 3; i++)
{
Vec3f temp;
str_vertex >> temp.x;
str_vertex >> temp.y;
str_vertex >> temp.z;
vertices_.push_back(temp);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////normal////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
normal_count = 0;
tinyxml2::XMLElement* xml_normal = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("source")->NextSiblingElement()->FirstChildElement("float_array");
xml_normal->QueryIntAttribute("count", &normal_count);
std::stringstream str_normal(xml_normal->GetText());
for (int i = 0; i < normal_count / 3; i++)
{
Vec3f temp;
str_normal >> temp.x;
str_normal >> temp.y;
str_normal >> temp.z;
normals_.push_back(temp);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
texcoord_count = 0;
tinyxml2::XMLElement* xml_texture = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("source")->NextSiblingElement()->NextSiblingElement()->FirstChildElement("float_array");
xml_texture->QueryIntAttribute("count", &texcoord_count);
std::stringstream str_texcoord(xml_texture->GetText());
for (int i = 0; i < texcoord_count / 2; i++)
{
Vec2f temp;
str_texcoord >> temp.x;
str_texcoord >> temp.y;
textureco_.push_back(temp);
}
load_texture(filename, "_diffuse.tga", diffusemap_);
load_texture(filename, "_nm_tangent.tga", normalmap_);
}
ColladaModel::~ColladaModel() {
}
void ColladaModel::ApplyTransform() {
Transform = Translation * Scale * Rotation;
}
void ColladaModel::translate(Vec3f tr) {
Translation[0][3] += tr.x;
Translation[1][3] += tr.y;
Translation[2][3] += tr.z;
}
void ColladaModel::rotate(Vec3f rot) {
rot = rot * DEG2RAD;
Rotation[0][0] = cosf(rot.y) * cosf(rot.z);
Rotation[0][1] = -cosf(rot.y) * sinf(rot.z);
Rotation[0][2] = sinf(rot.y);
Rotation[1][0] = sinf(rot.x) * sinf(rot.y) * cosf(rot.z) + cosf(rot.x) * sinf(rot.z);
Rotation[1][1] = -sinf(rot.x) * sinf(rot.y) * sinf(rot.z) + cosf(rot.x) * cosf(rot.z);
Rotation[1][2] = -sinf(rot.x) * cosf(rot.y);
Rotation[2][0] = -cosf(rot.x) * sinf(rot.y) * cosf(rot.z) + sinf(rot.x) * sinf(rot.z);
Rotation[2][1] = cosf(rot.x) * sinf(rot.y) * sinf(rot.z) + sinf(rot.x) * cosf(rot.z);
Rotation[2][2] = cosf(rot.x) * cosf(rot.y);
}
void ColladaModel::scale(Vec3f scl) {
Scale[0][0] = scl.x;
Scale[1][1] = scl.y;
Scale[2][2] = scl.z;
}
int ColladaModel::nfaces() {
return face_count;
}
int ColladaModel::nvertices() {
return vertex_count;
}
std::vector<int> ColladaModel::face(int idx) {
std::vector<int> face;
for (int i = 0; i < (int)faces_[idx].size(); i++) face.push_back(faces_[idx][i][0]);
return face;
}
Vec3f ColladaModel::vertix(int i) {
return vertices_[i];
}
Vec3f ColladaModel::vertix(int iface, int nthvert) {
return vertices_[faces_[iface][nthvert][0]];
}
void ColladaModel::load_texture(std::string filename, const char* suffix, TGAImage& img) {
std::string texfile(filename);
size_t dot = texfile.find_last_of(".");
if (dot != std::string::npos) {
texfile = texfile.substr(0, dot) + std::string(suffix);
std::cerr << "texture file " << texfile << " loading " << (img.read_tga_file(texfile.c_str()) ? "ok" : "failed") << std::endl;
img.flip_vertically();
}
}
TGAColor ColladaModel::diffuse(Vec2f uvf) {
Vec2i uv(uvf[0] * diffusemap_.get_width(), uvf[1] * diffusemap_.get_height());
return diffusemap_.get(uv[0], uv[1]);
}
Vec3f ColladaModel::normal(Vec2f uvf) {
Vec2i uv(uvf[0] * normalmap_.get_width(), uvf[1] * normalmap_.get_height());
TGAColor c = normalmap_.get(uv[0], uv[1]);
Vec3f res;
for (int i = 0; i < 3; i++)
res[2 - i] = (float)c[i] / 255.f * 2.f - 1.f;
return res;
}
Vec2f ColladaModel::uv(int iface, int nthvert) {
return textureco_[faces_[iface][nthvert][2]];
}
float ColladaModel::specular(Vec2f uvf) {
Vec2i uv(uvf[0] * specularmap_.get_width(), uvf[1] * specularmap_.get_height());
return specularmap_.get(uv[0], uv[1])[0] / 1.f;
}
Vec3f ColladaModel::normal(int iface, int nthvert) {
int idx = faces_[iface][nthvert][1];
return normals_[idx].normalize();
}
+66
View File
@@ -0,0 +1,66 @@
#ifndef __MODEL_s__
#define __MODEL_s__
#pragma once
#include "ColladaModel.h"
#include "tinyxml2.h"
#include "geometry.h"
#include "tgaimage.h"
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
class ColladaModel {
private:
int face_count;
int vertex_count;
int normal_count;
int texcoord_count;
std::vector<std::vector<Vec3i> > faces_; //vertex/normal/uv
std::vector<Vec3f> vertices_;
std::vector<Vec3f> normals_;
std::vector<Vec2f> textureco_;
TGAImage diffusemap_;
TGAImage normalmap_;
TGAImage specularmap_;
void load_texture(std::string filename, const char* suffix, TGAImage& img);
public:
ColladaModel(const char* filename);
~ColladaModel();
int nfaces();
int nvertices();
Vec3f vertix(int iface, int nthvert);
Vec3f vertix(int i);
Vec3f normal(int iface, int nthvert);
Vec3f normal(Vec2f uv);
Vec2f uv(int iface, int nthvert);
Matrix Transform;
Matrix Rotation;
Matrix Scale;
Matrix Translation;
void translate(Vec3f tr);
void rotate(Vec3f rot);
void scale(Vec3f scl);
void ApplyTransform();
TGAColor diffuse(Vec2f uv);
float specular(Vec2f uv);
std::vector<int> face(int idx);
};
#endif
+9
View File
@@ -0,0 +1,9 @@
#include "GeometryLibrary.h"
GeometryLibrary::GeometryLibrary(tinyxml2::XMLElement* xml)
{
auto xm = xml;
auto g = Geometry(xml->FirstChildElement("geometry"));
m_Geometries.push_back(g);
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include <vector>
#include "geometry.h"
class GeometryLibrary
{
std::vector<Geometry> m_Geometries;
public:
GeometryLibrary() = default;
GeometryLibrary(tinyxml2::XMLElement * xml);
};
class VisualSceneLibrary
{
Visualscene m_visual_scene;
public:
VisualSceneLibrary() = default;
VisualSceneLibrary(tinyxml2::XMLElement* xml);
};
+15 -5
View File
@@ -22,32 +22,32 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{42971E68-F861-4D45-9DA6-F5E163705584}</ProjectGuid>
<RootNamespace>OpenWindow</RootNamespace>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
@@ -115,18 +115,28 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="COLLADA.cpp" />
<ClCompile Include="ColladaModel.cpp" />
<ClCompile Include="data.cpp" />
<ClCompile Include="geometry.cpp" />
<ClCompile Include="GeometryLibrary.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="model.cpp" />
<ClCompile Include="renderer.cpp" />
<ClCompile Include="tgaimage.cpp" />
<ClCompile Include="tinyxml2.cpp" />
<ClCompile Include="util_window.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="COLLADA.h" />
<ClInclude Include="ColladaModel.h" />
<ClInclude Include="data.h" />
<ClInclude Include="geometry.h" />
<ClInclude Include="GeometryLibrary.h" />
<ClInclude Include="model.h" />
<ClInclude Include="renderer.h" />
<ClInclude Include="tgaimage.h" />
<ClInclude Include="tinyxml2.h" />
<ClInclude Include="util_window.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+30
View File
@@ -33,6 +33,21 @@
<ClCompile Include="renderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ColladaModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="tinyxml2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="COLLADA.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GeometryLibrary.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="data.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="util_window.h">
@@ -50,5 +65,20 @@
<ClInclude Include="renderer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ColladaModel.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="tinyxml2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="COLLADA.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GeometryLibrary.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="data.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
File diff suppressed because one or more lines are too long
+187
View File
@@ -0,0 +1,187 @@
#include "data.h"
Float_Array::Float_Array(tinyxml2::XMLElement* xml)
{
xml->QueryIntAttribute("count", (int*)&m_Count);
const char* ch;
xml->QueryStringAttribute("count", &ch);
std::string s(ch);
m_ID = s;
std::stringstream str(xml->GetText());
m_Floats = new float[m_Count];
for (int i = 0; i < m_Count; i++)
{
str >> m_Floats[i];
}
float f = m_Floats[55358];
}
Name_Array::Name_Array(tinyxml2::XMLElement* xml)
{
xml->QueryIntAttribute("count", (int*)&m_Count);
const char* ch;
xml->QueryStringAttribute("count", &ch);
std::string s(ch);
m_ID = s;
std::stringstream str(xml->GetText());
for (int i = 0; i < m_Count; i++)
{
str >> m_Names[i];
}
}
Param::Param(tinyxml2::XMLElement* xml)
{
const char* ch;
xml->QueryStringAttribute("name", &ch);
std::string s(ch);
m_Name = s;
const char* ch1;
xml->QueryStringAttribute("type", &ch1);
std::string s1(ch1);
m_Type = s1;
}
Accessor::Accessor(tinyxml2::XMLElement* xml)
{
const char* ch;
xml->QueryStringAttribute("source", &ch);
std::string s(ch);
m_Source = s;
xml->QueryIntAttribute("count", (int*)&m_Count);
xml->QueryIntAttribute("stride", (int*)&m_Stride);
for (tinyxml2::XMLElement* child = xml->FirstChildElement("param"); child != NULL; child = child->NextSiblingElement("param"))
{
Param p(child);
m_Params.push_back(p);
}
}
Technique_Common::Technique_Common(tinyxml2::XMLElement* xml)
{
m_Accessor = Accessor(xml->FirstChildElement("accessor"));
}
Source::Source(tinyxml2::XMLElement* xml)
{
const char* ch;
xml->QueryStringAttribute("id", &ch);
std::string s(ch);
m_ID = s;
tinyxml2::XMLElement* fa = xml->FirstChildElement("float_array");
if (fa != NULL)
{
m_Float_Array = Float_Array(fa);
}
tinyxml2::XMLElement* na = xml->FirstChildElement("Name_array");
if (na != NULL)
{
m_Name_Array = Name_Array(na);
}
m_TechniqueCommon = Technique_Common(xml->FirstChildElement("technique_common"));
}
Input::Input(tinyxml2::XMLElement* xml)
{
const char* ch;
xml->QueryStringAttribute("semantic", &ch);
std::string s(ch);
m_Semantic = s;
const char* ch1;
xml->QueryStringAttribute("source", &ch1);
std::string s1(ch1);
m_Source = s1;
if (xml->FindAttribute("offset"))
{
const char* ch2;
xml->QueryStringAttribute("offset", &ch2);
std::string s2(ch2);
m_Offset = s2;
}
if (xml->FindAttribute("set"))
{
const char* ch3;
xml->QueryStringAttribute("set", &ch3);
std::string s3(ch3);
m_Set = s3;
}
}
Vertices::Vertices(tinyxml2::XMLElement* xml)
{
const char* ch;
xml->QueryStringAttribute("id", &ch);
std::string s(ch);
m_ID = s;
for (tinyxml2::XMLElement* child = xml->FirstChildElement("input"); child != NULL; child = child->NextSiblingElement("input"))
{
Input in(child);
m_Inputs.push_back(in);
}
}
P::P(tinyxml2::XMLElement* xml, unsigned int count)
{
m_Count = count;
std::stringstream str(xml->GetText());
m_Indices = new unsigned short[count * 9];
for (int i = 0; i < count * 9; i++)
{
str >> m_Indices[i];
}
}
Triangles::Triangles(tinyxml2::XMLElement* xml)
{
xml->QueryIntAttribute("count", (int*)&m_Count);
const char* ch;
xml->QueryStringAttribute("count", &ch);
std::string s(ch);
m_Material = s;
for (tinyxml2::XMLElement* child = xml->FirstChildElement("input"); child != NULL; child = child->NextSiblingElement("input"))
{
Input in(child);
m_Inputs.push_back(in);
}
tinyxml2::XMLElement* mp = xml->FirstChildElement("p");
if (mp != NULL)
{
m_P = P(mp, m_Count);
}
}
Mesh::Mesh(tinyxml2::XMLElement* xml)
{
for (tinyxml2::XMLElement* child = xml->FirstChildElement("source"); child != NULL; child = child->NextSiblingElement("source"))
{
Source sc(child);
m_Sources.push_back(sc);
}
m_Vertices = Vertices(xml->FirstChildElement("vertices"));
for (tinyxml2::XMLElement* child = xml->FirstChildElement("triangles"); child != NULL; child = child->NextSiblingElement("triangles"))
{
Triangles tr(child);
m_Triangles.push_back(tr);
}
}
+137
View File
@@ -0,0 +1,137 @@
#pragma once
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "tinyxml2.h"
//----------------------------------------------//
class Float_Array
{
unsigned int m_Count;
std::string m_ID;
float* m_Floats;
public:
Float_Array() = default;
Float_Array(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Name_Array
{
unsigned int m_Count;
std::string m_ID;
std::string* m_Names;
public:
Name_Array() = default;
Name_Array(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Param
{
std::string m_Name;
std::string m_Type;
public:
Param() = default;
Param(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Accessor
{
std::string m_Source;
unsigned int m_Count;
unsigned int m_Stride;
std::vector<Param> m_Params;
public:
Accessor () = default;
Accessor(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Technique_Common
{
Accessor m_Accessor;
public:
Technique_Common() = default;
Technique_Common(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Source
{
std::string m_ID;
Float_Array m_Float_Array;
Name_Array m_Name_Array;
Technique_Common m_TechniqueCommon;
public:
Source() = default;
Source(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Input
{
std::string m_Semantic;
std::string m_Source;
std::string m_Offset;
std::string m_Set;
public:
Input() = default;
Input(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Vertices
{
std::string m_ID;
std::vector<Input> m_Inputs;
public:
Vertices() = default;
Vertices(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class P
{
unsigned int m_Count;
unsigned short* m_Indices;
public:
P() = default;
P(tinyxml2::XMLElement* xml, unsigned int count);
};
//----------------------------------------------//
class Triangles
{
unsigned int m_Count;
std::string m_Material;
std::vector<Input> m_Inputs;
P m_P;
public:
Triangles() = default;
Triangles(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Mesh
{
std::vector<Source> m_Sources;
Vertices m_Vertices;
std::vector<Triangles> m_Triangles;
public:
Mesh() = default;
Mesh(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Node
{
std::string m_ID;
std::string m_name;
std::string m_type;
std::string m_sid;
public:
Node() = default;
Node(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
class Matrix
{
std::string m_sid;
public:
Node() = default;
Node(tinyxml2::XMLElement* xml);
};
//----------------------------------------------//
+4
View File
@@ -5,3 +5,7 @@ template <> template <> vec<3,float>::vec(const vec<3,int> &v) : x(v.x),y(v.y)
template <> template <> vec<2,int> ::vec(const vec<2,float> &v) : x(int(v.x+.5f)),y(int(v.y+.5f)) {}
template <> template <> vec<2,float>::vec(const vec<2,int> &v) : x(v.x),y(v.y) {}
Geometry::Geometry(tinyxml2::XMLElement* xml)
{
m_Mesh = Mesh(xml->FirstChildElement("mesh"));
}
+42
View File
@@ -4,6 +4,7 @@
#include <vector>
#include <cassert>
#include <iostream>
#include "data.h"
template<size_t DimCols,size_t DimRows,typename T> class mat;
@@ -233,5 +234,46 @@ typedef vec<3, float> Vec3f;
typedef vec<3, int> Vec3i;
typedef vec<4, float> Vec4f;
typedef mat<4,4,float> Matrix;
class Geometry
{
Mesh m_Mesh;
public:
Geometry() = default;
Geometry(tinyxml2::XMLElement * xml);
};
class Visualscene
{
node m_Mesh;
public:
Visualscene() = default;
Visualscene(tinyxml2::XMLElement* xml);
};
#endif //__GEOMETRY_H__
Binary file not shown.
+8 -15
View File
@@ -8,6 +8,8 @@
#include "renderer.h"
#include "util_window.h"
#include <ctime>
#include "ColladaModel.h"
#include "COLLADA.h"
const TGAColor white = TGAColor(255, 255, 255, 255);
const TGAColor red = TGAColor(255, 0, 0, 255);
@@ -86,7 +88,7 @@ Vec3f barycentric(Vec3f* pts, Vec3f P)
void triangle(
Vec3f* pts, // Needed
Model* model, // Should be removed
ColladaModel* model, // Should be removed
Vec2f* diff_pts, // Should be removed
float* intensities,
Vec3f camera_pos) // Not really sure yet
@@ -187,20 +189,14 @@ Matrix lookat(Vec3f eye, Vec3f center, Vec3f up) {
void render()
{
Model* model = new Model("african_head.obj");
COLLADA C("sssssssssssss.dae");
ColladaModel* model = new ColladaModel("african_head.dae");
Matrix ViewPort = viewport(screen_width / 8, screen_height / 8, screen_width * 3 / 4, screen_height * 3 / 4);
Matrix Projection = Matrix::identity();
Matrix ModelView = lookat(eye, center, Vec3f(0, 1, 0));
Projection[3][2] = -1.f / (eye - center).norm();
model->rotate(Vec3f(0, 0, 90));
model->scale(Vec3f(0.5, 0.5, 0.5));
model->translate(Vec3f(0.5, 0.5, -1));
model->ApplyTransform();
Matrix z = ViewPort * Projection * ModelView * model->Transform;
init_zbuffer();
@@ -214,10 +210,10 @@ void render()
for (int j = 0; j < 3; j++)
{
Vec3f v = model->vert(face[j]);
Vec3f v = model->vertix(face[j]);
Vec4f v4(v);
Vec3f coord(z * v4);
screen_coords[j] = coord;
world_coords[j] = v;
diffuse_coords[j] = model->uv(i, j);
@@ -226,7 +222,4 @@ void render()
triangle(screen_coords, model, diffuse_coords, intensities, Vec3f(0, 0, 5));
}
delete model;
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff