static void _test_point(void) { int x, y; const void *clazz; void *point; const struct _propinfo props[] = { { MUME_TYPE_STRING, "name", _POINT_PROP_NAME, MUME_PROP_READWRITE }, { MUME_TYPE_STRING, "coord", _POINT_PROP_COORD, MUME_PROP_READWRITE }, }; const struct _property props1[] = { { "name", "hello" }, { "coord", "10, 20" }, }; const struct _property props2[] = { { "name", "another name" }, { "coord", "-1050, -1" }, }; _test_properties(point_class(), props, COUNT_OF(props)); test_assert(mume_class_of(mume_object_class()) == mume_meta_class()); test_assert(mume_class_of(mume_meta_class()) == mume_meta_class()); test_assert(mume_super_class(mume_object_class()) == mume_object_class()); test_assert(mume_super_class(mume_meta_class()) == mume_object_class()); point = point_new("hello", 10, 20); test_assert(strcmp(point_get_name(point), "hello") == 0); _test_get_properties(point, props1, COUNT_OF(props1)); point_get_coord(point, &x, &y); test_assert(10 == x && 20 == y); point_move(point, -10, 30); point_get_coord(point, &x, &y); test_assert(-10 == x && 30 == y); _test_set_properties(point, props2, COUNT_OF(props2)); _test_get_properties(point, props2, COUNT_OF(props2)); draw_result = 0; point_draw(point); test_assert(DRAW_POINT == draw_result); clazz = mume_class_of(point); test_assert(point_class() == clazz); test_assert(0 == strcmp(mume_class_name(clazz), "point")); test_assert(mume_object_class() == mume_super_class(clazz)); test_assert(mume_size_of(point) == sizeof(struct _point)); test_assert(mume_size_of(point_class()) == sizeof(struct _point_class)); test_assert(mume_is_a(point, point_class())); test_assert(mume_is_of(point, point_class())); test_assert(!mume_is_a(point, mume_object_class())); test_assert(mume_is_of(point, mume_object_class())); test_assert(mume_is_a(point_class(), point_meta_class())); test_assert(mume_is_of(point_class(), mume_object_class())); test_assert(mume_is_of(point_meta_class(), mume_meta_class())); test_assert(mume_is_of(point_class(), mume_meta_class())); mume_delete(point); }
static void _test_circle(void) { int x, y; double rad; const void *clazz; void *circle; const struct _propinfo props[] = { { MUME_TYPE_DOUBLE, "radian", _CIRCLE_PROP_RADIAN, MUME_PROP_READWRITE } }; const struct _property props1[] = { { "name", "world" }, { "coord", "40, 30" }, { "radian", "3.140000000000" }, }; const struct _property props2[] = { { "name", "diff world" }, { "coord", "0, -1024" }, { "radian", "-1.110000000000" }, }; _test_properties(circle_class(), props, COUNT_OF(props)); circle = circle_new("world", 40, 30, 3.14); test_assert(strcmp(point_get_name(circle), "world") == 0); _test_get_properties(circle, props1, COUNT_OF(props1)); point_get_coord(circle, &x, &y); test_assert(40 == x && 30 == y); point_move(circle, 50, 60); point_get_coord(circle, &x, &y); test_assert(50 == x && 60 == y); rad = circle_get_radian(circle); test_assert(fabs(rad - 3.14) < 0.001); _test_set_properties(circle, props2, COUNT_OF(props2)); _test_get_properties(circle, props2, COUNT_OF(props2)); draw_result = 0; point_draw(circle); test_assert((DRAW_POINT | DRAW_CIRCLE) == draw_result); clazz = mume_class_of(circle); test_assert(circle_class() == clazz); test_assert(0 == strcmp(mume_class_name(clazz), "circle")); test_assert(mume_super_class(clazz) == point_class()); test_assert(mume_size_of(circle) == sizeof(struct _circle)); test_assert(mume_size_of(circle_class()) == sizeof(struct _circle_class)); test_assert(mume_is_a(circle, circle_class())); test_assert(!mume_is_a(circle, point_class())); test_assert(mume_is_of(circle, point_class())); mume_delete(circle); }
/* * Draw the module into the image using the given view transformation matrix [VTM], * Lighting and DrawState by traversing the list of Elements. * (For now, Lighting can be an empty structure.) */ void module_draw(Module *md, Matrix *VTM, Matrix *GTM, DrawState *ds, Lighting *lighting, Image *src){ /* for antialiasing Module *thickLineMod = module_create(); Element *thickLineE; float dx, dy, dz, lineLength; Vector u, v, w;*/ // all locally needed variables Matrix LTM, tempGTM; Line tempLine; DrawState *tempds = drawstate_create(); Point tempPointLTM, tempPointGTM, tempPointVTM; Polyline *tempPolyline = polyline_create(); Polygon *tempPolygon = polygon_create(); Element *e = md->head; matrix_identity(<M); // loop until the end of the linked list is reached while(e){ //printf("Handling type %d\n", e->type); // draw based on type switch(e->type){ case ObjNone: break; case ObjPoint: //printf("drawing point "); // copy, xform, normalize, draw matrix_xformPoint(<M, &(e->obj.point), &tempPointLTM); matrix_xformPoint(GTM, &tempPointLTM, &tempPointGTM); matrix_xformPoint(VTM, &tempPointGTM, &tempPointVTM); point_normalize(&(tempPointVTM)); //point_print(&tempPointVTM, stdout); point_draw(&tempPointVTM, src, ds->color); break; case ObjLine: line_copy(&tempLine, &(e->obj.line)); //printf("drawing line "); // copy, xform, normalize, draw matrix_xformLine(<M, &tempLine); matrix_xformLine(GTM, &tempLine); matrix_xformLine(VTM, &tempLine); line_normalize(&tempLine); line_draw(&tempLine, src, ds->color); //line_print(&tempLine, stdout); /*if(antialias){ dx = tempLine.b.val[0]-tempLine.a.val[0]; dy = tempLine.b.val[1]-tempLine.a.val[1]; dz = tempLine.b.val[2]-tempLine.a.val[2]; lineLength = sqrt(dx*dx+dy*dy+dz*dz); module_scale( thickLineMod, 1, lineLength, 1 ); vector_set(&v, dx, dy, dz); vector_normalize(&v); vector_set(&u, -dz, dx, dy); vector_cross(&u, &v, &w); vector_cross(&v, &w, &u); vector_normalize(&u); vector_normalize(&w); module_rotateXYZ( thickLineMod, &u, &v, &w ); module_translate( thickLineMod, tempLine.a.val[0], tempLine.a.val[1], tempLine.a.val[2] ); module_cylinder( thickLineMod, 4, 1, 1, 0, 0, 0 ); thickLineE = element_init(ObjModule, thickLineMod); thickLineE->next = e->next; e->next = thickLineE; }*/ break; case ObjPolyline: //printf("drawing polyline "); // copy, xform, normalize, draw polyline_copy(tempPolyline, &(e->obj.polyline)); matrix_xformPolyline(<M, tempPolyline); matrix_xformPolyline(GTM, tempPolyline); matrix_xformPolyline(VTM, tempPolyline); polyline_normalize(tempPolyline); //polyline_print(tempPolyline, stdout); polyline_draw(tempPolyline, src, ds->color); break; case ObjPolygon: //printf("drawing polygon "); // copy, xform, normalize, draw polygon_copy(tempPolygon, &(e->obj.polygon)); matrix_xformPolygon(<M, tempPolygon); matrix_xformPolygon(GTM, tempPolygon); matrix_xformPolygon(VTM, tempPolygon); polygon_normalize(tempPolygon); //polygon_print(tempPolygon, stdout); polygon_draw(tempPolygon, src, ds); break; case ObjColor: drawstate_setColor(ds, e->obj.color); break; case ObjBodyColor: break; case ObjSurfaceColor: break; case ObjSurfaceCoeff: break; case ObjLight: break; case ObjIdentity: matrix_identity(<M); break; case ObjMatrix: matrix_multiply(&(e->obj.matrix), <M, <M); break; case ObjModule: matrix_multiply(GTM, <M, &tempGTM); drawstate_copy(tempds, ds); module_draw(e->obj.module, VTM, &tempGTM, tempds, lighting, src); break; default: printf("ObjectType %d is not handled in module_draw\n",e->type); } // advance traversal e = e->next; } // clean up polygon_free(tempPolygon); polyline_free(tempPolyline); free(tempds); }