Monday, June 4, 2012

Physics and Terrain

For the collision detection, jMonkeyEngine does most of the heavy work, which is very nice!  All the user must do is add bounding shapes over the object they want to have physics applied to, and then register those objects with the physics engine.  Also, its very important to change the way you move that object and go through the physics engine, not through the setLocalTranslation() method.

Terrain in JME is handles through the use of height maps and texture splatting maps.  Instead of storing every single point in the terrain's height, we just make a much smaller map of the height of the terrain and interpolate that map across the much larger game terrain.  Here is an example of a height map:

The whiter the color, the higher the terrain.  Thus, this map makes a mountain in the middle of the terrain, with another steeper peak in the top left.

Texture Splatting is similar in concept.  There is a small map of colors that determine which texture will be loaded to that area of the terrain.  For example, if you assign the color red to mean load a grass.png texture and blue to load ice.png, then the above height map will have blue where the peaks are and read where the valleys are.

That wraps up the tutorials for now, next I will begin to create the Wind Explorer game!

The first thing I worked on is seeing how to setup and load a scene.  Scenes are an organization of objects that can be quickly loaded into the game engine with two lines of code.  Behold:



Blue Pies!  These three pies were loaded into the initApp() function at those locations with only this code:

Spatial scene = assetManager.loadModel("Scenes/pie.j3o");
rootNode.attachChild(scene);

Scenes themselves have a graphical editor to them, making building of a game a little less trial and error.  Here is a picture of what the scene editor looks like:


 More to come!

4 comments:

  1. Very nice. Look forward to seeing your initial terrain design for the game. Do you think we'll stay in one terrain or allow the player to jump from one world to another?

    ReplyDelete
    Replies
    1. I was planning on having a main menu that can load different levels, each with a increasing difficulty.

      Delete
  2. Did you check out these two sites about terrain:
    http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:endless_terraingrid
    http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:terrain

    ReplyDelete
    Replies
    1. Thank you for the links, they were useful today!

      The only thing I had trouble with is that there seems to be a bug in the jmonkeyengine when adding a bounding box to the terrain. The terrain starts culling (disappearing) while still in view. I found a forum post about this, and no one had a fix, so I just did not put a bounding box on the terrain for now.

      Delete