Browse Source

anfang entwicklung modelloader

seba 12 years ago
parent
commit
744763dd4d
3 changed files with 94 additions and 0 deletions
  1. 13
    0
      models/Makefile
  2. 48
    0
      models/load3ds.cpp
  3. 33
    0
      models/load3ds.h

+ 13
- 0
models/Makefile View File

@@ -0,0 +1,13 @@
1
+CC = g++
2
+OBJOPT = -c `sdl-config --cflags` -Wall
3
+OBJECTS = load3ds.o
4
+
5
+glguilib: $(OBJECTS)
6
+# 	rm glgui.a -f
7
+	ar crus glmenu.a $(OBJECTS)
8
+
9
+%.o: %.cpp %.h
10
+	$(CC) $(OBJOPT) $<
11
+
12
+clean:
13
+	rm -f $(OBJECTS)

+ 48
- 0
models/load3ds.cpp View File

@@ -0,0 +1,48 @@
1
+#include "load3ds.h"
2
+
3
+Load3ds::Load3ds(std::string _fname, bool _parse) {
4
+	filename = _fname;
5
+	parsed = false;
6
+	error = false;
7
+	
8
+	if(_parse)
9
+		parse();
10
+}
11
+
12
+
13
+bool Load3ds::parse() {
14
+	if(parsed)
15
+		unload();
16
+	std::ifstream mfile(filename.c_str(), std::ios::binary);
17
+	
18
+	if(!mfile) {
19
+		return false;
20
+	}
21
+	
22
+	unsigned short ident;
23
+	unsigned char m, n;
24
+	
25
+	while(!mfile.eof()) {
26
+		ident = m = n = 0;
27
+		mfile.read((char *)&ident, 2);
28
+		mfile.read((char *)&m, 1);
29
+		mfile.read((char *)&n, 1);
30
+		std::cout << "Chunk: " << ident << " (" << (int)m << ", " << (int)n << ")" << std::endl;
31
+		switch(ident) {
32
+			case 0x4d4d:
33
+				std::cout << "yeah!" << std::endl;
34
+			break;
35
+			default:
36
+				//Switch Chunk
37
+				mfile.ignore(m+n);
38
+			break;
39
+		}
40
+	}
41
+
42
+	return true;
43
+}
44
+
45
+void Load3ds::unload() {
46
+	parsed = false;
47
+	error = false;
48
+}

+ 33
- 0
models/load3ds.h View File

@@ -0,0 +1,33 @@
1
+#ifndef __LOAD3DS_H
2
+#define __LOAD3DS_H
3
+
4
+#include <iostream>
5
+#include <fstream>
6
+#include <string>
7
+#include <vector>
8
+
9
+class Chunk {
10
+	private:
11
+		short ident;
12
+		char m;
13
+		char n;
14
+		
15
+	public:
16
+		Chunk() { };
17
+		void parse();
18
+};
19
+
20
+class Load3ds {
21
+	private:
22
+		std::string filename;
23
+		
24
+		bool parsed;
25
+		bool error;
26
+	public:
27
+		Load3ds(std::string _fname, bool parse=true);
28
+		
29
+		bool parse();
30
+		void unload();
31
+};
32
+
33
+#endif

Loading…
Cancel
Save