159 lines
2.7 KiB
C++
159 lines
2.7 KiB
C++
#include "model.h"
|
|
|
|
// Class Meshpoint
|
|
|
|
Meshpoint::Meshpoint() {
|
|
|
|
}
|
|
|
|
Meshpoint::Meshpoint(Punkt3D v, Punkt2D vt) {
|
|
set(v, vt);
|
|
}
|
|
|
|
void Meshpoint::set(Punkt3D v, Punkt2D vt) {
|
|
vertex = v;
|
|
texcoord = vt;
|
|
// normal = n;
|
|
}
|
|
|
|
void Meshpoint::use() {
|
|
glTexCoordP2D(texcoord);
|
|
// glNormalP3D(normal);
|
|
glVertexP3D(vertex);
|
|
}
|
|
|
|
// Class Material
|
|
|
|
Material::Material() {
|
|
name = "none";
|
|
ambient.set(1.0f, 1.0f, 1.0f);
|
|
diffuse.set(1.0f, 1.0f, 1.0f);
|
|
specular.set(1.0f, 1.0f, 1.0f);
|
|
}
|
|
|
|
Material::Material(std::string _name, GLColor _a, GLColor _d, GLColor _s) {
|
|
set(_name, _a, _d, _s);
|
|
}
|
|
|
|
void Material::set(std::string _name, GLColor _a, GLColor _d, GLColor _s) {
|
|
name = _name;
|
|
ambient = _a;
|
|
diffuse = _d;
|
|
specular = _s;
|
|
}
|
|
|
|
void Material::use() {
|
|
glColorGLC(diffuse);
|
|
}
|
|
|
|
// Polygonpoint
|
|
Polygonpoint::Polygonpoint() {
|
|
point = 0;
|
|
tex = 0;
|
|
normal = 0;
|
|
}
|
|
|
|
void Polygonpoint::use() {
|
|
if(normal)
|
|
glNormalP3D(*normal);
|
|
if(tex)
|
|
glTexCoordP2D(*tex);
|
|
if(point)
|
|
glVertexP3D(*point);
|
|
}
|
|
|
|
// Class Meshpolygon
|
|
|
|
Meshpolygon::Meshpolygon() {
|
|
a = b = c = 0;
|
|
}
|
|
|
|
Meshpolygon::Meshpolygon(Meshpoint *_a, Meshpoint *_b, Meshpoint *_c) {
|
|
set(_a, _b, _c);
|
|
}
|
|
|
|
void Meshpolygon::set(Meshpoint *_a, Meshpoint *_b, Meshpoint *_c) {
|
|
a = _a;
|
|
b = _b;
|
|
c = _c;
|
|
}
|
|
|
|
void Meshpolygon::render(GLenum mode) {
|
|
// if(!a || !b || !c)
|
|
// return;
|
|
|
|
glBegin(mode);
|
|
m1.use();
|
|
m2.use();
|
|
m3.use();
|
|
glEnd();
|
|
// std::cout << "Pos 1 " << *m1.point << std::endl;
|
|
// std::cout << "Pos 2 " << *m2.point << std::endl;
|
|
// std::cout << "Pos 3 " << *m3.point << std::endl;
|
|
}
|
|
// Class Model
|
|
|
|
Model::Model() {
|
|
meshdata = 0;
|
|
meshdataanz = 0;
|
|
matdata = 0;
|
|
matdataanz = 0;
|
|
polydata = 0;
|
|
polydataanz = 0;
|
|
texdata = 0;
|
|
texdataanz = 0;
|
|
normdata = 0;
|
|
normdataanz = 0;
|
|
loaded = false;
|
|
|
|
backupmat.diffuse.set(1.0f, 1.0f, 1.0f);
|
|
}
|
|
|
|
bool Model::isLoaded() {
|
|
return loaded;
|
|
}
|
|
|
|
void Model::unload() {
|
|
if(meshdata)
|
|
delete[](meshdata);
|
|
if(polydata)
|
|
delete[](polydata);
|
|
if(matdata)
|
|
delete[](matdata);
|
|
if(texdata)
|
|
delete[](texdata);
|
|
if(normdata)
|
|
delete[](normdata);
|
|
meshdataanz = polydataanz = matdataanz = texdataanz = normdataanz = 0;
|
|
meshdata = 0;
|
|
polydata = 0;
|
|
matdata = 0;
|
|
texdata = 0;
|
|
normdata = 0;
|
|
loaded = false;
|
|
}
|
|
|
|
void Model::render() {
|
|
if(!loaded) {
|
|
// std::cout << "Model not loaded" << std::endl;
|
|
return;
|
|
}
|
|
glPushMatrix();
|
|
// std::cout << " --- begin --- " << std::endl;
|
|
for(unsigned int i=0; i<polydataanz; i++) {
|
|
// glColor3f((float)i/polydataanz, 0.0f, 1.0f);
|
|
polydata[i].render(GL_LINE_LOOP);
|
|
}
|
|
glPopMatrix();
|
|
// std::cout << " --- end --- " << std::endl;
|
|
}
|
|
|
|
Model::~Model() {
|
|
unload();
|
|
}
|
|
|
|
const Punkt3D* Model::getMeshData(unsigned int *meshanz) {
|
|
*meshanz = meshdataanz;
|
|
return (const Punkt3D*)meshdata;
|
|
}
|