Doc hinzugefuegt, alte modelfiles weggemacht

This commit is contained in:
Sebastian 2008-08-13 02:49:52 +02:00
parent 45c8964c49
commit 393f1c9a65
7 changed files with 1417 additions and 456 deletions

1417
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

0
doc/.gitignore vendored Normal file
View File

View File

@ -1,13 +0,0 @@
CC = g++
OBJOPT = -c `sdl-config --cflags` -Wall
OBJECTS = load3ds.o model.o
glguilib: $(OBJECTS)
# rm glgui.a -f
ar crus glmenu.a $(OBJECTS)
%.o: %.cpp %.h
$(CC) $(OBJOPT) $<
clean:
rm -f $(OBJECTS)

View File

@ -1,228 +0,0 @@
#include "load3ds.h"
#include "../punkt3d.h"
Load3ds::Load3ds(std::string _fname, bool _parse) {
filename = _fname;
parsed = false;
error = false;
// if(_parse)
// parse();
}
bool Load3ds::parse(Model *m) {
if(parsed)
unload();
std::ifstream mfile(filename.c_str(), std::ios::binary);
if(!mfile) {
return false;
}
unsigned short ident;
unsigned int len;
bool modelloaded = false;
bool materialloaded = false;
Material mat;
ModelObject modobj;
m->clear();
while(!mfile.eof()) {
ident = len = 0;
mfile.read((char *)&ident, 2);
mfile.read((char *)&len, 4);
std::cout << "Chunk: 0x" << std::hex << ident << " (" << std::dec << len << ")" << std::endl;
switch(ident) {
case 0x4d4d:
// Main Chunk
break;
case 0x3d3d:
// 3D Editor Chunk
break;
case 0x4000:
{
if(modelloaded) {
modobj.calcNormales();
m->addObject(modobj);
modobj.clear();
}
modelloaded = true;
// std::cout << "namechunk" << std::endl;
std::string name;
char c;
do {
mfile.read(&c, 1);
name += c;
} while(c!=0);
std::cout << "Name: " << name << std::endl;
modobj.name = name;
}
break;
case 0x4100:
break;
case 0x4110:{
unsigned short panz;
Punkt3D p;
mfile.read((char*)&panz, 2);
// std::cout << "\t\t\tVertexanz: " << panz << std::endl;
glBegin(GL_LINE_LOOP);
for(unsigned int i=0; i<panz; i++) {
mfile.read((char*)&p.x, sizeof(float));
mfile.read((char*)&p.y, sizeof(float));
mfile.read((char*)&p.z, sizeof(float));
// p.print("Punkt");
modobj.vertex.push_back(p);
glVertex3f(p);
}
glEnd();
}
break;
case 0x4120:
{
unsigned short panz, tp;
Punkt3D p;
mfile.read((char*)&panz, 2);
// std::cout << "\t\t\tPolygonanz: " << panz << std::endl;
for(unsigned int i=0; i<panz; i++) {
mfile.read((char*)&tp, 2);
p.x = tp;
mfile.read((char*)&tp, 2);
p.y = tp;
mfile.read((char*)&tp, 2);
p.z = tp;
mfile.read((char*)&tp, 2);
tp; // flags
// p.print("Polygon");
modobj.polygon.push_back(p);
}
}
break;
// Komischer Chunk, ein haufen Zahlen sind sich selber zugewiesen
case 0x4130:
{
std::string name;
char c;
do {
mfile.read(&c, 1);
name += c;
} while(c!=0);
modobj.mat = m->findMaterial(name);
std::cout << "Mat Name: " << name << std::endl;
unsigned short panz, tp;
mfile.read((char*)&panz, 2);
mfile.ignore(panz*2);
// for(unsigned int i=0; i<panz; i++) {
// mfile.read((char*)&tp, 2);
// std::cout << i << " ==> " << tp << std::endl;
// }
}
break;
case 0x4140:
{
unsigned short panz;
Punkt2D p;
mfile.read((char*)&panz, 2);
// std::cout << "\t\t\tUV-Anz: " << panz << std::endl;
for(unsigned int i=0; i<panz; i++) {
mfile.read((char*)&p.x, sizeof(float));
mfile.read((char*)&p.y, sizeof(float));
modobj.mapcoord.push_back(p);
}
}
break;
case 0xafff:
// Materialchunk
break;
case 0xa000:
{
if(materialloaded) {
m->addMaterial(mat);
mat.clear();
}
materialloaded = true;
std::string name;
char c;
do {
mfile.read(&c, 1);
name += c;
} while(c!=0);
mat.name = name;
std::cout << "Mat Name: " << name << std::endl;
}
break;
case 0xa010:
{
GLColor col;
col = readColorChunk(&mfile);
mat.ambient = col;
std::cout << col.r << ", " << col.g << ", " << col.b << std::endl;
}
break;
case 0xa020:
{
GLColor col;
col = readColorChunk(&mfile);
mat.diffuse = col;
std::cout << col.r << ", " << col.g << ", " << col.b << std::endl;
}
break;
case 0xa030:
{
GLColor col;
col = readColorChunk(&mfile);
mat.specular = col;
std::cout << col.r << ", " << col.g << ", " << col.b << std::endl;
}
break;
default:
//Switch Chunk
// std::cout << "einfach ignorieren..." << std::endl;
mfile.ignore(len-6);
// std::cout << "moep" << std::endl;
break;
}
}
if(materialloaded)
m->addMaterial(mat);
if(modelloaded) {
modobj.calcNormales();
// modobj.mat = m->findMaterial(modobj.getName());
m->addObject(modobj);
}
std::cout << "Ende Load" << std::endl;
mfile.close();
return true;
}
GLColor Load3ds::readColorChunk(std::ifstream *file) {
GLColor col;
unsigned short id, tp;
unsigned int clen;
file->read((char*)&id, 2); // Color, warscheinlich nur bytes, wenn nich implementiere funktion
file->read((char*)&clen, 4); // len, gleiches wie oben
switch(id) {
case 0x11:
file->read((char*)&tp, 1);
col.r = tp/255.0f;
file->read((char*)&tp, 1);
col.g = tp/255.0f;
file->read((char*)&tp, 1);
col.b = tp/255.0f;
break;
default:
file->ignore(clen-6);
break;
}
return col;
}
void Load3ds::unload() {
parsed = false;
error = false;
}

View File

@ -1,37 +0,0 @@
#ifndef __LOAD3DS_H
#define __LOAD3DS_H
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "model.h"
#include "../glcolor.h"
class Chunk {
private:
short ident;
char m;
char n;
public:
Chunk() { };
void parse();
};
class Load3ds {
private:
std::string filename;
bool parsed;
bool error;
GLColor readColorChunk(std::ifstream *file);
public:
Load3ds(std::string _fname, bool parse=true);
bool parse(Model *m);
void unload();
};
#endif

View File

@ -1,112 +0,0 @@
#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_TRIANGLES);
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();
}

View File

@ -1,66 +0,0 @@
#ifndef __MODEL_H
#define __MODEL_H
#include <iostream>
#include <vector>
#include "../punkt2d.h"
#include "../punkt3d.h"
#include "../gltexture.h"
#include "../glcolor.h"
// #include "load3ds.h"
class Material {
friend class Load3ds;
friend class ModelObject;
private:
std::string name;
GLColor ambient;
GLColor diffuse;
GLColor specular;
float percent;
public:
Material();
void clear();
std::string getName();
};
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;
Material mat;
public:
ModelObject();
std::string getName();
void render();
void clear();
};
class Model {
private:
std::vector<ModelObject> objects;
std::vector<Material> materials;
public:
Model();
void addObject(ModelObject c);
void addMaterial(Material m);
void clear();
void render();
Material findMaterial(std::string name);
};
#endif