Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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 647 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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (14 views)
2014-04-15 18:08:23

BurntPizza (12 views)
2014-04-15 03:46:01

UprightPath (25 views)
2014-04-14 17:39:50

UprightPath (11 views)
2014-04-14 17:35:47

Porlus (28 views)
2014-04-14 15:48:38

tom_mai78101 (50 views)
2014-04-10 04:04:31

BurntPizza (109 views)
2014-04-08 23:06:04

tom_mai78101 (209 views)
2014-04-05 13:34:39

trollwarrior1 (177 views)
2014-04-04 12:06:45

CJLetsGame (184 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!