clray
annotate 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 |
rev | line source |
---|---|
nuclear@6 | 1 #ifndef MESH_H_ |
nuclear@6 | 2 #define MESH_H_ |
nuclear@6 | 3 |
nuclear@23 | 4 #include <stdio.h> |
nuclear@6 | 5 #include <vector> |
nuclear@24 | 6 #include <list> |
nuclear@6 | 7 |
nuclear@6 | 8 struct Vertex { |
nuclear@9 | 9 float pos[4]; |
nuclear@9 | 10 float normal[4]; |
nuclear@12 | 11 float tex[4]; |
nuclear@12 | 12 float padding[4]; |
nuclear@6 | 13 }; |
nuclear@6 | 14 |
nuclear@6 | 15 struct Face { |
nuclear@6 | 16 Vertex v[3]; |
nuclear@9 | 17 float normal[4]; |
nuclear@6 | 18 int matid; |
nuclear@12 | 19 int padding[3]; |
John@15 | 20 |
John@15 | 21 bool operator ==(const Face &f) const; |
nuclear@6 | 22 }; |
nuclear@6 | 23 |
nuclear@6 | 24 struct Material { |
nuclear@9 | 25 float kd[4], ks[4]; |
nuclear@6 | 26 float kr, kt; |
nuclear@6 | 27 float spow; |
nuclear@12 | 28 float padding; |
nuclear@6 | 29 }; |
nuclear@6 | 30 |
nuclear@6 | 31 struct Mesh { |
nuclear@6 | 32 std::vector<Face> faces; |
nuclear@6 | 33 int matid; |
nuclear@6 | 34 }; |
nuclear@6 | 35 |
nuclear@23 | 36 enum { |
nuclear@22 | 37 KDAXIS_X, |
nuclear@22 | 38 KDAXIS_Y, |
nuclear@22 | 39 KDAXIS_Z |
nuclear@22 | 40 }; |
nuclear@22 | 41 |
nuclear@22 | 42 #define KDCLEAR(node) ((node)->axis = -1) |
nuclear@22 | 43 #define KDUSED(node) ((node)->axis >= 0) |
nuclear@22 | 44 #define KDPARENT(x) ((x) >> 1) |
nuclear@22 | 45 #define KDLEFT(x) ((x) << 1) |
nuclear@22 | 46 #define KDRIGHT(x) (((x) << 1) + 1) |
nuclear@22 | 47 |
nuclear@22 | 48 struct KDNode { |
nuclear@22 | 49 int axis; |
nuclear@22 | 50 float pt; |
nuclear@24 | 51 |
nuclear@24 | 52 KDNode *left, *right; |
nuclear@24 | 53 std::list<Face*> faces; |
nuclear@23 | 54 }; |
nuclear@22 | 55 |
nuclear@24 | 56 struct KDNodeGPU { |
nuclear@24 | 57 int axis; |
nuclear@24 | 58 float pt; |
nuclear@24 | 59 }; |
nuclear@24 | 60 |
nuclear@24 | 61 |
nuclear@6 | 62 class Scene { |
nuclear@24 | 63 private: |
nuclear@24 | 64 mutable Face *facebuf; |
nuclear@24 | 65 mutable int num_faces; |
nuclear@24 | 66 |
nuclear@6 | 67 public: |
nuclear@6 | 68 std::vector<Mesh*> meshes; |
nuclear@6 | 69 std::vector<Material> matlib; |
nuclear@24 | 70 |
nuclear@24 | 71 KDNode *kdtree; |
nuclear@24 | 72 std::vector<KDNode> kdtree_gpu; |
nuclear@24 | 73 |
nuclear@24 | 74 Scene(); |
nuclear@24 | 75 ~Scene(); |
nuclear@6 | 76 |
nuclear@13 | 77 bool add_mesh(Mesh *m); |
John@14 | 78 int get_num_meshes() const; |
John@14 | 79 int get_num_materials() const; |
John@14 | 80 int get_num_faces() const; |
nuclear@13 | 81 |
John@14 | 82 Material *get_materials(); |
John@14 | 83 const Material *get_materials() const; |
nuclear@13 | 84 |
nuclear@6 | 85 bool load(const char *fname); |
nuclear@6 | 86 bool load(FILE *fp); |
nuclear@22 | 87 |
nuclear@24 | 88 const Face *get_face_buffer() const; |
nuclear@23 | 89 void build_kdtree(); |
nuclear@6 | 90 }; |
nuclear@6 | 91 |
nuclear@6 | 92 #endif /* MESH_H_ */ |