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

📄 meshfactory.java

📁 一个j2me的3d游戏实例
💻 JAVA
字号:
package game.terrain;

import javax.microedition.lcdui.Image;
import javax.microedition.m3g.*;


public class MeshFactory
{

    
    public static Mesh createQuad(short[] heights, int cullFlags, int x, int z , int factor, int xTrans,int zTrans, Appearance app)
    {
           	
    	short[] vertrices = {(short)( x - xTrans ), heights[0], (short)( z - zTrans),
                (short)(x+factor - xTrans), heights[1], (short)(z - zTrans),
                (short)(x+factor - xTrans), heights[2], (short)(z+factor - zTrans),
                (short)(x - xTrans), heights[3], (short)(z+factor- zTrans)}; 
    	
        VertexArray vertexArray;
        IndexBuffer triangles;
        
        vertexArray = new VertexArray(vertrices.length/3, 3, 2);
        vertexArray.set(0, vertrices.length/3, vertrices);
        
//        short texCoords[] = new short[] {        		
//        		0, 0,
//               255, 0,
//               255, 255,
//                0, 255  };
        short texCoords[] = new short[] {        		
        		0, 0,
                1, 0,
                1, 1,
                0, 1  };
        
        
        VertexArray texArray;
        texArray = new VertexArray(texCoords.length/2,2,2);
        texArray.set(0, texCoords.length/2, texCoords);

        VertexBuffer vertexBuffer = new VertexBuffer();
        vertexBuffer.setPositions(vertexArray, 1.0f, null);        
        vertexBuffer.setTexCoords(0,texArray,1, null);

        int indices[] = new int[] {0, 1, 3, 2};
        int[] stripLengths = new int[] {4};
        
        triangles = new TriangleStripArray(indices, stripLengths);        
        
        Mesh mesh = new Mesh(vertexBuffer, triangles, app);
        
        return mesh;
    }
    

    
    public static Appearance makeAppearance(String texFilename)
    {
    	Appearance app = new Appearance();
    	
    	PolygonMode pm = new PolygonMode();
        pm.setCulling(PolygonMode.CULL_NONE);
        app.setPolygonMode(pm);

        try
        {

            Image texImage = Image.createImage(texFilename);
            Texture2D theTexture = new Texture2D(new Image2D(Image2D.RGBA, texImage));

            theTexture.setBlending(Texture2D.FUNC_REPLACE);

            theTexture.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP);
            theTexture.setFiltering(Texture2D.FILTER_BASE_LEVEL, Texture2D.FILTER_NEAREST);

            app.setTexture(0, theTexture);
        }
        catch(Exception e)
        {
            System.out.println("Failed to create texture");
            System.out.println(e);
        }
    	return app;
    }
}

⌨️ 快捷键说明

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