25 struct object *clist, *ctail;
26 struct object *parent;
54 static float identity[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
58 if(!(root = csg_null(0, 0, 0))) {
62 csg_view(0, 0, 5, 0, 0, 0);
68 void csg_destroy(void)
70 csg_free_object(root);
74 void csg_view(float x, float y, float z, float tx, float ty, float tz)
84 void csg_fov(float fov)
86 cam.fov = M_PI * fov / 180.0f;
90 int csg_load(const char *fname)
95 int csg_save(const char *fname)
100 void csg_add_object(csg_object *parent, csg_object *child)
103 parent->ctail->next = child;
104 parent->ctail = child;
106 parent->clist = parent->ctail = child;
108 child->parent = parent;
111 void csg_remove_object(csg_object *parent, csg_object *child)
113 csg_object *c = parent->clist;
115 if(c->next == child) {
116 c->next = child->next;
125 void csg_free_object(csg_object *o)
127 csg_object *c = o->clist;
131 csg_free_object(tmp);
136 static void init_object(union csg_object *o)
138 o->ob.type = OBJ_NULL;
139 memcpy(o->ob.xform, identity, sizeof identity);
141 csg_emission(o, 0, 0, 0);
142 csg_color(o, 1, 1, 1);
147 csg_object *csg_null(float x, float y, float z)
151 if(!(o = calloc(sizeof *o, 1))) {
158 csg_object *csg_sphere(float x, float y, float z, float r)
162 csg_object *csg_cylinder(float x0, float y0, float z0, float x1, float y1, float z1, float r)
166 csg_object *csg_plane(float x, float y, float z, float nx, float ny, float nz)
170 csg_object *csg_box(float x, float y, float z, float xsz, float ysz, float zsz)
175 csg_object *csg_union(csg_object *a, csg_object *b)
179 csg_object *csg_intersection(csg_object *a, csg_object *b)
183 csg_object *csg_subtraction(csg_object *a, csg_object *b)
188 void csg_emission(csg_object *o, float r, float g, float b)
192 void csg_color(csg_object *o, float r, float g, float b)
196 void csg_roughness(csg_object *o, float r)
200 void csg_opacity(csg_object *o, float p)
205 void csg_render_pixel(int x, int y, float *color)
209 void csg_render_image(float *pixels, int width, int height)