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++ CC = g++
OBJOPT = -c `sdl-config --cflags` -Wall OBJOPT = -c `sdl-config --cflags` -Wall
OBJECTS = load3ds.o OBJECTS = load3ds.o model.o
glguilib: $(OBJECTS) glguilib: $(OBJECTS)
# rm glgui.a -f # rm glgui.a -f

View File

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

View File

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

View File

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

View File

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

View File

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