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 (407)
games submitted by our members
Games in WIP (293)
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  
  Splitting Terrain into Shape3D's  (Read 476 times)
0 Members and 1 Guest are viewing this topic.
Offline Preacher

Junior Member




Java games rock!


« Posted 2005-02-14 10:41:29 »

Hi trying to sub divide the terrain shape from the terrain demo into a 2 dim array of shape3d's  each of size 256 * 256.

wrote a piece of code (see below)  but the texturing is not mapping properly and there is large gaps between each shape3d geometry.

the init method is the only major thing i changed can anyone suggest a reason why there could be gaps between the shape3d's?Huh

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  
    public void rebuild(View view) {

      view.getTransform().get(pTemp); // get the location of the view
     terrain.update(pTemp,117); // update terrain according to the views location
     
      for(int row=0; row<geo.length; ++row){
        for(int col=0; col<geo[0].length; ++col){
       
          geo[row][col].drawStart(); // resets the terrain vertices
         totalIndex = totalVerts = 0;
          terrain.render(this);
          geo[row][col].drawEnd(); // commits the changes to the video card
         geo[row][col].setIndex(index);

          geo[row][col].setValidIndexCount(totalIndex);
          geo[row][col].setValidVertexCount(totalVerts);
         
        }
      }

    }// end rebuild()

    /** called at the beginning of rendering the triangles for one adaptive quad square
     */

    public void start() {
    }
   
    /** */
    public void initVert(int i, float x, float y, float z) {
     
      //System.out.println("initVert: x:"+x+" y:"+y+" z:"+z);
     //System.out.println("texture scale: "+textureScale);
     
      if (totalVerts>=MAX_VERTICES) return;
     
      int row = (int)((x) / 256);
      int col = (int)((z) / 256);
     
      if(row == 4)row = 3;
      if(col == 4)col = 3;
     
      //System.out.println("row: "+row);
     //System.out.println("col: "+col);
     
      //for(int row=0; row<geo.length; ++row){
       //for(int col=0; col<geo[0].length; ++col){
         
          geo[row][col].newVertex();
          geo[row][col].setCoordinate(x,y,z);

          /**
           * Next we have to divide out the texture coordinates. 2D textures have coordinates
           * from 0 to 1 in what is called "S,T" space. Each coordinate in our X,Z world
           * has to be mapped to its appropriate S,T texture coordinate. If we are stretching
           * the texture all the way across the terrain, then 0,0 in X,Z would be 0,0 in S,T and
           * the farthest point in X,Z from the origin would be 1,1 in S,T. Thus, mathematically,
           * we should divide X and Z by the width and depth (should be equal) of the terrain. To
           * wrap the texture, you would divide this depth and width by some number (set by textureScale)
           * to make the textured patches smaller.
          */

          float texCoordx = x / (terrain.getWidth() / textureScale);
          float texCoordz = z / (terrain.getWidth() / textureScale);
          // Now we need to use these figures to set up a TexCoord2f
         TexCoord2f texCoords = new TexCoord2f(texCoordx, texCoordz);
       
          geo[row][col].setTextureCoordinate(0,totalVerts,texCoords);

          // We want prettier colors :-)
         float c = y/1500;
          geo[row][col].setColor(0.48f+c, 0.48f+c, 0.39f+c);

          vertexMap[i] = totalVerts++;
         
        //}
     //}// end for loop

    }// initVert()

    /** */
    public void tri(int a, int b, int c) {
     
      if (totalIndex+3>=MAX_INDICES) return;
      index[totalIndex++] = vertexMap[a];
      index[totalIndex++] = vertexMap[b];
      index[totalIndex++] = vertexMap[c];
     
    }// end tri()
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!
 
Browse for soundtracks for your game!

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!
cubemaster21 (91 views)
2013-05-17 21:29:12

alaslipknot (100 views)
2013-05-16 21:24:48

gouessej (130 views)
2013-05-16 00:53:38

gouessej (125 views)
2013-05-16 00:17:58

theagentd (136 views)
2013-05-15 15:01:13

theagentd (123 views)
2013-05-15 15:00:54

StreetDoggy (165 views)
2013-05-14 15:56:26

kutucuk (187 views)
2013-05-12 17:10:36

kutucuk (190 views)
2013-05-12 15:36:09

UnluckyDevil (196 views)
2013-05-12 05:09:57
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

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.22 seconds with 21 queries.