penguinbase.java
来自「3D手机游戏开发实例源代码」· Java 代码 · 共 357 行
JAVA
357 行
import javax.microedition.m3g.*;public class PenguinBase { public VertexBuffer getVertexBuffer() { // create vertices short[] POINTS = getVerts(); VertexArray POSITION_ARRAY = new VertexArray(POINTS.length / 3, 3, 2); POSITION_ARRAY.set(0, POINTS.length / 3, POINTS); // create normals byte[] NORMALS = getNormals(); VertexArray NORMAL_ARRAY = new VertexArray(NORMALS.length / 3, 3, 1); NORMAL_ARRAY.set(0, NORMALS.length / 3, NORMALS); // create texture coordinates short[] TEXCOORDS = getTexCoords(); VertexArray TEXCOORD_ARRAY = new VertexArray(TEXCOORDS.length / 2, 2, 2); TEXCOORD_ARRAY.set(0, TEXCOORDS.length / 2, TEXCOORDS); float[] pbias = { (1.0f / 255.0f), (1.0f / 255.0f), (1.0f / 255.0f)}; VertexBuffer vertexBuffer = new VertexBuffer(); vertexBuffer.setPositions(POSITION_ARRAY, (2.0f / 255.0f), pbias); // scale, bias vertexBuffer.setNormals(NORMAL_ARRAY); vertexBuffer.setTexCoords(0, TEXCOORD_ARRAY, (1.0f / 255.0f), null); return vertexBuffer; } // end of getVertexBuffer() // -----------------------------------------------------------// Methods for model in penguinBase.obj private short[] getVerts() // return an array holding Verts [870 values / 3 = 290 points] { short[] POINTS = { -39,-15,-80, -39,11,-80, -20,-15,-75, -20,11,-75, -20,-15,-75, -6,26,-61, -6,-15,-60, -6,26,-61, -1,-15,-40, -1,26,-41, -1,-15,-40, -6,26,-21, -6,-15,-20, -6,26,-21, -20,-15,-6, -20,11,-6, -20,-15,-6, -39,11,-1, -39,-15,-1, -39,11,-1, -59,-15,-6, -59,11,-6, -59,-15,-6, -71,30,-26, -73,-15,-20, -71,30,-26, -78,-15,-40, -74,24,-40, -78,-15,-40, -69,29,-66, -73,-15,-60, -69,29,-66, -59,-15,-75, -69,29,-66, -59,11,-75, -69,29,-66, -59,36,-75, -123,42,-60, -59,36,-75, -73,62,-60, -59,62,-75, -73,62,-60, -59,87,-75, -73,62,-60, -73,87,-60, -73,62,-60, -82,87,-40, -78,62,-40, -82,87,-40, -73,62,-20, -73,87,-20, -73,62,-20, -58,87,-6, -58,62,-6, -58,87,-6, -39,71,22, -39,87,-1, -39,71,22, -20,87,-6, -20,62,-6, -20,87,-6, -6,62,-20, -6,87,-20, -6,62,-20, -1,87,-40, -1,62,-40, -1,87,-40, -6,62,-60, -6,87,-60, -6,62,-60, -20,87,-75, -6,62,-60, -20,62,-75, -6,62,-60, -20,36,-75, -6,62,-60, 49,31,-54, -6,62,-60, 49,31,-34, -1,62,-40, 49,31,-34, -6,62,-20, -6,36,-20, -6,62,-20, -20,36,-6, -20,62,-6, -20,36,-6, -39,71,22, -39,36,-1, -39,71,22, -58,36,-6, -58,62,-6, -58,36,-6, -73,62,-20, -73,36,-20, -73,62,-20, -128,42,-40, -78,62,-40, -128,42,-40, -73,62,-60, -128,42,-40, -123,42,-60, -128,42,-40, -69,29,-66, -128,42,-40, -74,24,-40, -128,42,-40, -71,30,-26, -73,36,-20, -71,30,-26, -58,36,-6, -59,11,-6, -58,36,-6, -39,11,-1, -39,36,-1, -39,11,-1, -20,36,-6, -20,11,-6, -20,36,-6, -6,26,-21, -6,36,-20, -6,26,-21, 49,31,-34, -1,26,-41, 49,31,-34, -6,26,-61, 49,31,-54, -6,26,-61, -20,36,-75, -20,11,-75, -20,36,-75, -39,11,-80, -20,36,-75, -39,36,-80, -20,36,-75, -39,62,-80, -20,62,-75, -39,62,-80, -20,87,-75, -39,87,-80, -20,87,-75, -39,113,-80, -20,87,-75, -20,113,-75, -20,87,-75, -6,113,-60, -6,87,-60, -6,113,-60, -1,87,-40, -1,113,-40, -1,87,-40, -6,113,-20, -6,87,-20, -6,113,-20, -20,87,-6, -20,113,-6, -20,87,-6, -39,113,-1, -39,87,-1, -39,113,-1, -58,87,-6, -58,113,-6, -58,87,-6, -72,113,-20, -73,87,-20, -72,113,-20, -82,87,-40, -82,113,-40, -82,87,-40, -73,113,-61, -73,87,-60, -73,113,-61, -59,87,-75, -59,113,-76, -59,87,-75, -39,113,-80, -59,87,-75, -39,87,-80, -59,87,-75, -39,62,-80, -59,62,-75, -39,62,-80, -59,36,-75, -39,36,-80, -59,36,-75, -39,11,-80, -59,11,-75, -39,11,-80, -59,-15,-75, -39,-15,-80, -59,-15,-75, -39,-40,-80, -59,-15,-75, -59,-40,-75, -59,-15,-75, -73,-40,-60, -73,-15,-60, -73,-40,-60, -78,-15,-40, -82,-40,-40, -78,-15,-40, -89,-40,-10, -73,-15,-20, -89,-40,-10, -59,-15,-6, -82,-40,-3, -59,-15,-6, -73,-40,-1, -59,-15,-6, -55,-40,1, -59,-15,-6, -39,-40,-1, -39,-15,-1, -39,-40,-1, -20,-15,-6, -22,-40,1, -20,-15,-6, -3,-40,1, -20,-15,-6, 7,-40,-2, -20,-15,-6, 11,-40,-10, -6,-15,-20, 11,-40,-10, -1,-15,-40, 4,-40,-40, -1,-15,-40, -6,-40,-60, -6,-15,-60, -6,-40,-60, -20,-15,-75, -20,-40,-75, -20,-15,-75, -39,-40,-80, -39,-15,-80, -39,113,-80, -59,113,-76, -40,127,-40, -73,113,-61, -40,127,-40, -82,113,-40, -40,127,-40, -72,113,-20, -40,127,-40, -58,113,-6, -40,127,-40, -39,113,-1, -40,127,-40, -20,113,-6, -40,127,-40, -6,113,-20, -40,127,-40, -1,113,-40, -40,127,-40, -6,113,-60, -40,127,-40, -20,113,-75, -39,113,-80, -39,-40,-80, -20,-40,-75, -39,-40,-40, -6,-40,-60, -39,-40,-40, 4,-40,-40, -39,-40,-40, 11,-40,-11, -39,-40,-40, 8,-40,-3, -39,-40,-40, -2,-40,1, -39,-40,-40, -22,-40,1, -39,-40,-40, -39,-40,-1, -39,-40,-40, -55,-40,1, -39,-40,-40, -73,-40,-1, -39,-40,-40, -82,-40,-3, -39,-40,-40, -89,-40,-10, -39,-40,-40, -82,-40,-40, -39,-40,-40, -73,-40,-60, -39,-40,-40, -59,-40,-75, -39,-40,-40, -39,-40,-80 }; return POINTS; } // end of getVerts() private byte[] getNormals() // return an array holding Normals [870 values / 3 = 290 points] { byte[] NORMALS = { 34,0,-123, 34,0,-123, 65,0,-110, 64,0,-111, 65,0,-110, 92,-56,-70, 112,-1,-63, 92,-56,-70, 126,16,-12, 94,-87,0, 126,16,-12, 99,-21,79, 106,41,59, 99,-21,79, 53,33,112, 67,0,109, 53,33,112, 0,0,127, 0,0,127, 0,0,127, -52,30,113, -78,1,102, -52,30,113, -101,-35,70, -104,48,58, -101,-35,70, -126,20,-11, -109,-67,10, -126,20,-11, -93,-47,-74, -112,0,-63, -93,-47,-74, -64,-1,-111, -93,-47,-74, -59,0,-114, -93,-47,-74, -48,-3,-119, -61,-15,-111, -48,-3,-119, -96,41,-74, -65,0,-110, -96,41,-74, -65,-2,-111, -96,41,-74, -106,-2,-72, -96,41,-74, -128,-5,1, -110,65,0, -128,-5,1, -98,14,82, -105,1,73, -98,14,82, -76,14,102, -98,0,82, -76,14,102, 0,13,127, 0,59,114, 0,13,127, 77,14,101, 100,0,80, 77,14,101, 101,15,77, 112,-1,61, 101,15,77, 127,-1,0, 111,63,0, 127,-1,0, 101,39,-68, 112,0,-63, 101,39,-68, 65,0,-110, 101,39,-68, 65,0,-110, 101,39,-68, 50,-6,-118, 101,39,-68, 68,-31,-104, 101,39,-68, 97,-20,81, 111,63,0, 97,-20,81, 101,15,77, 65,-4,110, 101,15,77, 77,-10,102, 100,0,80, 77,-10,102, 0,13,127, 0,-37,123, 0,13,127, -77,-21,100, -98,0,82, -77,-21,100, -98,14,82, -66,-48,99, -98,14,82, -106,-27,67, -110,65,0, -106,-27,67, -96,41,-74, -106,-27,67, -61,-15,-111, -106,-27,67, -93,-47,-74, -106,-27,67, -109,-67,10, -106,-27,67, -101,-35,70, -66,-48,99, -101,-35,70, -77,-21,100, -78,1,102, -77,-21,100, 0,0,127, 0,-37,123, 0,0,127, 77,-10,102, 67,0,109, 77,-10,102, 99,-21,79, 65,-4,110, 99,-21,79, 97,-20,81, 94,-87,0, 97,-20,81, 92,-56,-70, 68,-31,-104, 92,-56,-70, 50,-6,-118, 64,0,-111, 50,-6,-118, 34,0,-123, 50,-6,-118, 34,0,-123, 50,-6,-118, 34,0,-123, 65,0,-110, 34,0,-123, 65,0,-110, 34,0,-123, 65,0,-110, 34,0,-123, 65,0,-110, 65,0,-110, 65,0,-110, 111,0,-63, 112,0,-63, 111,0,-63, 127,-1,0, 127,-2,-1, 127,-1,0, 112,-1,62, 112,-1,61, 112,-1,62, 77,14,101, 66,0,110, 77,14,101, 0,0,127, 0,59,114, 0,0,127, -76,14,102, -65,0,110, -76,14,102, -105,1,73, -105,1,73, -105,1,73, -128,-5,1, -128,0,2, -128,-5,1, -106,-3,-71, -106,-2,-72, -106,-3,-71, -65,-2,-111, -62,-5,-112, -65,-2,-111, -31,-3,-124, -65,-2,-111, -34,0,-123, -65,-2,-111, -34,0,-123, -65,0,-110, -34,0,-123, -48,-3,-119, -34,0,-123, -48,-3,-119, -34,0,-123, -59,0,-114, -34,0,-123, -64,-1,-111, -34,0,-123, -64,-1,-111, -34,0,-123, -64,-1,-111, -65,0,-110, -64,-1,-111, -109,4,-67, -112,0,-63, -109,4,-67, -126,20,-11, -120,18,-42, -126,20,-11, -101,68,39, -104,48,58, -101,68,39, -52,30,113, -52,58,102, -52,30,113, -22,36,121, -52,30,113, 0,35,123, -52,30,113, 1,18,127, 0,0,127, 1,18,127, 53,33,112, -6,33,123, 53,33,112, 19,45,118, 53,33,112, 66,80,75, 53,33,112, 103,72,27, 106,41,59, 103,72,27, 126,16,-12, 119,22,-42, 126,16,-12, 108,5,-69, 112,-1,-63, 108,5,-69, 65,0,-110, 65,0,-110, 65,0,-110, 34,0,-123, 34,0,-123, 1,120,-45, -22,120,-39, 1,127,0, -38,119,-26, 1,127,0, -42,121,0, 1,127,0, -38,119,26, 1,127,0, -23,120,39, 1,127,0, 0,120,45, 1,127,0, 23,120,39, 1,127,0, 40,120,22, 1,127,0, 46,120,-1, 1,127,0, 40,119,-24, 1,127,0, 23,120,-39, 1,120,-45, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0, 0,-128,0 }; return NORMALS; } // end of getNormals() private short[] getTexCoords() // return an array holding TexCoords [580 values / 2 = 290 points] { short[] TEXCOORDS = { 0,212,0,170,21,212,21,170,21,212,43,170,43,212,43,170,64,212,64,170,64,212,85,170,85,212,85,170,107,212,107,170,107,212,128,170,128,212,128,170,149,212,149,170,149,212,171,170,171,212,171,170,192,212,192,170,192,212,213,170,213,212,213,170,235,212,213,170,235,170,213,170,235,127,213,127,235,127,213,84,235,84,213,84,235,42,213,84,213,42,213,84,192,42,192,84,192,42,171,84,171,42,171,84,149,42,149,84,149,42,128,84,128,42,128,84,107,42,107,84,107,42,85,84,85,42,85,84,64,42,64,84,64,42,43,84,43,42,43,84,21,42,43,84,21,84,43,84,21,127,43,84,43,127,43,84,64,127,64,84,64,127,85,84,85,127,85,84,107,127,107,84,107,127,128,84,128,127,128,84,149,127,149,84,149,127,171,84,171,127,171,84,192,127,192,84,192,127,213,84,192,127,213,127,192,127,213,170,192,127,192,170,192,127,171,170,171,127,171,170,149,127,149,170,149,127,128,170,128,127,128,170,107,127,107,170,107,127,85,170,85,127,85,170,64,127,64,170,64,127,43,170,43,127,43,170,21,127,21,170,21,127,0,170,21,127,0,127,21,127,0,84,21,84,0,84,21,42,0,42,21,42,0,0,21,42,21,0,21,42,43,0,43,42,43,0,64,42,64,0,64,42,85,0,85,42,85,0,107,42,107,0,107,42,128,0,128,42,128,0,149,42,149,0,149,42,171,0,171,42,171,0,192,42,192,0,192,42,213,0,213,42,213,0,235,42,235,0,235,42,255,0,235,42,255,42,235,42,255,84,235,84,255,84,235,127,255,127,235,127,255,170,235,170,255,170,235,212,255,212,235,212,255,255,235,212,235,255,235,212,213,255,213,212,213,255,192,212,192,255,192,212,171,255,171,212,171,255,149,212,165,255,149,212,160,255,149,212,149,255,149,212,128,255,128,212,128,255,107,212,107,255,107,212,101,255,107,212,96,255,107,212,85,255,85,212,85,255,64,212,64,255,64,212,43,255,43,212,43,255,21,212,21,255,21,212,0,255,0,212,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; return TEXCOORDS; } // end of getTexCoords()} // end of PenguinBase class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?