From 35bc9783eaa7444d3984991bd9815ea0f94a380e Mon Sep 17 00:00:00 2001 From: seba Date: Fri, 11 Apr 2008 15:57:56 +0200 Subject: [PATCH] erweiterungen, modelklasse --- models/Makefile | 2 +- models/load3ds.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++--- models/load3ds.h | 3 ++- punkt2d.cpp | 4 ++++ punkt2d.h | 1 + punkt3d.cpp | 2 +- 6 files changed, 59 insertions(+), 6 deletions(-) diff --git a/models/Makefile b/models/Makefile index ab29da5..1fdac2f 100755 --- a/models/Makefile +++ b/models/Makefile @@ -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 diff --git a/models/load3ds.cpp b/models/load3ds.cpp index ef89724..2da72db 100644 --- a/models/load3ds.cpp +++ b/models/load3ds.cpp @@ -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; iaddObject(modobj); + modobj.clear(); + } + mfile.close(); return true; diff --git a/models/load3ds.h b/models/load3ds.h index edb5338..4dd5b90 100644 --- a/models/load3ds.h +++ b/models/load3ds.h @@ -5,6 +5,7 @@ #include #include #include +#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(); }; diff --git a/punkt2d.cpp b/punkt2d.cpp index 760d310..5fb98b8 100644 --- a/punkt2d.cpp +++ b/punkt2d.cpp @@ -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(); // } diff --git a/punkt2d.h b/punkt2d.h index 71778af..40e0abc 100644 --- a/punkt2d.h +++ b/punkt2d.h @@ -44,6 +44,7 @@ class Punkt2D { }; +void glTexCoord2f(Punkt2D); // float abs(Punkt3D); #endif diff --git a/punkt3d.cpp b/punkt3d.cpp index 1c2b8a8..0cd98e9 100644 --- a/punkt3d.cpp +++ b/punkt3d.cpp @@ -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); }