void renderOutline(Graphics3D g3d) { g3d.glPolygonMode(Graphics3DDraw.GL_FRONT_AND_BACK, Graphics3DDraw.GL_LINE); float radiusProportions = m_config.getRadiusProportions(); IVector3f[] top = m_config.getTopVertices(); IVector3f[] bottom = m_config.getBottomVertices(); // top g3d.glBegin(Graphics3DDraw.GL_LINE_LOOP); g3d.glNormal3f(0, 0, -1); for (int i = 0; i < top.length; i++) g3d.glVertex3f(top[i]); g3d.glEnd(); if (radiusProportions == 0) { // sides g3d.glBegin(Graphics3DDraw.GL_LINES); for (int i = 0; i < top.length; i++) { g3d.glVertex3f(top[i]); g3d.glVertex3f(bottom[0]); } g3d.glEnd(); } else { g3d.glBegin(Graphics3DDraw.GL_LINES); for (int i = 0; i < top.length; i++) { g3d.glVertex3f(top[i]); g3d.glVertex3f(bottom[i]); } g3d.glEnd(); g3d.glBegin(Graphics3DDraw.GL_LINE_LOOP); for (int i = 0; i < bottom.length; i++) g3d.glVertex3f(bottom[i]); g3d.glEnd(); } }
private float getCapDistance(IVector3f i_rayOrigin, IVector3f i_rayDirection) { IVector3f[] bottom = m_config.getBottomVertices(); if (bottom.length > 1) { float d = Math3D.rayIntersectsPolygon( i_rayOrigin, i_rayDirection, bottom, IVector3f.Z_AXIS_NEG, null); if (!Float.isNaN(d)) return d; } IVector3f[] top = m_config.getTopVertices(); return Math3D.rayIntersectsPolygon(i_rayOrigin, i_rayDirection, top, IVector3f.Z_AXIS, null); }
private float doGetConeDistance( Vector3f rayOrigin, IVector3f rayDirection, float i_minZ, float i_height) { float sa2 = m_config.getSinApex2(); float ca2 = m_config.getCosApex2(); float xo = rayOrigin.getX(); float yo = rayOrigin.getY(); float zo = rayOrigin.getZ(); float xd = rayDirection.getX(); float yd = rayDirection.getY(); float zd = rayDirection.getZ(); float xo2 = xo * xo; float yo2 = yo * yo; float zo2 = zo * zo; float xd2 = xd * xd; float yd2 = yd * yd; float zd2 = zd * zd; float A = ca2 * (xd2 + yd2) - sa2 * zd2; float B = 2 * (ca2 * (xo * xd + yo * yd) - sa2 * zo * zd); float C = ca2 * (xo2 + yo2) - sa2 * zo2; Math3D.solveQuadraticEquation(A, B, C, TMP_F2); // we must check the z coordinates of possible hits now float d0 = TMP_F2[0]; float d1 = TMP_F2[1]; float zi0 = Float.isNaN(d0) ? Float.NaN : zo + zd * d0; float zi1 = Float.isNaN(d1) ? Float.NaN : zo + zd * d1; boolean v0 = Math3D.in(i_minZ, i_height, zi0); boolean v1 = Math3D.in(i_minZ, i_height, zi1); if (!v0 && !v1) return Float.NaN; if (v0 && v1) return Math3D.minDistance(d0, d1); if (v0) return d0; return d1; }
/** * {@inheritDoc} * * @see * org.eclipse.draw3d.shapes.PositionableShape#doGetDistance(org.eclipse.draw3d.geometry.IVector3f, * org.eclipse.draw3d.geometry.IVector3f, java.util.Map) */ @Override protected float doGetDistance( IVector3f i_rayOrigin, IVector3f i_rayDirection, Map<Object, Object> i_context) { float radiusProportions = m_config.getRadiusProportions(); if (radiusProportions == 1) return getCylinderDistance(i_rayOrigin, i_rayDirection); else if (radiusProportions == 0) return getConeDistance(i_rayOrigin, i_rayDirection); else return getTruncatedConeDistance(i_rayOrigin, i_rayDirection); }
void renderFill(Graphics3D g3d) { g3d.glPolygonMode(Graphics3DDraw.GL_FRONT_AND_BACK, Graphics3DDraw.GL_FILL); float radiusProportions = m_config.getRadiusProportions(); IVector3f[] top = m_config.getTopVertices(); IVector3f[] bottom = m_config.getBottomVertices(); // top g3d.glBegin(Graphics3DDraw.GL_POLYGON); for (int i = 0; i < top.length; i++) g3d.glVertex3f(top[i]); g3d.glEnd(); if (radiusProportions == 0) { // sides g3d.glBegin(Graphics3DDraw.GL_TRIANGLE_FAN); g3d.glVertex3f(bottom[0]); for (int i = top.length - 1; i >= 0; i--) g3d.glVertex3f(top[i]); g3d.glVertex3f(top[top.length - 1]); g3d.glEnd(); } else { g3d.glBegin(Graphics3DDraw.GL_QUAD_STRIP); for (int i = bottom.length - 1; i >= 0; i--) { g3d.glVertex3f(bottom[i]); g3d.glVertex3f(top[i]); } g3d.glVertex3f(bottom[bottom.length - 1]); g3d.glVertex3f(top[top.length - 1]); g3d.glEnd(); // bottom g3d.glBegin(Graphics3DDraw.GL_POLYGON); for (int i = bottom.length - 1; i >= 0; i--) g3d.glVertex3f(bottom[i]); g3d.glEnd(); } }
private float getTruncatedConeDistance(IVector3f i_rayOrigin, IVector3f i_rayDirection) { // if we hit an end cap, we are done float d = getCapDistance(i_rayOrigin, i_rayDirection); if (!Float.isNaN(d)) return d; // it's much quicker to intersect with a cone whose apex is the // origin and that extends along the positive Z axis, so translate the // ray accordingly and then check with a positive min Z value Vector3f newOrigin = Draw3DCache.getVector3f(); try { float h = m_config.getHeight(); Math3D.translate(i_rayOrigin, -0.5f, -0.5f, h - 1, newOrigin); return doGetConeDistance(newOrigin, i_rayDirection, h - 1, h); } finally { Draw3DCache.returnVector3f(newOrigin); } }