Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (306)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Skybox and textures  (Read 752 times)
0 Members and 1 Guest are viewing this topic.
Offline necroleak

Junior Newbie




Java games rock!


« Posted 2005-02-05 08:22:42 »

Hi, I'm trying to create a SkyBox that will wrap all the gameworld. The SkyBox cube will have six different textures for all its sides, but I currently cannot get how to easily implement this.
I'm creating a cube mesh (VB,IB) and putting it around the game world, but how can I put different texture on each side ?
Offline necroleak

Junior Newbie




Java games rock!


« Reply #1 - Posted 2005-02-10 12:07:46 »

I finally managed to work it out. For those interested here's the piece of code. The 'Group' class was the big thing here.

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
        {

            // load textures
           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 );
            }
            

            // front
           short[] vSide1 = { posCX, posCY, posCZ,  negCX, posCY, posCZ, posCX, negCY, posCZ,  negCX, negCY, posCZ };
            // back
           short[] vSide2 = { negCX, posCY, negCZ, posCX, posCY, negCZ, negCX, negCY, negCZ, posCX, negCY, negCZ };
            // left
           short[] vSide3 = { negCX, posCY, posCZ, negCX, posCY, negCZ, negCX, negCY, posCZ, negCX, negCY, negCZ };
            // right                
           short[] vSide4 = { posCX, posCY, negCZ, posCX, posCY, posCZ, posCX, negCY, negCZ, posCX, negCY, posCZ };
            // top
           short[] vSide5 = { posCX, posCY, negCZ, negCX, posCY, negCZ, posCX, posCY, posCZ, negCX, posCY, posCZ };
            // bottom            
           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 );

            // compose skybox mesh as a group of submeshes
           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 );
        
        // create the appearance
       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;
    }



Gud luk  Wink
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
Jesse_Attard (11 views)
2013-06-18 22:03:02

HeroesGraveDev (55 views)
2013-06-15 23:35:23

Vermeer (55 views)
2013-06-14 20:08:06

davedes (55 views)
2013-06-14 16:03:55

alaslipknot (50 views)
2013-06-13 07:56:31

Roquen (68 views)
2013-06-12 04:12:32

alaslipknot (56 views)
2013-06-10 19:30:18

HeroesGraveDev (72 views)
2013-06-09 04:36:03

alaslipknot (60 views)
2013-06-09 03:40:19

CodeHead (60 views)
2013-06-09 02:55:41
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!