Tuesday, April 28, 2015

opengl es - Tile map/terrain implementation with differing heights of neighbouring tiles


Ahoy!


I'm looking for some information about tile maps, or rather, what a specific type of tile map is called.



I'm interested in the kind of implementation used in rollercoaster tycoon, or the transport tycoon series of games and have been looking into vector field terrain and height map terrain but i'm not sure they're suitable for what i'm looking to develop.


It's been a struggle to find any decent info as most people refer to it as an isometric tile map, but I'm looking to create something in 3D with a fixed orthographic perspective. I understand that the underlying storage of the tile map has nothing to do with how it is rendered but i'm not looking to create a 2D tile map like old school pokemon/zelda games, more along the lines of diablo with the capability to include overhanging cliffs and sloping terrain.


I'm just trying to find the right terms to search google and stackoverflow for resources to help me decide which path to proceed.


So far i've managed to flesh out a basic tile map without using the height/y component stored in a VBO and rendered as a wireframe. This looks fine so far but I envisage that I will encounter problems when trying to manipulate a single vertex to create cliffs and slopes without affecting a neighbouring tile.


Is there a specific type of implementation I should be looking into? I thought i'd cracked it when I found a fair amount if info on vector field terrain but i'm not sure this would yield the correct results either.


If anyone can shed some light on this for me please, the help would be greatly appreciated :)


Update


I've included an image for further clarification as to what i'd like to achieve:


2.5D tile map


Image borrowed from How to create tilted (height) isometric tiles



This image shows the type of terrain i'd like to generate but doesn't include the "cliffs" or overhanging terrain types i'm interested in modelling. It does however raise a few other questions I hadn't considered, namely;



  • How would 'layers' such as the water (top left of the image) be handled to include the visible ground underneath the water?

  • How would the "edges" of the map be catered for so that the earth/mud is rendered to depict the world as a non-flat entity?

  • Could the underlying storage for this kind of terrain be used to model physics such as a ball rolling down a hill or movement speeds of a player traversing a slope?


I had an idea in that each tile of the terrain could be modelled with 8 vertices where the 4 main vertices cover the actual tile itself and the remaining 4 vertices are used to model the sides/walls of each tile. The two problems I see with this implementation is that a) the world map is essentially doubled in size and b) given that not all tiles will include "walls", some tiles will end up with redundant vertices which are not used.


I'd like to create a terrain editor which allows for each tile to be deformed as well as including the ability to change the terrain during game play. This in itself poses additional questions such as; Can a VBO be used to store and render the terrain whilst being modified on the fly and also, is it possible to modify vertices without affecting neighbouring tiles?


I'm under the impression that i'm either over-complicating things or running into analysis-paralysis in that i'm neglecting to write any code to solve the problem without having a clear idea of how I would achieve what I want.


Again, i'm really just looking for a shove in the right direction with this. Is there a specific type of tilemap/terrain implementation that would cater for a 3D map to be deformed by both a map editor as well as during gameplay or do I have to roll my own, so to speak? I'm not trying to reinvent the wheel here but I am struggling to find any resources given that I'm not sure what to be searching for.



If anyone can provide any info, resources or snippets of code, that would be hugely appreciated as i'm eager to get my hands dirty and start producing something other than the flat wireframe I currently have.


Thanks for reading!



Answer



If I were you I'd look into voxels, more specifically Minecraft-type cube rendering. Unlike heightmaps, they can handle overhangs, caverns, buildings with multiple floors, etc.


You'd store your terrain in a 3D array of integers, where numbers are mapped to a certain type of terrain: 0=air, 1=dirt, 2=water, etc. Then, to create the mesh to render, you'd create the faces of a cube for each non-empty voxel.


This tutorial is a great explanation of how to do this in C++ using Ogre3D. I presume you'd have to go a little more low-level in OpenGL.


After creating the cubes, you'd want to smooth the edges to create the kind of fluid terrain shown in your image. I believe PolyVox (also in C++) does this; you could take a look at their code. I think you basically do in 3D what the image shows in 2D: average the surrounding cube positions to know where to place each vertex.


EDIT:



  • Generate the faces for the cubes adjacent to water as if the water tile was empty, and render the water faces transparently.


  • Faces on the "edge" can be generated just like regular faces, if you consider voxels outside the world to be empty.

  • Physics: You can probably feed the rendered mesh to your physics engine as a static object.

  • Map editor: You'd want to edit the underlying voxel data, not the mesh itself! (The mesh should mirror the data, so editing the voxels should produce changes in your mesh.) You might want to look up Model, View, Controller (MVC) if you're not familiar with it.


If you have more questions, feel free to leave a comment. Welcome to gamedev.SE!


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...