# J2ME Mobile 3D入门教程（一）（转）

3D图形技术在各个领域已经越来越多的被应用了，当然这也包括了J2ME领域。在J2ME中为我们提供了JSR184这样一个可选包，该套API实现手机上3D图形的编程。同时也伴随着移动设备硬件的发展，现在也出现了越来越的支持该可选包的手机了，例如Sony Ericsson的 K系列、S系列等等。

short x = 20;

short y = 20;

short z = 20;

short fx = (short) -x;

short fy = (short) -y;

short fz = (short) -z;

//定点坐标
short[] vert = {x,y,z, fx,y,z, x,fy,z, fx,fy,z, //D

fx,y,fz, x,y,fz, fx,fy,fz, x,fy,fz, //C

fx,y,z, fx,y,fz, fx,fy,z, fx,fy,fz, //B

x,y,fz, x,y,z, x,fy,fz, x,fy,z, //F

x,y,fz, fx,y,fz, x,y,z, fx,y,z, //A

x,fy,z, fx,fy,z, x,fy,fz, fx,fy,fz}; //E

try{vertArray=new VertexArray(vert.length/3,3,2);
vertArray.set(0,vert.length/3,vert);
}catch(Exception e){System.out.println("vert");}

//发线
byte[] norm = { 0,0,127, 0,0,127, 0,0,127, 0,0,127,

0,0,-127, 0,0,-127, 0,0,-127, 0,0,-127,

-127,0,0, -127,0,0, -127,0,0, -127,0,0,

127,0,0, 127,0,0, 127,0,0, 127,0,0,

0,127,0, 0,127,0, 0,127,0, 0,127,0,

0,-127,0, 0,-127,0, 0,-127,0, 0,-127,0};

try{normArray=new VertexArray(norm.length/3,3,1);
normArray.set(0,norm.length/3,norm);
}catch(Exception e){System.out.println("norm");e.printStackTrace();}

//给出顶点们对应图片上的点（vert和tex数组是一一对应的）
short[] tex = { 1, 0, 0, 0, 1, 1, 0, 1,

1, 0, 0, 0, 1, 1, 0, 1,

1, 0, 0, 0, 1, 1, 0, 1,

1, 0, 0, 0, 1, 1, 0, 1,

1, 0, 0, 0, 1, 1, 0, 1,

1, 0, 0, 0, 1, 1, 0, 1 };

try{
texArray=new VertexArray(tex.length/2,2,2);
texArray.set(0,tex.length/2,tex);
}catch(Exception e){System.out.println("tex");}

//建立正方体
vb=new VertexBuffer();
vb.setPositions(vertArray,1.0f,null);
vb.setNormals(normArray);
vb.setTexCoords(0,texArray,1.0f,null);

appearnce=new Appearance();

//创建帖图
Texture2D texture=new Texture2D(image2d);
texture.setBlendColor(Texture2D.FUNC_DECAL);
texture.setWrapping(Texture2D.WRAP_REPEAT,Texture2D.WRAP_REPEAT);
texture.setFiltering(Texture2D.FILTER_NEAREST,Texture2D.FILTER_NEAREST);

material=new Material();
material.setColor(Material.DIFFUSE, 0xFFFFFFFF);
material.setColor(Material.SPECULAR, 0xFFFFFFFF);
material.setShininess(100.0f);

appearnce.setTexture(0,texture);
appearnce.setM

• 博文量
2996
• 访问量
2211162