Sign in to follow this  
  • entries
    132
  • comments
    99
  • views
    88618

Perspective Employers beware

Sign in to follow this  
Driv3MeFar

70 views

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(&vert, x, z));
verts[startIndex+1] = *(CreateVertex(&vert, x, z+1));
verts[startIndex+2] = *(CreateVertex(&vert, x+1, z+1));
verts[startIndex+3] = *(CreateVertex(&vert, x, z));
verts[startIndex+4] = *(CreateVertex(&vert, x+1, z+1));
verts[startIndex+5] = *(CreateVertex(&vert, 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;
}




Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now