2008-04-11 16:43:46 +02:00
|
|
|
#include "model.h"
|
|
|
|
|
|
|
|
ModelObject::ModelObject() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelObject::clear() {
|
|
|
|
normal.clear();
|
|
|
|
vertex.clear();
|
|
|
|
mapcoord.clear();
|
|
|
|
polygon.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelObject::calcNormales() {
|
|
|
|
normal.clear();
|
2008-04-13 03:17:27 +02:00
|
|
|
Punkt3D a, b, c;
|
2008-04-11 16:43:46 +02:00
|
|
|
for(unsigned int i=0; i<polygon.size(); i++) {
|
|
|
|
a = vertex.at((unsigned short)polygon[i].x) - vertex.at((unsigned short)polygon[i].z);
|
|
|
|
b = vertex.at((unsigned short)polygon[i].y) - vertex.at((unsigned short)polygon[i].z);
|
2008-04-13 03:17:27 +02:00
|
|
|
c = a.kreuzprodukt(b);
|
|
|
|
c.normalize();
|
|
|
|
normal.push_back(c);
|
|
|
|
// c.print("Normale");
|
2008-04-11 16:43:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelObject::render() {
|
2008-04-13 03:17:27 +02:00
|
|
|
// std::cout << "render " << name << " mit " << polygon.size()<< std::endl;
|
|
|
|
// std::cout << "Vertex: " << vertex.size() << std::endl;
|
2008-04-11 16:43:46 +02:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for(unsigned int i=0; i<polygon.size(); i++) {
|
2008-04-13 03:17:27 +02:00
|
|
|
// std::cout << "whee nr " <<i << std::endl;
|
|
|
|
// polygon[i].print();
|
|
|
|
// std::cout << "Stat: " << polygon.size() << " " << vertex.size() << " " << mapcoord.size() << " " << normal.size() << std::endl;
|
|
|
|
// glNormal3f(normal.at( (unsigned short)polygon[i].x));
|
|
|
|
// glColor3f(mat.diffuse.r, mat.diffuse.g, mat.diffuse.b);
|
|
|
|
glColorGLC(mat.ambient);
|
|
|
|
// std::cout << mat.ambient.r << ", " << mat.ambient.g << ", " << mat.ambient.b << std::endl;
|
|
|
|
|
|
|
|
glNormal3f(normal.at(i));
|
|
|
|
|
|
|
|
glTexCoord2f(mapcoord.at((unsigned short)polygon[i].x));
|
2008-04-11 16:43:46 +02:00
|
|
|
glVertex3f(vertex.at( (unsigned short)polygon[i].x));
|
|
|
|
|
2008-04-13 03:17:27 +02:00
|
|
|
|
|
|
|
glTexCoord2f(mapcoord.at((unsigned short)polygon[i].y));
|
2008-04-11 16:43:46 +02:00
|
|
|
glVertex3f(vertex.at( (unsigned short)polygon[i].y));
|
|
|
|
|
2008-04-13 03:17:27 +02:00
|
|
|
|
|
|
|
glTexCoord2f(mapcoord.at((unsigned short)polygon[i].z));
|
2008-04-11 16:43:46 +02:00
|
|
|
glVertex3f(vertex.at( (unsigned short)polygon[i].z));
|
2008-04-13 03:17:27 +02:00
|
|
|
// vertex.at( (unsigned short)polygon[i].x).print();
|
2008-04-11 16:43:46 +02:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2008-04-13 03:17:27 +02:00
|
|
|
std::string ModelObject::getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Material::Material() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Material::clear() {
|
|
|
|
name = "";
|
|
|
|
|
|
|
|
ambient.set(0.0f, 0.0f, 0.0f);
|
|
|
|
diffuse.set(0.0f, 0.0f, 0.0f);
|
|
|
|
specular.set(0.0f, 0.0f, 0.0f);
|
|
|
|
percent = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Material::getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-11 16:43:46 +02:00
|
|
|
Model::Model() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Model::clear() {
|
|
|
|
objects.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Model::addObject(ModelObject c) {
|
|
|
|
objects.push_back(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Model::render() {
|
2008-04-13 03:17:27 +02:00
|
|
|
// std::cout << "Render Model " << objects.size() << std::endl;
|
2008-04-11 16:43:46 +02:00
|
|
|
for(unsigned int i=0; i<objects.size(); i++)
|
|
|
|
objects[i].render();
|
|
|
|
}
|
2008-04-13 03:17:27 +02:00
|
|
|
|
|
|
|
void Model::addMaterial(Material m) {
|
|
|
|
materials.push_back(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
Material Model::findMaterial(std::string name) {
|
|
|
|
for(unsigned int i=0; i<materials.size(); i++) {
|
|
|
|
if(name==materials[i].getName()) {
|
|
|
|
std::cout<<"found!"<<std::endl;
|
|
|
|
return materials[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Material();
|
|
|
|
}
|