Skip to content

Instantly share code, notes, and snippets.

@pjanik
Created February 25, 2014 10:31
Show Gist options
  • Select an option

  • Save pjanik/9206519 to your computer and use it in GitHub Desktop.

Select an option

Save pjanik/9206519 to your computer and use it in GitHub Desktop.
offset axes
private void renderOffsetAxes() {
Axes axes = (Axes) shape;
boolean b = viewer.transformManager.getPerspectiveDepth();
viewer.transformManager.setPerspectiveDepth2(false);
viewer.transformPoint(axes.originPoint, originScreen);
dx = originScreen.x - (viewer.dimScreen.width - OFFSET_DISTANCE);
dy = originScreen.y - (viewer.dimScreen.height - OFFSET_DISTANCE);
originScreen.x -= dx;
originScreen.y -= dy;
int originScreenZ;
for (int i = 3; --i >= 0;) {
viewer.transformPoint(axes.conePoints[i], coneScreens[i]);
coneScreens[i].x -= dx;
coneScreens[i].y -= dy;
x12 = coneScreens[i].x - originScreen.x;
y12 = coneScreens[i].y - originScreen.y;
z12 = coneScreens[i].z - originScreen.z;
r12 = (float) Math.sqrt(x12 * x12 + y12 * y12 + z12 * z12);
if (r12 < 0.0001f)
continue;
r12 = 0.75f * OFFSET_DISTANCE / r12;
originScreenZ = originScreen.z;
coneScreens[i].x = (int) (originScreen.x + x12 * r12);
coneScreens[i].y = (int) (originScreen.y + y12 * r12);
coneScreens[i].z = originScreen.z = 1;
g3d.fillCylinder(colors[i], Graphics3D.ENDCAPS_SPHERICAL, 4, originScreen, coneScreens[i]);
originScreen.z = originScreenZ;
viewer.transformPoint(axes.axisPoints[i], axisScreens[i]);
axisScreens[i].x -= dx;
axisScreens[i].y -= dy;
x12 = axisScreens[i].x - originScreen.x;
y12 = axisScreens[i].y - originScreen.y;
z12 = axisScreens[i].z - originScreen.z;
r12 = (float) Math.sqrt(x12 * x12 + y12 * y12 + z12 * z12);
r12 = OFFSET_DISTANCE / r12;
axisScreens[i].x = (int) (originScreen.x + x12 * r12);
axisScreens[i].y = (int) (originScreen.y + y12 * r12);
axisScreens[i].z = 1;
g3d.fillCone(colors[i], Graphics3D.ENDCAPS_SPHERICAL, 10, coneScreens[i], axisScreens[i]);
frameRenderer.renderStringOutside(axisLabels[i], colors[i], axes.font3d, axisScreens[i], g3d);
}
viewer.transformManager.setPerspectiveDepth2(b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment