Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // hmap.halfww is world width / 2
- // hmap.ww is world width
- // get the wrapped coordinates relative to ax, az (and store them in wp)
- void setWrapPos(float ax, float az,
- float bx, float by, float bz,
- gamex::xVec3f & wp)
- {
- wp.x = bx; wp.z = bz; wp.y = by;
- if ( (bx - ax) > hmap.halfww ) { wp.x -= hmap.ww;}
- else if ( (bx - ax) < -hmap.halfww ) { wp.x += hmap.ww;}
- if ( (bz - az) > hmap.halfwh ) { wp.z -= hmap.wh;}
- else if ( (bz - az) < -hmap.halfwh ) { wp.z += hmap.wh;}
- }//setwrappos
- //check if the coordinates need to be wrapped around
- void checkWrapPos(float & ax, float & az)
- {
- if (ax < 0.0f ) { ax += hmap.ww; }
- else if (ax > hmap.ww ) { ax -= hmap.ww; }
- if (az < 0.0f ) { az += hmap.wh; }
- else if (az > hmap.wh ) { az -= hmap.wh; }
- }//checkwrap
- // mw is terrain width in number of vertices
- // needs to be power of 2 ( 2, 4, 8, 16, 32 .. 256 etc) for bitwise-AND trick to work
- float
- xHeightMap::getHeightAt(int ax, int az)
- {
- ax &= (mw-1); //32 mw -> 31
- az &= (mh-1);
- return vecHeight[ax+(az*mw)];
- }//getheightat
- void
- xHeightMap::setHeightAt(int ax, int az, float h)
- {
- ax &= (mw-1); //32 mw -> 31
- az &= (mh-1);
- vecHeight[ax+(az*mw)] = h;
- }//getheightat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement