1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| public SkyDome( Image2D[] img, int center_x, int center_y, int center_z, int width, int height, int depth ) { int half_width = (width / 2), half_height = (height / 2), half_depth = (depth / 2); short posCX = (short)(center_x + half_width), negCX = (short)(center_x - half_width), posCY = (short)(center_y + half_height), negCY =(short)(center_y - half_height), posCZ = (short)(center_z + half_depth), negCZ = (short)(center_z - half_depth); try {
Texture2D[] textures = new Texture2D[6]; for( int i = 0; i < 6; i++ ) { textures[i] = new Texture2D( img[i] ); textures[i].setFiltering( Texture2D.FILTER_LINEAR, Texture2D.FILTER_LINEAR ); textures[i].setWrapping( Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP ); textures[i].setBlendColor( Texture2D.FUNC_MODULATE ); }
short[] vSide1 = { posCX, posCY, posCZ, negCX, posCY, posCZ, posCX, negCY, posCZ, negCX, negCY, posCZ }; short[] vSide2 = { negCX, posCY, negCZ, posCX, posCY, negCZ, negCX, negCY, negCZ, posCX, negCY, negCZ }; short[] vSide3 = { negCX, posCY, posCZ, negCX, posCY, negCZ, negCX, negCY, posCZ, negCX, negCY, negCZ }; short[] vSide4 = { posCX, posCY, negCZ, posCX, posCY, posCZ, posCX, negCY, negCZ, posCX, negCY, posCZ }; short[] vSide5 = { posCX, posCY, negCZ, negCX, posCY, negCZ, posCX, posCY, posCZ, negCX, posCY, posCZ }; short[] vSide6 = { posCX, negCY, posCZ, negCX, negCY, posCZ, posCX, negCY, negCZ, negCX, negCY, negCZ };
short[] tex = { 1, 0, 0, 0, 1, 1, 0, 1, }; Mesh skymesh[] = new Mesh[6]; skymesh[0] = createFace( vSide1, textures[0], tex ); skymesh[1] = createFace( vSide2, textures[1], tex ); skymesh[2] = createFace( vSide3, textures[2], tex ); skymesh[3] = createFace( vSide4, textures[3], tex ); skymesh[4] = createFace( vSide5, textures[4], tex ); skymesh[5] = createFace( vSide6, textures[5], tex );
m_groupSkybox = new Group(); for( int i = 0; i < 6; i++) m_groupSkybox.addChild( skymesh[i] );
} catch( Exception e ) { System.out.println( "*** SkyDome::SkyBox Construction Exception **** "); e.printStackTrace(); } }
private Mesh createFace( short[] vertices, Texture2D texture, short[] texcoords ) { VertexArray v = new VertexArray( vertices.length / 3, 3, 2 ); v.set( 0, vertices.length / 3, vertices ); VertexArray t = new VertexArray( texcoords.length / 2, 2, 2 ); t.set( 0, texcoords.length / 2, texcoords ); VertexBuffer vb = new VertexBuffer(); vb.setPositions( v, 1.0f, null ); vb.setTexCoords( 0, t, 1.0f, null ); Appearance app = new Appearance(); app.setTexture( 0, texture ) ; PolygonMode poly = new PolygonMode(); poly.setCulling( PolygonMode.CULL_FRONT ); app.setPolygonMode( poly );
int strips[] = { 4 }; IndexBuffer ib = new TriangleStripArray( 0, strips ); Mesh meshFlat = new Mesh( vb, ib, app ); meshFlat.setAppearance( 0, app ); return meshFlat; } |