clray

view src/scene.h @ 25:58642a8316b7

continuing with the kdtree
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Aug 2010 07:00:04 +0100
parents 13091c00d7ca
children c740ae431d51
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 class AABBox {
37 public:
38 float min[4], max[4];
40 float calc_surface_area() const;
41 };
43 enum {
44 KDAXIS_X,
45 KDAXIS_Y,
46 KDAXIS_Z
47 };
49 #define KDCLEAR(node) ((node)->axis = -1)
50 #define KDUSED(node) ((node)->axis >= 0)
51 #define KDPARENT(x) ((x) >> 1)
52 #define KDLEFT(x) ((x) << 1)
53 #define KDRIGHT(x) (((x) << 1) + 1)
55 struct KDNode {
56 int axis;
57 float pt;
58 AABBox aabb;
60 KDNode *left, *right;
61 std::list<const Face*> faces;
62 };
64 struct KDNodeGPU {
65 int axis;
66 float pt;
67 };
70 class Scene {
71 private:
72 mutable Face *facebuf;
73 mutable int num_faces;
75 public:
76 std::vector<Mesh*> meshes;
77 std::vector<Material> matlib;
79 KDNode *kdtree;
80 std::vector<KDNode> kdtree_gpu;
82 Scene();
83 ~Scene();
85 bool add_mesh(Mesh *m);
86 int get_num_meshes() const;
87 int get_num_materials() const;
88 int get_num_faces() const;
90 Material *get_materials();
91 const Material *get_materials() const;
93 bool load(const char *fname);
94 bool load(FILE *fp);
96 const Face *get_face_buffer() const;
97 void build_kdtree();
98 };
100 #endif /* MESH_H_ */