working on the transformation node system
[erebus2020] / liberebus / src / erebus.h
index a2566d8..758e4d3 100644 (file)
@@ -10,19 +10,48 @@ struct erb_ray;
 struct erb_hit;
 struct erb_aabb;
 
+struct erb_rect {
+       int x, y, w, h;
+};
+
 typedef int (*erb_intersect_func)(struct erb_surf *surf, struct erb_ray *ray, struct erb_hit *hit);
 typedef void (*erb_hitgeom_func)(struct erb_surf *surf, struct erb_hit *hit);
 typedef void (*erb_sample_func)(struct erb_surf *surf, cgm_vec3 *pos);
 typedef void (*erb_bbox_func)(struct erb_surf *surf, struct erb_aabb *bb);
 
+/* job (block/frame) completion callback type */
+typedef void (*erb_done_func)(unsigned int job, struct erb_rect *rect, void *cls);
+
 struct erb_aabb {
        cgm_vec3 pos, sz;
 };
 
+struct erb_key {
+       long tm;
+       float val;
+};
+
+enum {
+       ERB_TRK_X, ERB_TRK_Y, ERB_TRK_Z,                                /* position (x,y,z) */
+       ERB_TRK_QX, ERB_TRK_QY, ERB_TRK_QZ, ERB_TRK_QW, /* rotation quat (xi+yj+zk+w) */
+       ERB_TRK_SX, ERB_TRK_SY, ERB_TRK_SZ,                             /* scaling (x,y,z) */
+       ERB_NUM_TRACKS
+};
+enum erb_interp { ERB_LINEAR, ERB_STEP, ERB_CUBIC };
+enum erb_extrap { ERB_CLAMP, ERB_EXTEND, ERB_REPEAT };
+
+struct erb_track {
+       enum erb_interp interp; /* interpolation mode */
+       enum erb_extrap extrap; /* extrapolation mode */
+       struct erb_key *keys;   /* dynamic array of keyframes */
+       int num_keys, max_keys; /* max_keys: allocated size, num_keys: used */
+};
+
 struct erb_node {
        struct erb_node *par;                                           /* parent node */
        struct erb_node *clist;                                         /* child nodes */
        struct erb_surf *surflist;                                      /* surfaces in this node */
+       struct erb_track track[ERB_NUM_TRACKS];         /* PRS keyframe tracks */
        float xform[16], inv_xform[16];                         /* global transformation */
        float node_xform[16], inv_node_xform[16];       /* local transformation */
 };
@@ -65,13 +94,18 @@ void erb_destroy(struct erb_rend *erb);
 int erb_allocframe(struct erb_rend *erb, int width, int height);
 float *erb_getframe(struct erb_rend *erb);
 
+void erb_setfov(struct erb_rend *erb, float vfov_deg);
+
 /* clears the framebuffer and sample counters to begin rendering a new frame */
 void erb_begin(struct erb_rend *erb);
 /* finalizes the frame, averaging samples (optional) */
 float *erb_end(struct erb_rend *erb);
 
-void erb_queue_frame(struct erb_rend *erb);
-void erb_queue_block(struct erb_rend *erb, int x, int y, int width, int height);
+void erb_set_done_callback(struct erb_rend *erb, erb_done_func donecb, void *cls);
+
+void erb_queue_frame(struct erb_rend *erb, unsigned int job_id);
+void erb_queue_block(struct erb_rend *erb, unsigned int job_id, int x, int y,
+               int width, int height);
 void erb_wait(struct erb_rend *erb);
 
 void erb_primary_ray(struct erb_rend *erb, struct erb_ray *ray, int sample);
@@ -86,8 +120,22 @@ int erb_node_addsurf(struct erb_node *n, struct erb_surf *s);
 int erb_node_rmsurf(struct erb_node *n, struct erb_surf *s);
 
 /* sets the transformation matrix and also calculates the inverse */
+void erb_node_pos(struct erb_node *n, long tm, float x, float y, float z);
+void erb_node_rot(struct erb_node *n, long tm, float qx, float qy, float qz, float qw);
+void erb_node_rot_axis(struct erb_node *n, long tm, float angle_deg, float x, float y, float z);
+void erb_node_scale(struct erb_node *n, long tm, float sx, float sy, float sz);
+/* calculates transformation matrices for time tm by keyframe interpolation */
+void erb_node_update(struct erb_node *n, long tm);
+/* sets transformation, ignoring animation keyframes */
 void erb_node_setxform(struct erb_node *n, float *mat);
 
+void erb_node_eval_pos(struct erb_node *n, long tm, cgm_vec3 *pos);
+void erb_node_eval_rot(struct erb_node *n, long tm, cgm_quat *rot);
+void erb_node_eval_scale(struct erb_node *n, long tm, cgm_vec3 *scale);
+
+void erb_node_eval_matrix(struct erb_node *n, long tm, float *mat);                    /* mat[16] */
+void erb_node_eval_node_matrix(struct erb_node *n, long tm, float *mat);       /* mat[16] */
+
 /* surfaces */
 struct erb_surf *erb_surface(int datasz);
 void erb_free_surface(struct erb_surf *surf);