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

📄 plane.java

📁 3D手机游戏开发实例源代码
💻 JAVA
字号:
import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import com.mascotcapsule.micro3d.v3.*;public class Plane extends V3Object {    public static final int TYPE_FLOOR = 0;    public static final int TYPE_ROOF= 1;    public static final int TYPE_BACK_WALL = 2;    public static final int TYPE_FRONT_WALL = 3;    public static final int TYPE_RIGHT_WALL = 4;    public static final int TYPE_LEFT_WALL = 5;    private int type = 0;        private final int COMMAND = Graphics3D.PRIMITVE_TRIANGLES |                                 Graphics3D.PDATA_NORMAL_NONE |                                Graphics3D.PDATA_COLOR_NONE |                                Graphics3D.PDATA_TEXURE_COORD;                                              private int []POINT;    private int []NORMAL = new int[] {0, 0, -4096};                                          private int []TEXTURE;                                          private int []COLOR = new int[] {0xFF0000};    private Texture texture = null;    private FigureLayout layout;    private Effect3D effect;    private AffineTrans trans;//    private AffineTrans lookAt;    private AffineTrans rotationY;    private AffineTrans rotationX;    private int rotY=0, rotX = 0;    public Plane(int w, int h, int type){        layout = new FigureLayout();        effect = new Effect3D();        trans = new AffineTrans();        trans.setIdentity();        effect.setShadingType(Effect3D.NORMAL_SHADING);        layout.setAffineTrans( trans );        layout.setPerspective(1, 4096, 512);        layout.setCenter(w/2, h/2);        rotationY = new AffineTrans();        rotationY.setIdentity();                rotationX = new AffineTrans();        rotationX.setIdentity();        trans.mul(lookAt, rotationY);        setType(type);        createPlane();    }    public void setType(int type){        this.type = type;        switch(type){            case TYPE_FLOOR:                rotX = -1024;                rotX(rotX);                break;            case TYPE_ROOF:                break;            case TYPE_BACK_WALL:                break;        }    }    public void rotY(int a){        rotationY.rotationY(a);    }    public void rotX(int a){        rotationX.rotationX(a);    }    public void rotate(){        AffineTrans rot = new AffineTrans();        rot.setIdentity();        rot.mul(rotationY);        rot.mul(rotationX);        trans.mul(lookAt, rot);    }    public void setTexture(Texture t){        texture = t;    }    public void draw(Graphics3D g3d){        rotate();        g3d.renderPrimitives(texture, 0, 0, layout, effect, COMMAND, 72, POINT, NORMAL, TEXTURE, COLOR);    }    /*     * Creates a 6x6 plane     */    private void createPlane(){        POINT = new int[6*6*2*3*3];        System.out.println("len=" + POINT.length);        int index=0;        int Z_POS = 0;        int row_index = -3;        if(type == TYPE_BACK_WALL ){            Z_POS = -96;            row_index = 0;        }        final int SIZE = 32;        for(int row=row_index; row<(row_index+6); row++){            for(int col=-3; col<3; col++){                System.out.println("index:" + index);                // == 1st triangle                POINT[index] = SIZE*col;                POINT[index+1] = SIZE*row+SIZE;                POINT[index+2] = Z_POS;                POINT[index+3] = SIZE*col;                POINT[index+4] = SIZE*row;                POINT[index+5] = Z_POS;                POINT[index+6] = SIZE*col+SIZE;                POINT[index+7] = SIZE*row;                POINT[index+8] = Z_POS;                // == 2nd triangle                POINT[index+9] = SIZE*col;                POINT[index+10] = SIZE*row+SIZE;                POINT[index+11] = Z_POS;                POINT[index+12] = SIZE*col+SIZE;                POINT[index+13] = SIZE*row;                POINT[index+14] = Z_POS;                POINT[index+15] = SIZE*col+SIZE;                POINT[index+16] = SIZE*row+SIZE;                POINT[index+17] = Z_POS;                //                System.out.println("px:" + POINT[index] + " py:" + POINT[index+1] + " pz:" + POINT[index+2] + "\tpx:" + POINT[index+3] + " py:" + POINT[index+4] + " pz:" + POINT[index+5] + "\tpx:" + POINT[index+6] + " py:" + POINT[index+7] + " pz:" + POINT[index+8]);//                System.out.println("2px:" + POINT[index+9] + " py:" + POINT[index+10] + " pz:" + POINT[index+11] + "\tpx:" + POINT[index+12] + " py:" + POINT[index+13] + " pz:" + POINT[index+14] + "\tpx:" + POINT[index+15] + " py:" + POINT[index+16] + " pz:" + POINT[index+17]);                index+=18;            }        }        TEXTURE = new int[6*6*2*3*2];        index=0;        int texW = 0, texH=255;        int texChange = 42;        for(int row=0; row<6; row++){            for(int col=0; col<6; col++){                texW = col*texChange;                System.out.println("index:" + index);                TEXTURE[index + 0] = texW;                TEXTURE[index + 1] = texH - texChange;                TEXTURE[index + 2] = texW;                TEXTURE[index + 3] = texH;                TEXTURE[index + 4] = texW + texChange;                TEXTURE[index + 5] = texH;                // ==                TEXTURE[index + 6] = texW;                TEXTURE[index + 7] = texH - texChange;                TEXTURE[index + 8] = texW + texChange;                TEXTURE[index + 9] = texH;                TEXTURE[index + 10] = texW + texChange;                TEXTURE[index + 11] = texH - texChange;                //                System.out.println("t0="+TEXTURE[index+0] + " t1="+TEXTURE[index+1] + "\tt2="+TEXTURE[index+2] + " t3="+TEXTURE[index+3] + "\tt4="+TEXTURE[index+4] + " t5="+TEXTURE[index+5]);//                System.out.println("t6="+TEXTURE[index+6] + " t7="+TEXTURE[index+7] + "\tt8="+TEXTURE[index+8] + " t9="+TEXTURE[index+9] + "\tt10="+TEXTURE[index+10] + " t11="+TEXTURE[index+11]);                                index+=12;            }            texH -= texChange;        }            }    }

⌨️ 快捷键说明

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