modelobject
This commit is contained in:
parent
35bc9783ea
commit
4db04f28c7
|
@ -0,0 +1,61 @@
|
||||||
|
#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();
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef __MODEL_H
|
||||||
|
#define __MODEL_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include "../punkt2d.h"
|
||||||
|
#include "../punkt3d.h"
|
||||||
|
#include "../gltexture.h"
|
||||||
|
// #include "load3ds.h"
|
||||||
|
|
||||||
|
class ModelObject {
|
||||||
|
friend class Load3ds;
|
||||||
|
private:
|
||||||
|
std::vector<Punkt3D> normal;
|
||||||
|
std::vector<Punkt3D> vertex;
|
||||||
|
std::vector<Punkt2D> mapcoord;
|
||||||
|
std::vector<Punkt3D> polygon;
|
||||||
|
void calcNormales();
|
||||||
|
std::string name;
|
||||||
|
public:
|
||||||
|
ModelObject();
|
||||||
|
|
||||||
|
void render();
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class Model {
|
||||||
|
private:
|
||||||
|
std::vector<ModelObject> objects;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
Model();
|
||||||
|
void addObject(ModelObject c);
|
||||||
|
void clear();
|
||||||
|
void render();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue