113 lines
2.3 KiB
C++
113 lines
2.3 KiB
C++
#include "model.h"
|
|
|
|
ModelObject::ModelObject() {
|
|
|
|
}
|
|
|
|
void ModelObject::clear() {
|
|
normal.clear();
|
|
vertex.clear();
|
|
mapcoord.clear();
|
|
polygon.clear();
|
|
}
|
|
|
|
void ModelObject::calcNormales() {
|
|
normal.clear();
|
|
Punkt3D a, b, c;
|
|
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);
|
|
c = a.kreuzprodukt(b);
|
|
c.normalize();
|
|
normal.push_back(c);
|
|
// c.print("Normale");
|
|
}
|
|
|
|
}
|
|
|
|
void ModelObject::render() {
|
|
// std::cout << "render " << name << " mit " << polygon.size()<< std::endl;
|
|
// std::cout << "Vertex: " << vertex.size() << std::endl;
|
|
|
|
// if(mat.name[0]=='g') {
|
|
// std::cout << "Render NOT: " << name << std::endl;
|
|
// return;
|
|
// }
|
|
// mat.diffuse.print(mat.name);
|
|
glBegin(GL_LINES);
|
|
for(unsigned int i=0; i<polygon.size(); i++) {
|
|
|
|
glColorGLC(mat.diffuse);
|
|
|
|
|
|
glNormal3f(normal.at(i));
|
|
|
|
glTexCoord2f(mapcoord.at((unsigned short)polygon[i].x));
|
|
glVertex3f(vertex.at( (unsigned short)polygon[i].x));
|
|
|
|
|
|
glTexCoord2f(mapcoord.at((unsigned short)polygon[i].y));
|
|
glVertex3f(vertex.at( (unsigned short)polygon[i].y));
|
|
|
|
|
|
glTexCoord2f(mapcoord.at((unsigned short)polygon[i].z));
|
|
glVertex3f(vertex.at( (unsigned short)polygon[i].z));
|
|
// vertex.at( (unsigned short)polygon[i].x).print();
|
|
}
|
|
glEnd();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
Model::Model() {
|
|
|
|
}
|
|
|
|
void Model::clear() {
|
|
objects.clear();
|
|
}
|
|
|
|
void Model::addObject(ModelObject c) {
|
|
objects.push_back(c);
|
|
}
|
|
|
|
void Model::render() {
|
|
// std::cout << "Render Model " << objects.size() << std::endl;
|
|
for(unsigned int i=0; i<objects.size(); i++)
|
|
objects[i].render();
|
|
}
|
|
|
|
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();
|
|
}
|