🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Perspective Employers beware

Published January 22, 2007
Advertisement
Well, I just got my ass handed to me in caps. First game 11-1, second 11-5. Basically, that means I've drank ~11 beers in ~2 hours. A winner is me!

Also, I realize this is about my third journal entry in about 24 hours. Hooray journal whoring! If you want anything meaningfull, read my previous two entries.

Anyway, to post something useful: there was a bug in my heightmap renderering code. Turns out I was drawing a quad to few for each row of the heightmap I was drawing. The real resuluts should look something like this:


And here's the new and improved Heightmap.cpp (which still needs documentation/cleanup):
#include "../Header Files/heightmap.h"#include "../Header Files/defines.h"#include "../Header Files/structs.h"#include "../Header Files/Renderer.h"extern CRenderInterface* g_renderer;Heightmap::Heightmap(unsigned numRows, unsigned numCols, unsigned width, unsigned depth, unsigned height) : m_numRows(numRows),									   m_numCols(numCols), 								           m_bitmap(NULL),									   m_bufferIndex(-1),									   m_width(width),									   m_depth(depth),									   m_height(height){}Heightmap::~Heightmap(){	SAFEDEL(m_bitmap);}int Heightmap::LoadHeightmap(std::string filename, HDC hdc){	SAFEDEL(m_bitmap);	m_bitmap = new CBitmap();	if ( !m_bitmap->LoadBitmap(filename, hdc) )	{		SAFEDEL(m_bitmap);		return FAIL;	}	int width = m_bitmap->GetWidth();	int height = m_bitmap->GetHeight();	m_xstep = width / m_numCols;	m_ystep = height / m_numRows;	return CreateVertsFromBitmap();}int Heightmap::Draw(){	g_renderer->Render(m_bufferIndex);	return 0;}MapVertex* Heightmap::CreateVertex(MapVertex *vert, int x, int z){	int lineNumber = z * m_ystep;	if (lineNumber == m_bitmap->GetHeight())	{		--lineNumber;	}	BYTE *line = m_bitmap->GetLinePtr(lineNumber);	int lineIndex = x * m_xstep;	if (lineIndex == m_bitmap->GetWidth())	{		--lineIndex;	}	int xdisp = m_width / m_numCols;	int zdisp = m_depth / m_numRows;	float y = (line[lineIndex * m_bitmap->GetChannels()] / 255.0f) * m_height;	vert->tv = static_cast<float>(z) / (m_numRows );	vert->tu = static_cast<float>(x) / (m_numCols);	vert->x = static_cast<float>(x * xdisp);	vert->y = y;	vert->z = static_cast<float>(z * zdisp);	vert->color = COLOR_ARGB(255, line[lineIndex * m_bitmap->GetChannels()], 0, 100);	return vert;}int Heightmap::CreateVertsFromBitmap(){	int numVerts = (m_numRows) * (m_numCols) * 6;	MapVertex *verts = new MapVertex[numVerts];	MapVertex vert = {0};	for (int z = 0; z < m_numRows; ++z)	{		for (int x = 0; x < m_numCols; ++x)		{			int startIndex =  GetIndexFromXZ(x, z) * 6;			verts[startIndex]	= *(CreateVertex(|, x,	 z));			verts[startIndex+1]	= *(CreateVertex(|, x,	 z+1));			verts[startIndex+2]	= *(CreateVertex(|, x+1, z+1));			verts[startIndex+3]	= *(CreateVertex(|, x,	 z));			verts[startIndex+4]	= *(CreateVertex(|, x+1, z+1));			verts[startIndex+5]	= *(CreateVertex(|, x+1, z));		}	}	return g_renderer->CreateStaticBuffer(MAP_FVF, TRIANGLE_LIST, numVerts, 0, 		sizeof(MapVertex), (void**)&verts, NULL, &m_bufferIndex);}inline int Heightmap::GetIndexFromXZ(int x, int z){	return (z * (m_numCols)) + x;}
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

/facepalm

1770 views

Baby Steps

1316 views

...

720 views

Stuff

1380 views

Productivity++

1248 views

Rock Band FTW

1277 views

Seattle Opera

1322 views

Christ

1245 views

I maek gaem!

1223 views
Advertisement