clray

view src/scene.h @ 24:13091c00d7ca

- moved create_face_buffer to Scene::get_face_buffer and did a few reorganizations. - starting work on the kdtree creation
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Aug 2010 03:02:52 +0100
parents 51f115e337c2
children 58642a8316b7
line source
1 #ifndef MESH_H_
2 #define MESH_H_
4 #include <stdio.h>
5 #include <vector>
6 #include <list>
8 struct Vertex {
9 float pos[4];
10 float normal[4];
11 float tex[4];
12 float padding[4];
13 };
15 struct Face {
16 Vertex v[3];
17 float normal[4];
18 int matid;
19 int padding[3];
21 bool operator ==(const Face &f) const;
22 };
24 struct Material {
25 float kd[4], ks[4];
26 float kr, kt;
27 float spow;
28 float padding;
29 };
31 struct Mesh {
32 std::vector<Face> faces;
33 int matid;
34 };
36 enum {
37 KDAXIS_X,
38 KDAXIS_Y,
39 KDAXIS_Z
40 };
42 #define KDCLEAR(node) ((node)->axis = -1)
43 #define KDUSED(node) ((node)->axis >= 0)
44 #define KDPARENT(x) ((x) >> 1)
45 #define KDLEFT(x) ((x) << 1)
46 #define KDRIGHT(x) (((x) << 1) + 1)
48 struct KDNode {
49 int axis;
50 float pt;
52 KDNode *left, *right;
53 std::list<Face*> faces;
54 };
56 struct KDNodeGPU {
57 int axis;
58 float pt;
59 };
62 class Scene {
63 private:
64 mutable Face *facebuf;
65 mutable int num_faces;
67 public:
68 std::vector<Mesh*> meshes;
69 std::vector<Material> matlib;
71 KDNode *kdtree;
72 std::vector<KDNode> kdtree_gpu;
74 Scene();
75 ~Scene();
77 bool add_mesh(Mesh *m);
78 int get_num_meshes() const;
79 int get_num_materials() const;
80 int get_num_faces() const;
82 Material *get_materials();
83 const Material *get_materials() const;
85 bool load(const char *fname);
86 bool load(FILE *fp);
88 const Face *get_face_buffer() const;
89 void build_kdtree();
90 };
92 #endif /* MESH_H_ */