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

📄 meshtool.java

📁 一个旋转的四棱锥
💻 JAVA
字号:
/***************************************************************************** Description: The  MeshTool class. Used to create figures. Created By: Oscar Vivall 2006-06-12 @file        MeshTool.java COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2004. The software is the copyrighted work of Sony Ericsson Mobile Communications AB. The use of the software is subject to the terms of the end-user license  agreement which accompanies or is included with the software. The software is  provided "as is" and Sony Ericsson specifically disclaim any warranty or  condition whatsoever regarding merchantability or fitness for a specific  purpose, title or non-infringement. No warranty of any kind is made in  relation to the condition, suitability, availability, accuracy, reliability,  merchantability and/or non-infringement of the software provided herein. *****************************************************************************/import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.m3g.*;import javax.microedition.m3g.Camera;public class MeshTool {        public static Mesh createMesh(){        short POINTS[] = new short[] {0, 10, -2,                                      0, 10, 2,                                                                            -5, 0, -2,                                      -5, 0, 2,                                                                            5, 0, -2,                                      5, 0, 2,                                      -2, 0, -2,                                      -2, 0, 2,                                                                            2, 0, -2,                                      2, 0, 2,                                                                            -2, -10, -2,                                      -2, -10, 2,                                                                            2, -10, -2,                                      2, -10, 2};        byte COLOR[] = new byte[] {127, 127,127,                                            127, 0, 0,                                            0, 127, 0,                                            0, 0, 127,                                            127, 127, 0,                                            0, 127, 127,                                            127, 0, 127,                                            0, 127, 0,                                            127, 0, 0,                                            0, 127, 0,                                            0, 0, 127,                                            127, 127, 0,                                            0, 127, 127,                                            127, 0, 127};        int INDICES[] = {0, 1, 2, 3, 4, 5, 0, 1,                         6, 7, 8, 9, 12, 13, 10, 11, 6, 7,                         0, 2, 4,                         1, 3, 5,                         6, 8, 10, 12,                         7, 9, 11, 13};        int[] LENGTHS = new int[] {8, 10, 3, 3, 4, 4};        VertexArray POSITIONS_ARRAY, TEXTURE_ARRAY, COLOR_ARRAY;        IndexBuffer INDEX_BUFFER ;        float textureRepeat;        // initialize the common arrays        POSITIONS_ARRAY = new VertexArray(POINTS.length, 3, 2);        POSITIONS_ARRAY.set(0, POINTS.length/3, POINTS);        COLOR_ARRAY = new VertexArray(COLOR.length, 3, 1);        COLOR_ARRAY.set(0, COLOR.length / 3, COLOR);        INDEX_BUFFER = new TriangleStripArray(INDICES, LENGTHS);        VertexBuffer vertexBuffer = new VertexBuffer();        vertexBuffer.setPositions(POSITIONS_ARRAY, 1.0f, null);        vertexBuffer.setColors(COLOR_ARRAY);        Mesh mesh = new Mesh(vertexBuffer, INDEX_BUFFER, null);        Appearance appearance = new Appearance();        PolygonMode polygonMode = new PolygonMode();        polygonMode.setPerspectiveCorrectionEnable(true);        polygonMode.setShading(PolygonMode.SHADE_FLAT);        polygonMode.setCulling(PolygonMode.CULL_NONE);        appearance.setPolygonMode(polygonMode);        mesh.setAppearance(0, appearance);        return mesh;    }    public static Mesh createPlane(short size){//        short size=50;                short []POINTS = new short[] {size, 0, (short)-size,                                      (short)-size, 0, (short)-size,                                      (short)-size, 0, size,                                      size, 0, size};        byte []COLOR = new byte[] {127, 127, 127,                                127, 127, 127,                                127, 127, 127,                                127, 127, 127,};                                        short []TEXTURE = new short[] {1, 0,                                      0, 0,                                      0, 1,                                      1, 1};                                        int []INDICES = new int[] {0,1,3,2};        int []LENGTHS = new int[] {4};        VertexArray POSITIONS_ARRAY, TEXTURE_ARRAY, COLOR_ARRAY;         IndexBuffer INDEX_BUFFER;        float textureRepeat;        // initialize the common arrays        POSITIONS_ARRAY = new VertexArray(POINTS.length/3, 3, 2);         POSITIONS_ARRAY.set(0, POINTS.length/3, POINTS);         COLOR_ARRAY = new VertexArray(COLOR.length/3, 3, 1);        COLOR_ARRAY.set(0, COLOR.length / 3, COLOR);        TEXTURE_ARRAY = new VertexArray(TEXTURE.length/2, 2, 2);        TEXTURE_ARRAY.set(0, TEXTURE.length/2, TEXTURE);        INDEX_BUFFER = new TriangleStripArray(INDICES, LENGTHS);        VertexBuffer vertexBuffer = new VertexBuffer();         vertexBuffer.setPositions(POSITIONS_ARRAY, 1.0f, null); //        vertexBuffer.setColors(COLOR_ARRAY);        vertexBuffer.setTexCoords(0, TEXTURE_ARRAY, 1.0f, null);        Mesh mesh = new Mesh(vertexBuffer, INDEX_BUFFER, null);         Appearance appearance = new Appearance();        PolygonMode polygonMode = new PolygonMode();        polygonMode.setPerspectiveCorrectionEnable(true);//        polygonMode.setShading(PolygonMode.SHADE_FLAT);        polygonMode.setCulling(PolygonMode.CULL_NONE);        appearance.setPolygonMode(polygonMode);        CompositingMode cm = new CompositingMode();        cm.setBlending(CompositingMode.ALPHA);        appearance.setCompositingMode(cm);                Texture2D texture = null;        try{            Image texImg = Image.createImage("/coord64.png"); // Load the image            texture = new Texture2D(new Image2D(Image2D.RGBA, texImg)); // create the texture from the image            texture.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP); // don't repeat the texture.            texture.setBlending(Texture2D.FUNC_MODULATE);            texture.setFiltering(Texture2D.FILTER_LINEAR, Texture2D.FILTER_LINEAR);        }catch(Exception e){            e.printStackTrace();        }        appearance.setTexture(0, texture);        mesh.setAppearance(0, appearance);        return mesh;    }}

⌨️ 快捷键说明

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