Hey all,
I've tried to adapt kaedroho's dbpro code for applying a heightmap to a geosphere, to darkgdk and an exported plain (.x) instead of a sphere.
void ApplyHeightmap(int objectid,int imgnum,float min,float max)
{
dbMakeMemblockFromImage(1,imgnum);
int hwidth = dbMemblockDword(1,0);
int hheight = dbMemblockDword(1,4);
dbLockVertexDataForLimb(1,1,1);
for (int i = 0; i < dbGetVertexDataVertexCount(); i++)
{
float u = dbGetVertexDataU(i);
float v = dbGetVertexDataV(i);
int x = floor(u * hwidth);
if (x >= hwidth)
{
x = hwidth - 1;
}
if (x < 0)
{
x = 0;
}
int y = floor(v * hheight);
if (y >= hheight)
{
y = hheight - 1;
}
if (y < 0)
{
y = 0;
}
int position = 12 + (x+y*(hwidth-1))*4;
float height = min + dbRGBB(dbMemblockDword(1,position))*((max-min)/255.0);
float vertx = dbGetVertexDataPositionX(i);
float verty = height;
float vertz = dbGetVertexDataPositionZ(i);
dbSetVertexDataPosition(i,vertx,verty,vertz);
}
dbUnlockVertexData();
dbDeleteMemblock(1);
}
dbLoadObject("Media/terrainPlain.x",1);
dbPositionObject(1,512,0,512);
dbRotateObject(1,0,180,0);
ApplyHeightmap(1,5,0,1000);
I have been staring at this for a while now and can't understand why it isn't working. There is no error message, the application runs fine with this code but the heightmap is not applied to the object.
Any help would be greatly appreciated.
Cheers
EDIT:
kaedroho's original code can be found in this thread:
http://forum.thegamecreators.com/?m=forum_view&t=154121&b=1
EDIT 2:
Please ignore this post, I found my problem.
I wasn't calling the function in my main game loop. /facepalm