Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HeightMapInfo Struct Reference

#include <quadsquare.h>

Public Member Functions

float Sample (int x, int z, float &texture) const
 

Public Attributes

short * Data
 
unsigned char * terrainmap
 
int XOrigin
 
int ZOrigin
 
unsigned long XSize
 
unsigned long ZSize
 
unsigned int RowWidth
 
int Scale
 

Detailed Description

Definition at line 55 of file quadsquare.h.

Member Function Documentation

float HeightMapInfo::Sample ( int  x,
int  z,
float texture 
) const

Definition at line 445 of file quadsquare.cpp.

References float, x, and z.

Referenced by quadsquare::AddHeightMapAux().

450 {
451  //Break coordinates into grid-relative coords (ix,iz) and remainder (rx,rz)
452  int ix = (x-XOrigin)>>Scale;
453  int iz = (z-ZOrigin)>>Scale;
454  int mask = (1<<Scale)-1;
455  int rx = (x-XOrigin)&mask;
456  int rz = (z-ZOrigin)&mask;
457  int ixpp = ix+1;
458  int izpp = iz+1;
459  if (ix < 0) {
460  ix = 0;
461  ixpp = 0;
462  }
463  if ( ix >= (int) (XSize-1) ) {
464  ix = XSize-1;
465  ixpp = XSize-1;
466  }
467  if (iz < 0) {
468  iz = 0;
469  izpp = 0;
470  }
471  if ( iz >= (int) (ZSize-1) ) {
472  iz = ZSize-1;
473  izpp = ZSize-1;
474  }
475  float fx = float(rx)/(mask+1);
476  float fz = float(rz)/(mask+1);
477  float s00 = Data[ix+iz*RowWidth];
478  float s01 = Data[(ixpp)+iz*RowWidth];
479  float s10 = Data[ix+(izpp)*RowWidth];
480  float s11 = Data[(ixpp)+(izpp)*RowWidth];
481  float t00 = texturelookup[terrainmap[ix+iz*RowWidth]];
482  float t01 = texturelookup[terrainmap[(ixpp)+iz*RowWidth]];
483  float t10 = texturelookup[terrainmap[ix+(izpp)*RowWidth]];
484  float t11 = texturelookup[terrainmap[(ixpp)+(izpp)*RowWidth]];
485  texture = (t00*(1-fx)+t01*fx)*(1-fz)
486  +(t10*(1-fx)+t11*fx)*fz;
487  return (s00*(1-fx)+s01*fx)*(1-fz)
488  +(s10*(1-fx)+s11*fx)*fz;
489 }

Member Data Documentation

short* HeightMapInfo::Data

Definition at line 57 of file quadsquare.h.

unsigned int HeightMapInfo::RowWidth

Definition at line 61 of file quadsquare.h.

int HeightMapInfo::Scale

Definition at line 62 of file quadsquare.h.

Referenced by quadsquare::AddHeightMapAux().

unsigned char* HeightMapInfo::terrainmap

Definition at line 58 of file quadsquare.h.

int HeightMapInfo::XOrigin

Definition at line 59 of file quadsquare.h.

Referenced by quadsquare::AddHeightMapAux().

unsigned long HeightMapInfo::XSize

Definition at line 60 of file quadsquare.h.

Referenced by quadsquare::AddHeightMapAux().

int HeightMapInfo::ZOrigin

Definition at line 59 of file quadsquare.h.

Referenced by quadsquare::AddHeightMapAux().

unsigned long HeightMapInfo::ZSize

Definition at line 60 of file quadsquare.h.

Referenced by quadsquare::AddHeightMapAux().


The documentation for this struct was generated from the following files: