public override void BeginOpenGLMainDisplay(SolidEdgeSDK.IGL gl) { if (gl == null) return; DrawBoundingBox(gl); if (_showOpenGlBoxes) { float fSize = 0.025f; double[] matrix0 = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; double[] matrix1 = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, fSize, 1 }; double[] matrix2 = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, fSize, -fSize, 1 }; double[] matrix3 = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, fSize, -fSize, 0, 1 }; gl.glMatrixMode(SharpGL.OpenGL.GL_MODELVIEW); int mode = 0; int depth = 0; uint error; error = gl.glGetError(); gl.glGetIntegerv(SharpGL.OpenGL.GL_MATRIX_MODE, ref mode); gl.glGetIntegerv(SharpGL.OpenGL.GL_MODELVIEW_STACK_DEPTH, ref depth); gl.glPushMatrix(); gl.glGetIntegerv(SharpGL.OpenGL.GL_MODELVIEW_STACK_DEPTH, ref depth); gl.glLoadMatrixd(matrix0); gl.glColor3f(1, 0, 0); DrawCube(gl, fSize / 2.0f); gl.glPopMatrix(); gl.glPushMatrix(); { gl.glMultMatrixd(matrix1); gl.glColor3f(0, 1, 0); DrawCube(gl, fSize / 2.0f); } { gl.glMultMatrixd(matrix2); gl.glColor3f(0, 0, 1); DrawCube(gl, fSize / 2.0f); } { gl.glMultMatrixd(matrix3); gl.glColor4f(1, 1, 0, .25f); DrawCube(gl, fSize / 2.0f); } gl.glPopMatrix(); } }
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(); } }