L3DT documentation
Large 3D terrain generator

LibHFZ examples

Loading a file

#include "libhfz.h"

// declare some variables
float* pMyMap; // a handle to a float array, to be initialised by LibHFZ
hfzHeader fh;  // a LibHFZ header struct

// load the file
long rval = hfzLoadEx("myMapFile.hfz", fh, &pMyMap);
if(HFZ_STATUS_OK != rval) {
  // report error (using MFC; sorry!)
  CStringA TempStr;
  TempStr.Format("Error when loading: LibHFZ returned '%s' (code = %d)", hfzGetErrorStr(rval), rval);
  AfxMessageBox(TempStr);
}

// get width/height/scale
long width = fh.nx; // in pixels
long height = fh.ny; // in pixels
float HorizScale = fh.HorizScale; // in metres per pixel

// get value from a pixel (e.g. x,y = 50,12)
int x = 50;
int y = 12;
int k = x+y*width; // linearised index
float value = pMyMap[k]; // note: careful dev's should do a bounds check here!

// now clean-up once we're done
hfzHeader_Reset(fh); // deallocate header info
hfzFree(pMyMap); // release map data allocated by hfzLoadEx

A complete example

For a complete example of LibHFZ usage, please refer to the source code for the L3DTio_HFZ plugin for L3DT.

 
libhfz/examples.txt · Last modified: 2017/08/31 05:18 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki