private void DrawCube(SolidEdgeSDK.IGL gl, float fSize) { float[][] p0 = new float[][] { new float[] { 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, fSize, 0.0f }, new float[] { fSize, 0.0f, 0.0f }, new float[] { fSize, fSize, 0.0f } }; float[][] p1 = new float[][] { new float[] { 0.0f, 0.0f, fSize }, new float[] { 0.0f, fSize, fSize }, new float[] { fSize, 0.0f, fSize }, new float[] { fSize, fSize, fSize } }; float[][] p2 = new float[][] { new float[] { 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, fSize }, new float[] { 0.0f, fSize, 0.0f }, new float[] { 0.0f, fSize, fSize } }; float[][] p3 = new float[][] { new float[] { fSize, 0.0f, 0.0f }, new float[] { fSize, 0.0f, fSize }, new float[] { fSize, fSize, 0.0f }, new float[] { fSize, fSize, fSize } }; float[][] p4 = new float[][] { new float[] { 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, fSize }, new float[] { fSize, 0.0f, 0.0f }, new float[] { fSize, 0.0f, fSize } }; float[][] p5 = new float[][] { new float[] { 0.0f, fSize, 0.0f }, new float[] { 0.0f, fSize, fSize }, new float[] { fSize, fSize, 0.0f }, new float[] { fSize, fSize, fSize } }; // Normals float[][] n0 = new float[][] { new float[] { 0.0f, 0.0f, -1.0f }, new float[] { 0.0f, 0.0f, 1.0f}, new float[] { 0.0f, -1.0f, 0.0f}, new float[] { 0.0f, 1.0f, 0.0f}, new float[] { 0.0f, 0.0f, 1.0f}, new float[] { 0.0f, 1.0f, 0.0f}, new float[] { 0.0f, -1.0f, 0.0f } }; { gl.glBegin(SharpGL.OpenGL.GL_TRIANGLES); gl.glNormal3fv(n0[0]); gl.glEdgeFlag((byte)SharpGL.OpenGL.GL_TRUE); gl.glVertex3fv(p0[0]); gl.glEdgeFlag(0); gl.glVertex3fv(p0[1]); gl.glEdgeFlag(1); gl.glVertex3fv(p0[2]); gl.glNormal3fv(n0[1]); gl.glEdgeFlag(0); gl.glVertex3fv(p0[1]); gl.glEdgeFlag(1); gl.glVertex3fv(p0[2]); gl.glEdgeFlag(1); gl.glVertex3fv(p0[3]); gl.glEnd(); } { gl.glBegin(SharpGL.OpenGL.GL_TRIANGLE_STRIP); gl.glNormal3fv(n0[2]); gl.glEdgeFlag(1); gl.glVertex3fv(p1[0]); gl.glEdgeFlag(1); gl.glVertex3fv(p1[1]); gl.glEdgeFlag(1); gl.glVertex3fv(p1[2]); gl.glEdgeFlag(1); gl.glVertex3fv(p1[3]); gl.glEnd(); } { gl.glBegin(SharpGL.OpenGL.GL_TRIANGLE_STRIP); gl.glNormal3fv(n0[3]); gl.glEdgeFlag(1); gl.glVertex3fv(p2[0]); gl.glEdgeFlag(1); gl.glVertex3fv(p2[1]); gl.glEdgeFlag(1); gl.glVertex3fv(p2[2]); gl.glEdgeFlag(1); gl.glVertex3fv(p2[3]); gl.glEnd(); } { gl.glBegin(SharpGL.OpenGL.GL_TRIANGLE_STRIP); gl.glNormal3fv(n0[4]); gl.glEdgeFlag(1); gl.glVertex3fv(p3[0]); gl.glEdgeFlag(1); gl.glVertex3fv(p3[1]); gl.glEdgeFlag(1); gl.glVertex3fv(p3[2]); gl.glEdgeFlag(1); gl.glVertex3fv(p3[3]); gl.glEnd(); } { gl.glBegin(SharpGL.OpenGL.GL_TRIANGLE_STRIP); gl.glNormal3fv(n0[5]); gl.glEdgeFlag(1); gl.glVertex3fv(p4[0]); gl.glEdgeFlag(1); gl.glVertex3fv(p4[1]); gl.glEdgeFlag(1); gl.glVertex3fv(p4[2]); gl.glEdgeFlag(1); gl.glVertex3fv(p4[3]); gl.glEnd(); } { gl.glBegin(SharpGL.OpenGL.GL_TRIANGLE_STRIP); gl.glNormal3fv(n0[6]); gl.glEdgeFlag(1); gl.glVertex3fv(p5[0]); gl.glEdgeFlag(1); gl.glVertex3fv(p5[1]); gl.glEdgeFlag(1); gl.glVertex3fv(p5[2]); gl.glEdgeFlag(1); gl.glVertex3fv(p5[3]); gl.glEnd(); } }
private void DrawBoundingBox(SolidEdgeSDK.IGL gl) { if (_boundingBoxInfo.Visible == false) return; if (gl == null) return; Vector3d min = new Vector3d(); Vector3d max = new Vector3d(); this.View.GetModelRange(out min.X, out min.Y, out min.Z, out max.X, out max.Y, out max.Z); gl.glColor3i(_boundingBoxInfo.LineColor.R, _boundingBoxInfo.LineColor.G, _boundingBoxInfo.LineColor.B); gl.glLineWidth(_boundingBoxInfo.LineWidth); gl.glHint(SharpGL.OpenGL.GL_LINE_SMOOTH_HINT, SharpGL.OpenGL.GL_NICEST); { gl.glBegin(SharpGL.OpenGL.GL_LINE_LOOP); gl.glVertex3d(min.X, min.Y, max.Z); gl.glVertex3d(max.X, min.Y, max.Z); gl.glVertex3d(max.X, max.Y, max.Z); gl.glVertex3d(min.X, max.Y, max.Z); gl.glEnd(); } { gl.glBegin(SharpGL.OpenGL.GL_LINE_LOOP); gl.glVertex3d(min.X, min.Y, min.Z); gl.glVertex3d(max.X, min.Y, min.Z); gl.glVertex3d(max.X, max.Y, min.Z); gl.glVertex3d(min.X, max.Y, min.Z); gl.glEnd(); } { gl.glBegin(SharpGL.OpenGL.GL_LINES); gl.glVertex3d(min.X, min.Y, min.Z); gl.glVertex3d(min.X, min.Y, max.Z); gl.glVertex3d(max.X, max.Y, min.Z); gl.glVertex3d(max.X, max.Y, max.Z); gl.glVertex3d(min.X, max.Y, min.Z); gl.glVertex3d(min.X, max.Y, max.Z); gl.glVertex3d(max.X, min.Y, min.Z); gl.glVertex3d(max.X, min.Y, max.Z); gl.glEnd(); } { gl.glColor3f(1, 0, 0); gl.glBegin(SharpGL.OpenGL.GL_LINES); // Diagonal line between min & max points. gl.glVertex3d(min.X, min.Y, min.Z); gl.glVertex3d(max.X, max.Y, max.Z); gl.glEnd(); } }