4 #include <cgmath/cgmath.h>
13 typedef int (*erb_intersect_func)(struct erb_surf *surf, struct erb_ray *ray, struct erb_hit *hit);
14 typedef void (*erb_hitgeom_func)(struct erb_surf *surf, struct erb_hit *hit);
15 typedef void (*erb_sample_func)(struct erb_surf *surf, cgm_vec3 *pos);
16 typedef void (*erb_bbox_func)(struct erb_surf *surf, struct erb_aabb *bb);
23 struct erb_node *par; /* parent node */
24 struct erb_node *clist; /* child nodes */
25 struct erb_surf *surflist; /* surfaces in this node */
26 float xform[16], inv_xform[16]; /* global transformation */
27 float node_xform[16], inv_node_xform[16]; /* local transformation */
31 struct erb_node *node; /* transformation node for this surface */
33 struct erb_aabb bbox; /* local space bounding box */
36 erb_intersect_func isect; /* intersection routine */
37 erb_hitgeom_func hitgeom; /* calculate derived values of the erb_hit structure */
38 erb_sample_func sample; /* random sample generation */
39 erb_bbox_func calc_bbox; /* bounds calculation */
41 long data[1]; /* type chosen to match worst case alignment req. */
45 cgm_vec3 o, d; /* origin and direction */
46 float tmin, tmax; /* segment bounds */
47 float ior; /* IOR of the medium through which this ray travels */
48 float total_dist; /* travel distance accumulator */
53 cgm_vec3 pos, lpos; /* global and local space hit positions */
54 struct erb_surf *surf;
57 /* derived by calc_hit */
62 struct erb_rend *erb_create(void);
63 void erb_destroy(struct erb_rend *erb);
65 int erb_allocframe(struct erb_rend *erb, int width, int height);
66 float *erb_getframe(struct erb_rend *erb);
68 /* clears the framebuffer and sample counters to begin rendering a new frame */
69 void erb_begin(struct erb_rend *erb);
70 /* finalizes the frame, averaging samples (optional) */
71 float *erb_end(struct erb_rend *erb);
73 /* transformation nodes */
74 struct erb_node *erb_node(void);
75 void erb_free_node(struct erb_node *n);
76 int erb_node_addchild(struct erb_node *n, struct erb_node *c);
77 int erb_node_rmchild(struct erb_node *n, struct erb_node *c);
78 int erb_node_addsurf(struct erb_node *n, struct erb_surf *s);
79 int erb_node_rmsurf(struct erb_node *n, struct erb_surf *s);
81 /* sets the transformation matrix and also calculates the inverse */
82 void erb_node_setxform(struct erb_node *n, float *mat);
85 struct erb_surf *erb_surface(int datasz);
86 void erb_free_surface(struct erb_surf *surf);
87 struct erb_surf *erb_surf_sphere(float rad);
88 struct erb_surf *erb_surf_box(float xsz, float ysz, float zsz);
90 /* utility functions */
91 void erb_xform_ray(struct erb_ray *inray, float *mat, cgm_vec3 *org, cgm_vec3 *dir);
93 #endif /* RENDLIB_H_ */