anfang entwicklung modelloader

This commit is contained in:
seba 2008-04-10 00:59:47 +02:00
parent f0fb315b19
commit 744763dd4d
3 changed files with 94 additions and 0 deletions

13
models/Makefile Executable file
View File

@ -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)

48
models/load3ds.cpp Normal file
View File

@ -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;
}

33
models/load3ds.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef __LOAD3DS_H
#define __LOAD3DS_H
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
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