Generate polylines from Insert_Elliptical_Arc using callbacks

The following sample code insert a circle in a offscreen driver. A callback is used to retrieve circle geometry points to polylines points.

These polylines points is inserted to the main scene for validation.

Sample code is tested using PartViewer.

static HIC_Point * global_polylines_pts;
static int polyline_count;

extern "C" {
	typedef void (*him_function)(HC_ANY_ARGS);
}
#define HIM_FUNCTION(function) (him_function)(function)



static void draw3dpolyline_cb(HIC_Rendition const *nr, HIC_Polyline const *polyline)
{
	polyline_count = HIC_Show_Polyline_Count(polyline);
	HIC_Point const* polyline_points = HIC_Show_Polyline_Points(polyline);

	global_polylines_pts = new HIC_Point[polyline_count];

	for (int i = 0; i < polyline_count; i++) {
		char buf[1024];
		sprintf(buf, "(%.2f,%.2f,%.2f)\n", polyline_points[i].x, polyline_points[i].y, polyline_points[i].z);

		global_polylines_pts[i].x = polyline_points[i].x;
		global_polylines_pts[i].y = polyline_points[i].y;
		global_polylines_pts[i].z = polyline_points[i].z;

	}

	//  global_polylines_pts will contain all polylines generated points 

	HIC_Draw_3D_Polyline(nr, polyline);
}


void CSolidHoopsView::OnExtraSlot1()
{	


	HC_KEY ikey;
	char options[MVO_BUFFER_SIZE];


	HC_Open_Segment("/driver/opengl2/image"); {

		ikey = HC_Insert_Image(0, 0, 0, "rgba", 50, 50, 0);
		sprintf(options, "use window id = image key = %s%p, no subscreen, no border, isolated", H_EXTRA_POINTER_FORMAT, (void *)ikey);

		HC_Set_Driver_Options(options);

		HC_Open_Segment("scene"); {

			float position[] = { 0.0, 0.0, -5.0 };
			float target[] = { 0.0, 0.0, 0.0 };
			float up[] = { 0.0, 1.0, 0.0 };

			float field_width = 8.0 / 3.0;
			float field_height = 2.0;

			HC_Set_Camera(&position, &target, &up, field_width, field_height, "orthographic");

			HC_Open_Segment("model"); {
				HC_Define_Callback_Name("poly", HIM_FUNCTION(draw3dpolyline_cb));
				HC_Set_Callback("draw 3d polyline=poly");

				HC_Set_Visibility("lines=on");
				HPoint center, major, minor;

				center.x = 0; center.y = 0; center.z = 0;
				major.x = 1; major.y = 0; major.z = 0;
				minor.x = 0; minor.y = 1; minor.z = 0;

				HC_Open_Segment("circle");
				HC_Insert_Elliptical_Arc(&center, &major, &minor, 0, 1);
				HC_Close_Segment();

			} HC_Close_Segment();

		} HC_Close_Segment();

	} HC_Close_Segment();

	HC_Update_One_Display("/driver/opengl2/image");


//  insert polyline into the main scene
	HC_Open_Segment_By_Key(m_pHView->GetModelKey()); {
		HC_Open_Segment(""); {
			HC_Set_Visibility("lines=on");
			HC_Insert_Polyline(polyline_count, global_polylines_pts);
		} HC_Close_Segment();
	} HC_Close_Segment();

}

1 Like