erweiterungen, modelklasse

This commit is contained in:
seba 2008-04-11 15:57:56 +02:00
parent 956ce66c63
commit 35bc9783ea
6 changed files with 59 additions and 6 deletions

View File

@ -1,6 +1,6 @@
CC = g++
OBJOPT = -c `sdl-config --cflags` -Wall
OBJECTS = load3ds.o
OBJECTS = load3ds.o model.o
glguilib: $(OBJECTS)
# rm glgui.a -f

View File

@ -6,12 +6,12 @@ Load3ds::Load3ds(std::string _fname, bool _parse) {
parsed = false;
error = false;
if(_parse)
parse();
// if(_parse)
// parse();
}
bool Load3ds::parse() {
bool Load3ds::parse(Model *m) {
if(parsed)
unload();
std::ifstream mfile(filename.c_str(), std::ios::binary);
@ -22,6 +22,9 @@ bool Load3ds::parse() {
unsigned short ident;
unsigned int len;
bool modelloaded = false;
ModelObject modobj;
m->clear();
std::cout << "size: " << sizeof(int) << std::endl;
while(!mfile.eof()) {
ident = len = 0;
@ -41,6 +44,12 @@ bool Load3ds::parse() {
break;
case 0x4000:
{
if(modelloaded) {
modobj.calcNormales();
m->addObject(modobj);
modobj.clear();
}
modelloaded = true;
std::cout << "namechunk" << std::endl;
std::string name;
char c;
@ -49,6 +58,7 @@ bool Load3ds::parse() {
name += c;
} while(c!=0);
std::cout << "Name: " << name << std::endl;
modobj.name = name;
}
break;
case 0x4100:
@ -63,11 +73,41 @@ bool Load3ds::parse() {
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);
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;
p.print("Polygon");
modobj.polygon.push_back(p);
}
}
break;
case 0x4140:
{
unsigned short panz;
Punkt2D p;
mfile.read((char*)&panz, 2);
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;
default:
//Switch Chunk
std::cout << "einfach ignorieren..." << std::endl;
@ -75,6 +115,13 @@ bool Load3ds::parse() {
break;
}
}
if(modelloaded) {
modobj.calcNormales();
m->addObject(modobj);
modobj.clear();
}
mfile.close();
return true;

View File

@ -5,6 +5,7 @@
#include <fstream>
#include <string>
#include <vector>
#include "model.h"
class Chunk {
private:
@ -26,7 +27,7 @@ class Load3ds {
public:
Load3ds(std::string _fname, bool parse=true);
bool parse();
bool parse(Model *m);
void unload();
};

View File

@ -127,6 +127,10 @@ Punkt2D operator/(const float& _m, const Punkt2D& b) {
return Punkt2D(b.x/_m, b.y/_m);
}
void glTexCoord2f(Punkt2D p) {
glTexCoord2f(p.x, p.y);
}
// float abs(Punkt2D p) {
// return p.abs();
// }

View File

@ -44,6 +44,7 @@ class Punkt2D {
};
void glTexCoord2f(Punkt2D);
// float abs(Punkt3D);
#endif

View File

@ -198,7 +198,7 @@ void glTranslatef(Punkt3D p) {
glTranslatef(p.x, p.y, p.z);
}
void glNormal(Punkt3D p) {
void glNormal3f(Punkt3D p) {
glNormal3f(p.x, p.y, p.z);
}