Example #1
0
        public void drawBoundingBox(MDrawRequest request, M3dView view)
        //
        // Description:
        //
        //     Bounding box drawing routine
        //
        // Arguments:
        //
        //     request - request to be drawn
        //     view    - view to draw into
        //
        {
            // Get the surface shape
            MPxSurfaceShape shape = (MPxSurfaceShape)surfaceShape;

            if (shape == null)
            {
                return;
            }

            // Get the bounding box
            MBoundingBox box = shape.boundingBox();
            float        w   = (float)box.width;
            float        h   = (float)box.height;
            float        d   = (float)box.depth;

            view.beginGL();

            // Below we just two sides and then connect
            // the edges together

            MPoint minVertex = box.min;

            // Draw first side
            OpenGL.glBegin(OpenGL.GL_LINE_LOOP);
            MPoint vertex = minVertex;

            OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]);
            OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1], (float)vertex[2]);
            OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1] + h, (float)vertex[2]);
            OpenGL.glVertex3f((float)vertex[0], (float)vertex[1] + h, (float)vertex[2]);
            OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]);
            OpenGL.glEnd();

            // Draw second side
            MVector sideFactor = new MVector(0, 0, d);
            MPoint  vertex2    = minVertex.plus(sideFactor);

            OpenGL.glBegin(OpenGL.GL_LINE_LOOP);
            OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]);
            OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1], (float)vertex2[2]);
            OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1] + h, (float)vertex2[2]);
            OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1] + h, (float)vertex2[2]);
            OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]);
            OpenGL.glEnd();

            // Connect the edges together
            OpenGL.glBegin(OpenGL.GL_LINES);
            OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]);
            OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]);

            OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1], (float)vertex2[2]);
            OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1], (float)vertex[2]);

            OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1] + h, (float)vertex2[2]);
            OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1] + h, (float)vertex[2]);

            OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1] + h, (float)vertex2[2]);
            OpenGL.glVertex3f((float)vertex[0], (float)vertex[1] + h, (float)vertex[2]);
            OpenGL.glEnd();

            view.endGL();
        }