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

📄 jogldrawingarea.java

📁 基于java的3d开发库。对坐java3d的朋友有很大的帮助。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                framedBody.setMaterial(theScene.defaultMaterial());                bodySet.getBodies().add(framedBody);            }            //-----------------------------------------------------------------            Matrix4x4 Mset = bodySet.getTransformationMatrix(), R, Ri, Mbody, S, M;            SimpleBody copiedBody;            Quaternion q;            for ( i = 0; i < referenceBodies.getBodies().size(); i++ ) {                referenceBody = referenceBodies.getBodies().get(i);                if ( cam == 1 ) {                    copiedBody = theScene.addThing(referenceBody.getGeometry());                    Mbody = referenceBody.getTransformationMatrix();                    M = Mset.multiply(Mbody);                    p = new Vector3D(M.M[0][3], M.M[1][3], M.M[2][3]);                    M.M[0][3] = M.M[1][3] = M.M[2][3] = 0.0;                    q = M.exportToQuaternion();                    q.normalize();                    R = new Matrix4x4();                    R.importFromQuaternion(q);                    Ri = R.inverse();                    S = Ri.multiply(M);                    s = new Vector3D(M.M[0][0], M.M[1][1], M.M[2][2]);                    copiedBody.setPosition(p);                    copiedBody.setScale(s);                    copiedBody.setRotation(R);                }            }            //-----------------------------------------------------------------        }        //- Render will proceed in a PBuffer ------------------------------        IndexedColorImage distanceFieldIndexed;        projectedViewRenderer.configureScene(bodySet, cam);        projectedViewRenderer.draw(gl);        //canvas.swapBuffers();        //-----------------------------------------------------------------        Image finalImage;        if ( !doDistanceField ) {            finalImage = projectedViewRenderer.image;        }        else {            System.out.print("Processing maps for view " + cam + "... ");            distanceFieldIndexed = new IndexedColorImage();            distanceFieldIndexed.init(distanceFieldSide, distanceFieldSide);            ImageProcessing.processDistanceFieldWithArray(projectedViewRenderer.image, distanceFieldIndexed, 1);            ImageProcessing.gammaCorrection(distanceFieldIndexed, 2.0);            RGBAImage distanceFieldRgba;            distanceFieldRgba = distanceFieldIndexed.exportToRgbaImage();            int x, y;            for ( x = 0; x < distanceFieldRgba.getXSize(); x++ ) {                for ( y = 0; y < distanceFieldRgba.getYSize(); y++ ) {                    if ( distanceFieldIndexed.getPixel(x, y) < 1 ) {                        distanceFieldRgba.putPixel(x, y,                                                   (byte)255, (byte)0, (byte)0, (byte)128);                    }                }            }            finalImage = distanceFieldRgba;            System.out.println("Ok!");        }        //vsdk.toolkit.io.image.ImagePersistence.exportPPM(new java.io.File("./test" + cam + ".ppm"), finalImage);        //- Obtain Pbuffer's rendered image -------------------------------        return finalImage;    }    private SimpleBodyGroup    addDebugProjectedView(GL gl, SimpleBodyGroup referenceBodies)    {        SimpleBody boxBody;        Image texture;        SimpleBodyGroup group;        Vector3D position = new Vector3D(0, 0, 0);        Vector3D scale = new Vector3D(1, 1, 1);        Matrix4x4 R = new Matrix4x4();        Matrix4x4 R1 = new Matrix4x4();        Matrix4x4 R2 = new Matrix4x4();        int i;        double delta = 0.01/2.0;        TriangleMesh mesh;        Vertex[] vertexArray;        Triangle[] triangleArray;        Vector3D n;        Image textureArray[];        Material materialArray[];        int materialRanges[][];        int textureRanges[][];        group = new SimpleBodyGroup();        for ( i = 1; i <= 13; i++ ) {            R = new Matrix4x4();            switch ( i ) {              case 1:                position = new Vector3D(0, -2, 0);                R.axisRotation(Math.toRadians(90), new Vector3D(1, 0, 0));                break;              case 2:                position = new Vector3D(-2, 0, 0);                R1.axisRotation(Math.toRadians(90), new Vector3D(0, 0, -1));                R2.axisRotation(Math.toRadians(90), new Vector3D(0, -1, 0));                R = R2.multiply(R1);                break;              case 3:                position = new Vector3D(0, 0, -2);                R.axisRotation(Math.toRadians(180), new Vector3D(0, 1, 0));                break;              case 4:                position = new Vector3D(-1, -1, 1);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(45), new Vector3D(0, 0, -1));                R2.axisRotation(Math.toRadians(35), new Vector3D(1, -1, 0));                R = R2.multiply(R1);                break;              case 5:                position = new Vector3D(1, -1, 1);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(45), new Vector3D(0, 0, 1));                R2.axisRotation(Math.toRadians(35), new Vector3D(1, 1, 0));                R = R2.multiply(R1);                break;              case 6:                position = new Vector3D(1, 1, 1);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(135), new Vector3D(0, 0, 1));                R2.axisRotation(Math.toRadians(35), new Vector3D(-1, 1, 0));                R = R2.multiply(R1);                break;              case 7:                position = new Vector3D(-1, 1, 1);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(135), new Vector3D(0, 0, -1));                R2.axisRotation(Math.toRadians(35), new Vector3D(-1, -1, 0));                R = R2.multiply(R1);                break;              case 8:                position = new Vector3D(0, 1, -1);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(180), new Vector3D(0, 0, 1));                R2.axisRotation(Math.toRadians(135), new Vector3D(-1, 0, 0));                R = R2.multiply(R1);                break;              case 9:                position = new Vector3D(-1, 0, -1);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(90), new Vector3D(0, 0, -1));                R2.axisRotation(Math.toRadians(135), new Vector3D(0, -1, 0));                R = R2.multiply(R1);                break;              case 10:                position = new Vector3D(0, -1, -1);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R.axisRotation(Math.toRadians(135), new Vector3D(1, 0, 0));                break;              case 11:                position = new Vector3D(1, 0, -1);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(90), new Vector3D(0, 0, 1));                R2.axisRotation(Math.toRadians(135), new Vector3D(0, 1, 0));                R = R2.multiply(R1);                break;              case 12:                position = new Vector3D(1, -1, 0);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(90), new Vector3D(1, 0, 0));                R2.axisRotation(Math.toRadians(45), new Vector3D(0, 0, 1));                R = R2.multiply(R1);                break;              case 13:                position = new Vector3D(1, 1, 0);                position.normalize();                position = position.multiply(1.5);                scale = new Vector3D(0.5, 0.5, 0.5);                R1.axisRotation(Math.toRadians(90), new Vector3D(1, 0, 0));                R2.axisRotation(Math.toRadians(135), new Vector3D(0, 0, 1));                R = R2.multiply(R1);                break;            }            //-----------------------------------------------------------------            texture = createProjectedView(gl, referenceBodies, i);            if ( texture == null ) {                return null;            }            //-----------------------------------------------------------------            n = new Vector3D(0, 0, 1);            vertexArray = new Vertex[4];            vertexArray[0] = new Vertex(new Vector3D(-1, -1, 0), n, 0.0, 0.0);            vertexArray[1] = new Vertex(new Vector3D(1, -1, 0), n, 1.0, 0.0);            vertexArray[2] = new Vertex(new Vector3D(1, 1, 0), n, 1.0, 1.0);            vertexArray[3] = new Vertex(new Vector3D(-1, 1, 0), n, 0.0, 1.0);            triangleArray = new Triangle[2];            triangleArray[0] = new Triangle(0, 1, 2);            triangleArray[1] = new Triangle(2, 3, 0);            textureArray = new Image[1];            textureArray[0] = texture;            textureRanges = new int[1][2];            textureRanges[0][0] = 2;            textureRanges[0][1] = 1;            materialArray = new Material[1];            materialArray[0] = theScene.defaultMaterial();            materialArray[0].setDoubleSided(true);            materialArray[0].setAmbient(new ColorRgb(1, 1, 1));            materialArray[0].setDiffuse(new ColorRgb(1, 1, 1));            materialArray[0].setSpecular(new ColorRgb(1, 1, 1));            materialRanges = new int[1][2];            materialRanges[0][0] = 2;            materialRanges[0][1] = 0;            mesh = new TriangleMesh();            mesh.setVertexes(vertexArray);            mesh.setTriangles(triangleArray);            mesh.setTextures(textureArray);            mesh.setTextureRanges(textureRanges);            mesh.setMaterials(materialArray);            mesh.setMaterialRanges(materialRanges);            //-----------------------------------------------------------------            boxBody = new SimpleBody();            boxBody.setGeometry(mesh);            boxBody.setPosition(position);            boxBody.setScale(scale);            boxBody.setRotation(R);            boxBody.setRotationInverse(R.inverse());            boxBody.setMaterial(theScene.defaultMaterial());            boxBody.getMaterial().setDoubleSided(true);            boxBody.getMaterial().setAmbient(new ColorRgb(1, 1, 1));            boxBody.getMaterial().setDiffuse(new ColorRgb(1, 1, 1));            boxBody.getMaterial().setSpecular(new ColorRgb(1, 1, 1));            boxBody.setName("Proyected view box");            boxBody.setTexture(texture);            //-----------------------------------------------------------------            group.getBodies().add(boxBody);        }        return group;    }    private void debugProjectedViewsIfNeeded(GL glAppContext)    {        //-----------------------------------------------------------------        if ( wantToDebugProjectedViews == false ) {            return;        }        wantToDebugProjectedViews = false;        //-----------------------------------------------------------------        int selectedThing = theScene.selectedThings.firstSelected();        SimpleBody referenceBody = null;        int i;        if ( selectedThing >= 0 ) {            referenceBody = theScene.scene.getSimpleBodies().get(selectedThing);        }        if ( referenceBody == null ) {            parent.statusMessage.setText("ERROR: An object must be selected for projected views debugging to be created");        }        else {            SimpleBodyGroup group;            SimpleBodyGroup bodySet;            bodySet = new SimpleBodyGroup();            for ( i = 0; i < theScene.selectedThings.size(); i++ ) {                if ( theScene.selectedThings.isSelected(i) ) {                    referenceBody = theScene.scene.getSimpleBodies().get(i);                    bodySet.getBodies().add(referenceBody);                }            }            group = addDebugProjectedView(glAppContext, bodySet);            if ( group != null ) {                theScene.debugThingGroups.add(group);            }            else {                parent.statusMessage.setText("ERROR: cannot create Pbuffer, you need recent 3D hardware acceleration for this function");            }        }    }    private void copyColorBufferIfNeeded(GL gl)    {        if ( wantToGetColor ) {            parent.zbufferImage = JoglRGBImageRenderer.getImageJOGL(gl);            if ( parent.imageControlWindow == null ) {                parent.imageControlWindow = new SwingImageControlWindow(parent.zbufferImage, parent.gui, parent.executorPanel);            }            else {                parent.imageControlWindow.setImage(parent.zbufferImage);            }            parent.imageControlWindow.redrawImage();            parent.statusMessage.setText("ZBuffer Color Image obtained!");            wantToGetColor = false;        }    }    private void copyZBufferIfNeeded(GL gl)    {        if ( wantToGetDepth ) {            if ( wantToGetContourns ) {                IndexedColorImage zbuffer;                NormalMap nm;                zbuffer = JoglZBufferRenderer.importJOGLZBuffer(gl).exportIndexedColorImage();                nm = new NormalMap();                nm.importBumpMap(zbuffer, new Vector3D(1, 1, 0.1));                parent.zbufferImage = nm.exportToRgbImageGradient();            }            else {                parent.zbufferImage =                    JoglZBufferRenderer.importJOGLZBuffer(gl).exportRGBImage(                        parent.palette);            }

⌨️ 快捷键说明

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