libsegl/models/model.cpp

62 lines
1.5 KiB
C++
Raw Normal View History

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();
Punkt3D a, b;
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);
normal.push_back(a.kreuzprodukt(b));
}
}
void ModelObject::render() {
std::cout << "render " << name << std::endl;
glBegin(GL_TRIANGLES);
for(unsigned int i=0; i<polygon.size(); i++) {
// glNormal3f(normal.at( (unsigned short)polygon[i].x));
// glTexCoord2f(mapcoord.at((unsigned short)polygon[i].x));
glVertex3f(vertex.at( (unsigned short)polygon[i].x));
// glNormal3f(normal.at( (unsigned short)polygon[i].y));
// glTexCoord2f(mapcoord.at((unsigned short)polygon[i].y));
glVertex3f(vertex.at( (unsigned short)polygon[i].y));
// glNormal3f(normal.at( (unsigned short)polygon[i].z));
// 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();
}
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();
}