clray

view src/scene.h @ 54:6a30f27fa1e6

separated the OpenGL visualization and added a CPU raytracing mode
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 10 Sep 2010 16:47:00 +0100
parents 8047637961a2
children 8c858e1a89e8
line source
1 #ifndef MESH_H_
2 #define MESH_H_
4 #include <stdio.h>
5 #include <vector>
6 #include <list>
7 #include "common.h"
9 struct Vertex {
10 float pos[4];
11 float normal[4];
12 float tex[4];
13 float padding[4];
14 };
16 struct Face {
17 Vertex v[3];
18 float normal[4];
19 int matid;
20 int padding[3];
22 bool operator ==(const Face &f) const;
23 };
25 struct Material {
26 float kd[4], ks[4];
27 float kr, kt;
28 float spow;
29 float padding;
30 };
32 struct Mesh {
33 std::vector<Face> faces;
34 int matid;
35 };
37 struct Light {
38 float pos[4], color[4];
39 };
41 class AABBox {
42 public:
43 float min[4], max[4];
45 float calc_surface_area() const;
46 };
48 struct KDNode {
49 int axis;
50 AABBox aabb;
51 float cost;
53 KDNode *left, *right;
54 std::vector<int> face_idx;
56 KDNode();
57 };
59 struct KDNodeGPU {
60 AABBox aabb;
61 int face_idx[MAX_NODE_FACES];
62 int num_faces;
63 int left, right;
64 int padding;
65 };
68 class Scene {
69 private:
70 mutable Face *facebuf;
71 mutable int num_faces;
73 mutable KDNodeGPU *kdbuf;
75 public:
76 std::vector<Mesh*> meshes;
77 std::vector<Light> lights;
78 std::vector<Material> matlib;
79 KDNode *kdtree;
81 Scene();
82 ~Scene();
84 bool add_mesh(Mesh *m);
85 bool add_light(const Light &lt);
87 int get_num_meshes() const;
88 int get_num_lights() const;
89 int get_num_faces() const;
90 int get_num_materials() const;
91 int get_num_kdnodes() const;
93 Mesh **get_meshes();
94 const Mesh * const *get_meshes() const;
96 Light *get_lights();
97 const Light *get_lights() const;
99 Material *get_materials();
100 const Material *get_materials() const;
102 bool load(const char *fname);
103 bool load(FILE *fp);
105 const Face *get_face_buffer() const;
106 const KDNodeGPU *get_kdtree_buffer() const;
108 void draw_kdtree() const;
109 bool build_kdtree();
110 };
112 enum {
113 ACCEL_PARAM_MAX_TREE_DEPTH,
114 ACCEL_PARAM_MAX_NODE_ITEMS,
115 ACCEL_PARAM_COST_TRAVERSE,
116 ACCEL_PARAM_COST_INTERSECT,
118 NUM_ACCEL_PARAMS
119 };
121 void set_accel_param(int p, int v);
123 int kdtree_depth(const KDNode *tree);
124 int kdtree_nodes(const KDNode *tree);
126 bool kdtree_dump(const KDNode *tree, const char *fname);
127 KDNode *kdtree_restore(const char *fname);
129 #endif /* MESH_H_ */