Creating grids

What is the best approach to creating grids like this?  See attached jpeg.

The user would then need the ability to rotate, pan, and zoom.



Most importantly, is JMonkey the right tool for building a viewer like this?

You can most certainly accomplish something along these lines in jME :slight_smile:



My guess is that you would be best suited by using the terrain functionality.  How exactly you implement this depends on how/where the data is coming from (a greyscale heightmap, numbers from a database, etc)

Data would be coming from an industry standard grid file with numbers. Thoughts on your approach? I am new to visualization. I have done some camera orientation using Open Inventor.



Thanks,

John

Well if you're using an ESRI grid file, getting the data out of there is fairly straight forward, then you just have to bring it into jME terrain :wink:



http://www.jmonkeyengine.com/wiki/doku.php/starter:hello_terrain



Pay special attention to this bit in that code:



private void homeGrownHeightMap() {
        // The map for our terrain.  Each value is a height on the terrain
        float[] map=new float[]{
            1,2,3,4,
            2,1,2,3,
            3,2,1,2,
            4,3,2,1
        };
 
        // Create a terrain block.  Our integer height values will scale on the map 2x larger x,
        //   and 2x larger z.  Our map's origin will be the regular origin.
        TerrainBlock tb=new TerrainBlock("block",4,
                new Vector3f(2,1,2),
                map,
                new Vector3f(0,0,0));
 
        // Give the terrain a bounding box.
        tb.setModelBound(new BoundingBox());
        tb.updateModelBound();
 
        // Attach the terrain TriMesh to our rootNode
        rootNode.attachChild(tb);
    }

Got it. A few questions.


  1. How do I define the cell sizes?
  2. How do I map a color to a cell?
  3. How would I rotate the grid when initializing it?
  4. How would I skew the grid to make it non-orthogonal?



    Thanks,

    John
jfuqua said:

Got it. A few questions.

1. How do I define the cell sizes?


The stepScale parameter will be of interest to you...  By using different X and Z values for the Vector3f passed in you can control the width and height of each individual TerrainBlock

jfuqua said:

2. How do I map a color to a cell?



terrainBlock.setSolidColor(ColorRGBA.blue);



jfuqua said:

3. How would I rotate the grid when initializing it?


The actual code:

terrainBlock.setLocalRotation(myQuaternion);



The explanation:
Objects are most easily rotated through the use of Quaternions.  There are some popular ones here

jfuqua said:

4. How would I skew the grid to make it non-orthogonal?


Unless I'm misunderstanding the question, it sounds like you're just trying to move the camera around the object, right?  Have a look into FirstPersonHandler.  It provides both mouse and keyboard control over the camera.

Hope this helps!

So you are saying that I should create a TerrainBlock for each cell in my grid?



More clarification for question 4. "How would I skew the grid to make it non-orthogonal?"

For example, the grid could be in the shape of a trapazoid rather than a parallelagram. This is what I meant by skewed.



Thanks for your great feedback.

jfuqua said:

So you are saying that I should create a TerrainBlock for each cell in my grid?


Yes, it will give you enough control over the 'important' side of the cell (the one facing up that the camera sees) without making you do all the work that goes into building your own TriMesh.  It also allows for you to use the terrain paging system in jME2.

jfuqua said:

More clarification for question 4. "How would I skew the grid to make it non-orthogonal?"
For example, the grid could be in the shape of a trapazoid rather than a parallelagram. This is what I meant by skewed.


That could be taken two ways :D  Since you mention non-orthogonal I believe you're saying that you want it to appear as a trapezoid instead of a parallelogram rather than the geometry actually being morphed and resized to a trapezoid.

The former is done by manipulating the the camera's frustum.  Think in terms of changing the viewport (and its associated field of view and aspect ratio) as opposed to changing the shape of the object for this method.

If you're interested in literally 'changing the shape of the grid' then you would likely want to start by playing with the stepScale parameter of TerrainBlock that I mentioned in the last post.  For the rows closest to the camera, make the X or Z value larger and gradually reduce that value as you go through the rows.  This would result in smaller individual blocks as they get further out.  Manipulating the camera will be simpler XD