Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  [SOLVED]Terrain Texturing  (Read 2460 times)
0 Members and 1 Guest are viewing this topic.
Offline evilion

Junior Newbie





« Posted 2010-04-30 13:45:59 »

Hey guys

I need your help

I am a begginer in Java3D and i read quite a lot Tutorials and tried some stuff to make.
Now i made a terrain out of a coordinates, which are in a DB. All works fine but i just cant get the texture over the whole terrain.

The texture is a real map.

This is my code snippet in which i set the geometry and the texture

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  
//grid is filled with coordinates taken out of a DB
// pts are the points of geometry, taken out of a grid
      for (int i = 0; i < grid.length - 1; i++) {
          for (int j = 0; j < grid[0].length - 1; j++) {
            pts[counter] = grid[i][j]; //top left corner
           counter++;

            pts[counter] = grid[i][j + 1]; //top right corner
           counter++;

            pts[counter] = grid[i + 1][j + 1]; //bottom right corner
           counter++;

            pts[counter] = grid[i + 1][j]; //bottom left corner
           counter++;
       
         }
      }

//geometry stuff
     GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
      gi.setCoordinates(pts);

//making strips
     Stripifier sp = new Stripifier();
      sp.stripify(gi);

//making normals
     NormalGenerator ng = new NormalGenerator();
      ng.setCreaseAngle((float) Math.toRadians(30));
      ng.generateNormals(gi);

//setting appearance
     Appearance aper = new Appearance();
      Material Mser = new Material();
      Mser.setShininess(0.01f);
      Mser.setEmissiveColor(0.0f, 0.0f, 0.0f);
      Mser.setAmbientColor(0.1f, 0.1f, 0.1f);
      aper.setMaterial(Mser);

//setting the texturecoordinates
     Vector4f planeS = new Vector4f((float)1.0/1800,0.0f, 0.0f, 0.0f);
      Vector4f planeT = new Vector4f(0.0f, 0.0f, (float)1.0/1800, 0.0f);
     
      TexCoordGeneration tcg = new TexCoordGeneration(
                  TexCoordGeneration.OBJECT_LINEAR,
                  TexCoordGeneration.TEXTURE_COORDINATE_2,
                  planeS,
                  planeT);
     
      aper.setTexCoordGeneration(tcg);
     
//loading texture
     TextureLoader texLoad = new TextureLoader("125.tif", null);
      ImageComponent2D textImage = texLoad.getImage();

//setting texture
     Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGB,
                                        textImage.getWidth(),
                                        textImage.getHeight());
      texture.setImage(0, textImage);

//setting texture attributes
     texture.setMinFilter(Texture.NICEST);
      texture.setMagFilter(Texture.NICEST);
      texture.setEnable(true);

      TextureAttributes texatt = new TextureAttributes(
            TextureAttributes.DECAL, new Transform3D(), new Color4f(1.0f,
                                                                    1.0f,
                                                                    1.0f,
                                                                    1.0f),
            TextureAttributes.NICEST);

//adding texture to appearance
     aper.setTextureAttributes(texatt);
      aper.setTexture(texture);

//give geometry and appearance the scene graph
     this.setGeometry(gi.getGeometryArray());
      this.setAppearance(aper);


before I used the TexCoordGeneration I had this:

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  
//set logical texture coordinates
//STEP = 2.0
for (int v = 0; v < textsint; v++) {
         //top left corner
        texts[v] = 0.0f;
         texts[++v] = 0.0f;

         //top right corner
        texts[++v] = 0.0f;
         //texts[++v] = widUnit;
        texts[++v] = (float) STEP;
 
         //bottom right corner
        //texts[++v] = lenUnit;
        texts[++v] = (float) STEP;
         //texts[++v] = widUnit;
        texts[++v] = (float) STEP;

         //bottom left corner
        //texts[++v] = lenUnit;
        texts[++v] = (float) STEP;  
         texts[++v] = 0.0f;
 
      }

//setting texturecoordinates
     gi.setTextureCoordinateParams(1, 2);
      gi.setTextureCoordinates(0, texts);

//setting texture and attributes
try {
         TextureLoader Texget = new TextureLoader(new java.net.URL(texture),
                                                  null);
         Texture2D ourTex = (Texture2D) Texget.getTexture();
         TextureAttributes texatt = new TextureAttributes(
               TextureAttributes.BLEND, new Transform3D(), new Color4f(1.0f,
                                                                       1.0f,
                                                                       1.0f,
                                                                       1.0f),
               TextureAttributes.NICEST);
         aper.setTextureAttributes(texatt);
         aper.setTexture(ourTex);
      }
      catch (java.net.MalformedURLException e) {
         System.err.println("error loading textures");
         e.printStackTrace();
      }


Now I got two questions
#1: How can I set the texturecoordinates, so one image covers the whole terrain?
#2: In TexCoordGeneration has planeS and T (and R, Q) and i searched in the internet for the meaning of the 4 parameters, which i can set... Vector4f planeS = new Vector4f(1.0f, 0.0f, 0.0f, 0.0f); Can someone tell me exactly for what does those 4 numbers stand?
-----EDIT:-----
k I found out what the first 3 parameters exactly do... x (length), y (height), z(width), w (wtf?)
-----------------

Here is a pic of my current situation:


The problem:

The texture is wrapped exactly 4 times on the terrain but it shouldnt be wrapped at all. And is think because of the wrap the texture flips, but I dont care about that now.

Can anyone please help me?
Offline evilion

Junior Newbie





« Reply #1 - Posted 2010-05-04 11:26:25 »

Ok I found out how and why

here is my code for it

1  
the code was too big for the post... I attached it


the "heart" of the code are the classes, which i copied from "Pro Java 6 3D Game Development"
My biggest problem in my early code was, that the geometry wasnt created as it should, thats why i never could put one image over the whole map.
hf gl
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.

pw (37 views)
2014-07-24 01:59:36

Riven (38 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00

Cero (60 views)
2014-07-16 00:42:17

Riven (57 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!