⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joglpolyhedralboundedsolidrenderer.java

📁 基于java的3d开发库。对坐java3d的朋友有很大的帮助。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            // Face polygon processing via JOGL GLU tesselator            for ( j = 0; j < face.boundariesList.size(); j++ ) {                _PolyhedralBoundedSolidLoop loop;                _PolyhedralBoundedSolidHalfEdge he, heStart;                loop = face.boundariesList.get(j);                he = loop.boundaryStartHalfEdge;                heStart = he;                do {                    // Logic                    he = he.next();                    if ( he == null ) {                        // Loop is not closed!                        break;                    }                    // Draw polygon parts                    vertex.position = he.startingVertex.position;                    JoglGeometryRenderer.drawVertexNormal(gl, vertex);                } while( he != heStart );            }        }        gl.glEnd();    }    private static void    drawSurfaces(GL gl, PolyhedralBoundedSolid solid)    {        int i, j;        //- Prepare tesselator --------------------------------------------        if ( tesselatorProcessor == null ) {            glu = new GLU();            tesselatorProcessor =                 new _JoglPolygonTesselatorRoutines(gl, glu);        }        GLUtessellator tesselator;        //- Draw solid faces one by one -----------------------------------        gl.glCullFace(gl.GL_BACK);        gl.glEnable(gl.GL_CULL_FACE);        //-----------------------------------------------------------------        Vector3D p0, n;        for ( i = 0; i < solid.polygonsList.size(); i++ ) {            // Logic            _PolyhedralBoundedSolidFace face = solid.polygonsList.get(i);            if ( face.containingPlane != null ) {                n = face.containingPlane.getNormal();                gl.glNormal3d(n.x, n.y, n.z);            }            // Count used vertex for current face            int totalNumberOfPoints = 0;            for ( j = 0; j < face.boundariesList.size(); j++ ) {                _PolyhedralBoundedSolidLoop loop;                _PolyhedralBoundedSolidHalfEdge he, heStart;                loop = face.boundariesList.get(j);                he = loop.boundaryStartHalfEdge;                heStart = he;                do {                    // Logic                    he = he.next();                    if ( he == null  ) {                        // Loop is not closed!                        break;                    }                    // Counting                    totalNumberOfPoints++;                } while( he != heStart );            }            // Tesselator preparation for current face            int count;            double list[][]; // JOGL GLU Tesselator needs a vertex memory            tesselator = glu.gluNewTess();            list = new double[totalNumberOfPoints][3];            count = 0;            glu.gluTessCallback(tesselator,                glu.GLU_TESS_VERTEX, tesselatorProcessor);            glu.gluTessCallback(tesselator,                glu.GLU_TESS_BEGIN, tesselatorProcessor);            glu.gluTessCallback(tesselator,                glu.GLU_TESS_END, tesselatorProcessor);            glu.gluTessCallback(tesselator,                glu.GLU_TESS_ERROR, tesselatorProcessor);            glu.gluTessBeginPolygon(tesselator, null);            // Face polygon generation via JOGL GLU tesselator            for ( j = 0; j < face.boundariesList.size(); j++ ) {                _PolyhedralBoundedSolidLoop loop;                _PolyhedralBoundedSolidHalfEdge he, heStart;                glu.gluTessBeginContour(tesselator);                loop = face.boundariesList.get(j);                he = loop.boundaryStartHalfEdge;                heStart = he;                do {                    // Logic                    he = he.next();                    if ( he == null ) {                        // Loop is not closed!                        break;                    }                    // Draw polygon parts                    p0 = he.startingVertex.position;                    list[count][0] = p0.x;                    list[count][1] = p0.y;                    list[count][2] = p0.z;                    glu.gluTessVertex(tesselator, list[count], 0, list[count]);                    count++;                } while( he != heStart );                glu.gluTessEndContour(tesselator);            }            glu.gluTessEndPolygon(tesselator);            glu.gluDeleteTess(tesselator);        }    }    public static void    drawDebugFaceBoundary(GL gl, PolyhedralBoundedSolid solid, int faceIndex)    {        int i, j;        Vector3D startP, endP;        Vector3D p0 = null, p1 = null;        Vector3D p2 = null, a, b;        Vector3D n;        _PolyhedralBoundedSolidHalfEdge hePrev;        InfinitePlane loopPlane;        gl.glDisable(gl.GL_CULL_FACE);        gl.glDisable(gl.GL_TEXTURE_2D);        gl.glDisable(gl.GL_LIGHTING);        gl.glLineWidth(1.0f);        //- Draw face boundaries, one for each loop -----------------------        for ( i = 0; faceIndex >= -1 && i < solid.polygonsList.size(); i++ ) {            _PolyhedralBoundedSolidFace face = solid.polygonsList.get(i);            //n = face.containingPlane.getNormal();            if ( i != faceIndex && faceIndex > -1 ) {                continue;            }            for ( j = 0; j < face.boundariesList.size(); j++ ) {                _PolyhedralBoundedSolidLoop loop;                _PolyhedralBoundedSolidHalfEdge he, heStart;                loop = face.boundariesList.get(j);                he = loop.boundaryStartHalfEdge;                heStart = he;                do {                    // Logic                    he = he.next();                    if ( he == null ) {                        // Loop is not closed!                        break;                    }                    // Calculate containing plane equation for current edge                    p0 = he.startingVertex.position;                    p1 = he.next().startingVertex.position;                    p2 = he.next().next().startingVertex.position;                    a = p1.substract(p0);    a.normalize();                    b = p2.substract(p0);    b.normalize();                    n = a.crossProduct(b);   n.normalize();                    loopPlane = new InfinitePlane(n, p0);                    //loopPlane = face.containingPlane;                    // Draw halfedges                    if ( i == faceIndex ) {                        gl.glLineWidth(2);                    }                    else {                        gl.glLineWidth(1);                    }                    setColor(gl, i);                    drawHalfEdge(gl, he, p0, p1, loopPlane);                } while( he != heStart );            }        }    }    public static void    drawDebugFace(GL gl, PolyhedralBoundedSolid solid, int faceIndex)    {        //- Draw face boundaries, one for each loop -----------------------        int i, j;        //- Prepare tesselator --------------------------------------------        if ( tesselatorProcessor == null ) {            glu = new GLU();            tesselatorProcessor =                 new _JoglPolygonTesselatorRoutines(gl, glu);        }        GLUtessellator tesselator;        //- Draw solid faces one by one -----------------------------------        gl.glCullFace(gl.GL_BACK);        gl.glEnable(gl.GL_CULL_FACE);        //-----------------------------------------------------------------        Vector3D p0, n;        for ( i = faceIndex;              i >= 0 && i == faceIndex && i < solid.polygonsList.size();              i++ ) {            // Logic            _PolyhedralBoundedSolidFace face = solid.polygonsList.get(i);            if ( face.containingPlane != null ) {                n = face.containingPlane.getNormal();                gl.glNormal3d(n.x, n.y, n.z);            }            // Count used vertex for current face            int totalNumberOfPoints = 0;            for ( j = 0; j < face.boundariesList.size(); j++ ) {                _PolyhedralBoundedSolidLoop loop;                _PolyhedralBoundedSolidHalfEdge he, heStart;                loop = face.boundariesList.get(j);                he = loop.boundaryStartHalfEdge;                heStart = he;                do {                    // Logic                    he = he.next();                    if ( he == null  ) {                        // Loop is not closed!                        break;                    }                    // Counting                    totalNumberOfPoints++;                } while( he != heStart );            }            // Tesselator preparation for current face            int count;            double list[][]; // JOGL GLU Tesselator needs a vertex memory            tesselator = glu.gluNewTess();            list = new double[totalNumberOfPoints][3];            count = 0;            glu.gluTessCallback(tesselator,                glu.GLU_TESS_VERTEX, tesselatorProcessor);            glu.gluTessCallback(tesselator,                glu.GLU_TESS_BEGIN, tesselatorProcessor);            glu.gluTessCallback(tesselator,                glu.GLU_TESS_END, tesselatorProcessor);            glu.gluTessCallback(tesselator,                glu.GLU_TESS_ERROR, tesselatorProcessor);            glu.gluTessBeginPolygon(tesselator, null);            // Face polygon generation via JOGL GLU tesselator            for ( j = 0; j < face.boundariesList.size(); j++ ) {                _PolyhedralBoundedSolidLoop loop;                _PolyhedralBoundedSolidHalfEdge he, heStart;                glu.gluTessBeginContour(tesselator);                loop = face.boundariesList.get(j);                he = loop.boundaryStartHalfEdge;                heStart = he;                do {                    // Logic                    he = he.next();                    if ( he == null ) {                        // Loop is not closed!                        break;                    }                    // Draw polygon parts                    p0 = he.startingVertex.position;                    list[count][0] = p0.x;                    list[count][1] = p0.y;                    list[count][2] = p0.z;                    glu.gluTessVertex(tesselator, list[count], 0, list[count]);                    count++;                } while( he != heStart );                glu.gluTessEndContour(tesselator);            }            glu.gluTessEndPolygon(tesselator);            glu.gluDeleteTess(tesselator);        }    }    /**    PRE: Solid has been previously validated. This implies for example that    all faces are planar and has its containing plane equation calculated, so    they are correctly formed geometrical and topological entities.    */    public static void    draw(GL gl, PolyhedralBoundedSolid solid,         Camera c, RendererConfiguration quality)    {        //-----------------------------------------------------------------        JoglRenderer.disableNvidiaCgProfiles();        gl.glDisable(gl.GL_TEXTURE_2D);        gl.glEnable(gl.GL_NORMALIZE);        //-----------------------------------------------------------------        if ( quality.isSurfacesSet() ) {            JoglGeometryRenderer.prepareSurfaceQuality(gl, quality);            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL);            gl.glPolygonOffset(0.5f, 1.0f);            drawSurfaces(gl, solid);        }        if ( quality.isWiresSet() ) {            gl.glPolygonOffset(-0.5f, 0.0f);            drawEdges(gl, solid);        }        if ( quality.isPointsSet() ) {            drawPoints(gl, solid);        }        if ( quality.isNormalsSet() ) {            drawVertexNormals(gl, solid);        }        if ( quality.isBoundingVolumeSet() ) {            JoglGeometryRenderer.drawMinMaxBox(gl, solid, quality);        }        if ( quality.isSelectionCornersSet() ) {            JoglGeometryRenderer.drawSelectionCorners(gl, solid, quality);        }        //-----------------------------------------------------------------    }}//===========================================================================//= EOF                                                                     =//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -