How to create 3-color-manipulator


One of the useful tips of creating an arrow in HOOPS Visualize is to use Polycylinder geometry. You can get the sample code at InsertNormalIndicator mothod in CuttingSectionOperator class. The following sample source code would give you an idea of how to create an impressive manupulator.

Translation Arrow Method would go like this.

//////////////////////////////////
void CHPSView::
InsertTransArrow(Point Origin, Vector Dir, double dLength, double dRadius, SegmentKey indicator_seg)
{
	PointArray pts(6);
	FloatArray radii(6);
	double dArrowTop = dLength + dRadius * 6;
	double dArrowBottom = dLength + dRadius * 2;
	pts[0] = Origin + dArrowTop * Dir;
	pts[1] = Origin + dArrowBottom * Dir;
	pts[2] = pts[1];
	pts[3] = pts[1];
	pts[4] = pts[1];
	pts[5] = Origin;

	radii[0] = 0.0f;
	radii[1] = dRadius * 2;
	radii[2] = radii[1];
	radii[3] = dRadius;
	radii[4] = radii[3];
	radii[5] = radii[3];
	indicator_seg.InsertCylinder(pts, radii);
}

Rotational Arrow Method would go like this.

//////////////////////////////////
void CHPSView::
InsertRotArrow(Point Origin, Vector UDir, Vector VDir, double dLength, double dRadius, SegmentKey indicator_seg)
{
	int i = 0;
	PointArray pts(13);
	FloatArray radii(13);

	double dCoordU;
	double dCoordV;
	double M_PI = 3.141592;

	for (i = 0; i < 9; i++)
	{
		dCoordU = dLength * cos(M_PI / 2 * i / 8);
		dCoordV = dLength * sin(M_PI / 2 * i / 8);
		pts[i + 2] = Origin + dCoordU * UDir + dCoordV * VDir;
		radii[i + 2] = dRadius;
	}
	
	pts[1] = pts[2];
	pts[0] = pts[1] - dRadius * 8 * VDir;
	pts[11] = pts[10];
	pts[12] = pts[11] - dRadius * 8 * UDir;

	radii[0] = 0.0f;
	radii[1] = dRadius * 2;
	radii[11] = dRadius * 2;
	radii[12] = 0;
	indicator_seg.InsertCylinder(pts, radii);
}

You can call the following code from Sandbox.

SegmentKey indicated_key = GetCanvas().GetAttachedLayout().GetAttachedView().GetSegmentKey();

	double dLength = 20.0f;
	double dRadius = 2.0f;
	Point Origin = Point(0, 0, 0);
	Vector XAxis = Vector(1, 0, 0);
	Vector YAxis = Vector(0, 1, 0);
	Vector ZAxis = Vector(0, 0, 1);

	SegmentKey redArrowKey = indicated_key.Subsegment("red");
	InsertTransArrow(Origin, ZAxis, dLength, dRadius, redArrowKey);
	InsertRotArrow(Origin, XAxis, YAxis, dLength, dRadius, redArrowKey);
	redArrowKey.GetMaterialMappingControl().SetFaceColor(RGBAColor(1, 0, 0, 1));

	SegmentKey greenArrowKey = indicated_key.Subsegment("green");
	InsertTransArrow(Origin, YAxis, dLength, dRadius, greenArrowKey);
	InsertRotArrow(Origin, ZAxis, XAxis, dLength, dRadius, greenArrowKey);
	greenArrowKey.GetMaterialMappingControl().SetFaceColor(RGBAColor(0, 1, 0, 1));

	SegmentKey blueArrowKey = indicated_key.Subsegment("blue");
	InsertTransArrow(Origin, XAxis, dLength, dRadius, blueArrowKey);
	InsertRotArrow(Origin, YAxis, ZAxis, dLength, dRadius, blueArrowKey);
	blueArrowKey.GetMaterialMappingControl().SetFaceColor(RGBAColor(0, 0, 1, 1));

	GetCanvas().Update();