Logic behind grid terrain
Is there an algorithm for this? Or a way to test to see if it works correctly? Any hints or advice is appreciated
Edit: the terrain is completely flat and made with jmonkeyengine, so it's a model type
You want the tiles to line up to the model / terrain. ie if your background is 640 x 640, than your 64 x 64 map holds 10 unit by 10 unit tiles.
I wouldn't really match up tile for tile on your terrain unless you have a per tile terrain system (ie like your 2d tiled rpgs where maps are made out of tile sets) which it sounds like you dont. If you just want to map a single textured quad to fit under all of your tiles just make the quad bounds match up in world space to your data structure bounds.
If your data structure is 1 by 1 tiles, then the whole thing is 64 by 64 in your world space coords, which means you need to figure out how to make your textured quad 64 by 64. Also your quad's center should be at 32, 32.
It depends on what libraries you are using on how you could do this. In my engine (c++) for example I would do something like
Entity * ent = engine->createResource<Entity>("terrain");
RenderComp * rcomp = ent->create<RenderComp>();
rcomp->setMeshID(engine->resource<Mesh>("1by1quad")->id());
rcomp->setMaterialID(0 /*submesh index*/, engine->resource<Material>("terrainmat")->id());
uint tformid = engine->currentScene()->add(ent,
fvec3(32.0f,32.0f,0.0f), // position in world coords
fquat(), // orientation
fvec3(64.0f, 64.0f, 1.0f) // scaling (64 times 1)
);
But what your using should have some sort of facility to translate and scale the quad geometry in the scene.
I think I understand what you're getting at.
I tried to draw what I'm thinking of. I suppose I don't really need "tiles", its just the first thing that came to mind. I need to set my points in my array to the little dots in the map. So nodes[0][0] would be the first point. If the map is 64x64 and its scaled by 1, I would set the center at .5 and .5, and then 1.5 and 1.5 for the next object in the array. If I can set the center points, creating a quadlike data structure should be a piece of cake.
class GridNode{
public final int x;
public final int y;
public GridNode(final int x, final int y)
{
this.x = x;
this.y = y;
}
}
This is what my array is to start with. It will need another variable to hold the center point and then a rectangle object if I decide I want to use it for some reason. JMonkeyEngine draws the center of the terrain at the origin (0, 0, 0), so in order to get the GridNode to line up correctly, I would have to offset it by a -32?
int offset = -32
GridNode[][]nodes = new GridNode[64][64];
for(int x = 0; x < nodes.length; x++){
for(int y = 0; y < nodes[0].length; y++){
nodes[x][y] = new GridSpace(x + offset, y + offset);
}
}