clray

view src/scene.h @ 23:51f115e337c2

separated obj loading and vector class
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 13 Aug 2010 18:20:45 +0100
parents 6c44e4b1726d
children 13091c00d7ca
line source
1 #ifndef MESH_H_
2 #define MESH_H_
4 #include <stdio.h>
5 #include <vector>
7 struct Vertex {
8 float pos[4];
9 float normal[4];
10 float tex[4];
11 float padding[4];
12 };
14 struct Face {
15 Vertex v[3];
16 float normal[4];
17 int matid;
18 int padding[3];
20 bool operator ==(const Face &f) const;
21 };
23 struct Material {
24 float kd[4], ks[4];
25 float kr, kt;
26 float spow;
27 float padding;
28 };
30 struct Mesh {
31 std::vector<Face> faces;
32 int matid;
33 };
35 enum {
36 KDAXIS_X,
37 KDAXIS_Y,
38 KDAXIS_Z
39 };
41 #define KDCLEAR(node) ((node)->axis = -1)
42 #define KDUSED(node) ((node)->axis >= 0)
43 #define KDPARENT(x) ((x) >> 1)
44 #define KDLEFT(x) ((x) << 1)
45 #define KDRIGHT(x) (((x) << 1) + 1)
47 struct KDNode {
48 int axis;
49 float pt;
50 };
52 class Scene {
53 public:
54 std::vector<Mesh*> meshes;
55 std::vector<Material> matlib;
56 std::vector<KDNode> kdtree;
58 bool add_mesh(Mesh *m);
59 int get_num_meshes() const;
60 int get_num_materials() const;
61 int get_num_faces() const;
63 Material *get_materials();
64 const Material *get_materials() const;
66 bool load(const char *fname);
67 bool load(FILE *fp);
69 void build_kdtree();
70 };
72 #endif /* MESH_H_ */