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);
|