TerrainBlock

Hey! I am trying to follow the terrainBlock example on the wiki :



public void buildTerrain(){
      
      // Generate a random terrain data
      MidPointHeightMap heightMap = new MidPointHeightMap(64, 1f);
      // Scale the data
      Vector3f terrainScale = new Vector3f(20, 0.5f, 20);
      // create a terrainblock
      tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
            heightMap.getHeightMap(), new Vector3f(0, 0, 0), false);
 
      tb.setModelBound(new BoundingBox());
      tb.updateModelBound();
 
      // generate a terrain texture with 3 textures
      ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
            heightMap);
      pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader()
            .getResource("jmetest/data/texture/grassb.png")), -128, 0, 128);
      pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader()
            .getResource("jmetest/data/texture/dirt.jpg")), 0, 128, 255);
      pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader()
            .getResource("jmetest/data/texture/highest.jpg")), 128, 255,
            384);
      pt.createTexture(32);
      
      // assign the texture to the terrain
      TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      Texture t1 = TextureManager.loadTexture(pt.getImageIcon().getImage(),
            Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR, true);
      ts.setTexture(t1, 0);
 
      tb.setRenderState(ts);

   }



I am using jme2 and it seems the constructor for terrainBlock has been changed and the line :

tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
heightMap.getHeightMap(), new Vector3f(0, 0, 0), false);

claims the arguments dont match any constructor.

Any ideas?

Also ImageIcon also doesnt appear to have been defined - inless this refers to the java.swing ImageIcons?

Thanks in advance guys,

Andy

The terrain block seems to want an int[] for the heightmap parameter- however MidPointHeightMap returns a float[] for the heightmap!?



This seems confused :S

You could just scale the floats up, convert to int, then scale the geometry smaller to compensate. I think that has been mentioned before.

(1280, 32, 1280) certainly makes sense in local coordinates. Does your terrain have any translation from (0,0,0)? That would change the midpoint in world coordinates. I guess it really depends on the parameters passed into the constructor, if one size unit really == one jme unit.

I fixed that problem thanks to IRC!



Didnt need the constructor boolean value.



Anyway.



I am trying to find the center of my TerrainBlock, was thinking:



If MidpointHeightMap size = 128,



scale is : 20,0.5,20 then it would be in vector3f terms:



1280,32,1280 - this is defintely wrong!



How can I tell the dimensions of the terrain block!? :smiley:

Also check that Y is up in your camera/frustrum setup

Im not sure how to check if y is up , im guesing it is:




private void cameraFrame() {
       Vector3f loc = new Vector3f(250.0f, 100.0f, 250.0f);
        Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
        Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
        Vector3f dir = new Vector3f(0.0f, 0.0f, -1.0f);
        camera.setFrame(loc, left, up, dir);
    }

 private void cameraPerspective() {
        camera.setFrustumPerspective(45.0f, (float)display.getWidth() / (float)display.getHeight(), 1.0f, 1000.0f);
        camera.setParallelProjection(false);
        camera.update();
    }




-1280,-32,-1280 doesnt position it in the center of the map. I cannot even find it!  its - because the origin of the node, being 0,0,0 is the bottom left hand corner and thus -values to go back from here.

Help!

It should expand from (0,0,0) along the positive axes, with the far corner being

(mapscalesize), (mapscalevalue), (scale*mapsize)



If your map is size 128 and scale 20 then you should be right with 1280 for the middle.

Your y position will depend on the map itself of course, have you checked you are actually above the terrain?

so if the terrain was 128,



scaled to 20,0.5,20



i want to position my object at (1280,32,1280)?



I am fairly usre its above it, but i have looked underneath the terrain just to be sure also!

Just for kicks, you should add a box with a first person handler and walk the box over to where you believe the center is. Use system.out to print the location of the box. Might give some insight.

wouldnt just getting the camera location work just the same?

yes, it would give you a location in world space. If you wanted to get it in coordinates relative to the terrain, you could use the box approach and attach it to the terrain node instead of the root.

well i dont think you can attach children to the terrainblock node…

Ah, you're right. Unless you have translated your terrain away from 0,0,0 then word coordinates from the camera should be good enough information.



I'm just trying to help you figure out what the middle may be, and hopefully understand why that is.

Might also be worth doing an updateWorldVectors or whatever just to make sure the object is actually showing where you put it.

Hmm finally work it out to be :



towerNode.setLocalTranslation(new Vector3f(-1280,32,1280));

renegadeandy said:

Hmm finally work it out to be :

towerNode.setLocalTranslation(new Vector3f(-1280,32,1280));



Ah, the old right handed coordinate system