Walking on terrain

Started by
17 comments, last by GameDev.net 19 years, 1 month ago
don't know if anybody mentioned this, but i always thought
it would be possible to generate a grayscale "heightmap"
of the terrain, and then simply use the pixel values
as "heights".
it might be a retarded idea, but yeah, just thinking. :)
function(prototype);
Advertisement
then your guys movement is jerky because there is no transition between the altitudes
-----------------www.stevemata.com
i think it'll be easier to interpolate between two values given to you
than to interpolate between randomly placed vertices, dont you think? :)
function(prototype);
Quote:Original post by fproto
i think it'll be easier to interpolate between two values given to you
than to interpolate between randomly placed vertices, dont you think? :)


Heightmaps generally have the problem of being of discrete size and depth. The depth problem could be fixed using floating-point pixel format on the map, though, but the lack of arbitrary sized domain cannot easily be fixed (if at all).

Furthermore, triangle-ray collision works with any geometry of any size, and doesn't require uniform UV mapping (while a heightmap inherently does).

Niko Suni

wow lol. you're so right.
that never occurred to me.
stupid ideas of mine. =)
function(prototype);
Quote:Original post by fproto
wow lol. you're so right.
that never occurred to me.
stupid ideas of mine. =)


On the contrary, it is always a good idea to spend a healthy amount of time to research alternative solutions to problems. In this particular case, however, my experience on the matter just happens to strongly suggest that the heightmapping is not the most practical solution to the problem at hand.

Kind regards,
-Nik

Niko Suni

Now that you mention it, it occurs to me that there's probably something you could do using displacement mapping. You'd probably use it for your terrain in it's entirety, but if you're rendering a character, you bind the map to a texture stage, sample it in the vertex shader to get a height, and add that height to all vertices. That way the hardware does the interpolating for you.

Of course, sampling per-vertex is going to be very wasteful, given that you only really need to do it once per object. OK, ignore me. [grin]

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

unsigned int nPos = GetVertexIndex(int(floor((kPoint.X() - m_kBigBound.m_kMin.X()) / 7.5f)), int(floor((kPoint.Z() - m_kBigBound.m_kMin.Z()) / 7.5f)), m_uiWidth, m_uiHeight);			float lx = (kPoint.X() - m_akVertex[nPos].X());			float lz = (kPoint.Z() - m_akVertex[nPos].Z());			int	ix = floor(lx);			int	iz = floor(lz);			if (ix < 0) ix = 0;			if (ix > 1) ix = 1;			if (iz < 0) iz = 0;			if (iz > 1) iz = 1;			lx -= ix;			if (lx < 0) lx = 0;			if (lx > 1) lx = 1;						lz -= iz;			if (lx < 0) lz = 0;			if (lz > 1) lz = 1;			nPos = GetVertexIndex(int(0), int(0), m_uiWidth, m_uiHeight);			int cx = floor((kPoint.X() - m_akVertex[nPos].X()) / 7.5f);			int cz = floor((kPoint.Z() - m_akVertex[nPos].Z()) / 7.5f);			nPos = GetVertexIndex(int(cx), int(cz), m_uiWidth, m_uiHeight);			float s00, s01, s10, s11;			nPos = GetVertexIndex(int(cx), int(cz), m_uiWidth, m_uiHeight);			s00 = m_akVertex[nPos].Y();			nPos = GetVertexIndex(int(cx), int(cz + 1), m_uiWidth, m_uiHeight);			s01 = m_akVertex[nPos].Y();			nPos = GetVertexIndex(int(cx + 1), int(cz), m_uiWidth, m_uiHeight);			s10 = m_akVertex[nPos].Y();			nPos = GetVertexIndex(int(cx + 1), int(cz + 1), m_uiWidth, m_uiHeight);			s11 = m_akVertex[nPos].Y();			fHeight = (s00 * (1-lx) + s01 * lx) * (1 - lz) + (s10 * (1-lx) + s11 * lx) * lz;


Just to let you know i got it working with the above code, might help anyone else who's stuck.
PsYvIsIoN


I'm walking on sunshine...ohh ohh
I'm walking on sunshine...ohh ohh
And don't it feel good!



This topic is closed to new replies.

Advertisement