From 744763dd4d2a5daf9143646306a174956d430d10 Mon Sep 17 00:00:00 2001 From: seba Date: Thu, 10 Apr 2008 00:59:47 +0200 Subject: [PATCH] anfang entwicklung modelloader --- models/Makefile | 13 +++++++++++++ models/load3ds.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ models/load3ds.h | 33 +++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100755 models/Makefile create mode 100644 models/load3ds.cpp create mode 100644 models/load3ds.h diff --git a/models/Makefile b/models/Makefile new file mode 100755 index 0000000..ab29da5 --- /dev/null +++ b/models/Makefile @@ -0,0 +1,13 @@ +CC = g++ +OBJOPT = -c `sdl-config --cflags` -Wall +OBJECTS = load3ds.o + +glguilib: $(OBJECTS) +# rm glgui.a -f + ar crus glmenu.a $(OBJECTS) + +%.o: %.cpp %.h + $(CC) $(OBJOPT) $< + +clean: + rm -f $(OBJECTS) diff --git a/models/load3ds.cpp b/models/load3ds.cpp new file mode 100644 index 0000000..986439b --- /dev/null +++ b/models/load3ds.cpp @@ -0,0 +1,48 @@ +#include "load3ds.h" + +Load3ds::Load3ds(std::string _fname, bool _parse) { + filename = _fname; + parsed = false; + error = false; + + if(_parse) + parse(); +} + + +bool Load3ds::parse() { + if(parsed) + unload(); + std::ifstream mfile(filename.c_str(), std::ios::binary); + + if(!mfile) { + return false; + } + + unsigned short ident; + unsigned char m, n; + + while(!mfile.eof()) { + ident = m = n = 0; + mfile.read((char *)&ident, 2); + mfile.read((char *)&m, 1); + mfile.read((char *)&n, 1); + std::cout << "Chunk: " << ident << " (" << (int)m << ", " << (int)n << ")" << std::endl; + switch(ident) { + case 0x4d4d: + std::cout << "yeah!" << std::endl; + break; + default: + //Switch Chunk + mfile.ignore(m+n); + break; + } + } + + return true; +} + +void Load3ds::unload() { + parsed = false; + error = false; +} diff --git a/models/load3ds.h b/models/load3ds.h new file mode 100644 index 0000000..edb5338 --- /dev/null +++ b/models/load3ds.h @@ -0,0 +1,33 @@ +#ifndef __LOAD3DS_H +#define __LOAD3DS_H + +#include +#include +#include +#include + +class Chunk { + private: + short ident; + char m; + char n; + + public: + Chunk() { }; + void parse(); +}; + +class Load3ds { + private: + std::string filename; + + bool parsed; + bool error; + public: + Load3ds(std::string _fname, bool parse=true); + + bool parse(); + void unload(); +}; + +#endif