Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/importer/height_map.cc @ 9715

Last change on this file since 9715 was 9715, checked in by bensch, 18 years ago

renamed newclassid to classid and newobjectlist to objectlist

  • Property svn:executable set to *
File size: 20.8 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: bottac@ee.ethz.ch
13
14   review: patrick boenzli, patrick@orxonox.ethz.ch
15*/
16
17#include "height_map.h"
18#include "model.h"
19#include "texture.h"
20#include "vector.h"
21#include "material.h"
22#include "p_node.h"
23#include "state.h"
24#include "util/loading/resource_manager.h"
25#include "debug.h"
26
27// INCLUDING SDL_Image
28#ifdef HAVE_SDL_IMAGE_H
29#include <SDL_image.h>
30#else
31#include <SDL/SDL_image.h>
32#endif
33
34
35/**
36 * default constructor
37 *  @param xOffset
38 */
39Tile::Tile(int xOffset, int yOffset, int i2, int j2, HeightMap* heightMapReference )
40{
41  PRINTF(0)("Tile Constructor\n");
42
43  this->highResModel = new VertexArrayModel();
44  this->lowResModel  = new VertexArrayModel();
45
46  this->heightMapReference = heightMapReference;
47
48  // create high res model
49  this->load(xOffset, yOffset, i2, j2, this->highResModel, 4);
50  // create low res model
51  this->load(xOffset, yOffset, i2, j2, this->lowResModel, 8);
52}
53
54
55Tile::~Tile()
56{
57  if( highResModel)
58    delete highResModel;
59  if( lowResModel)
60    delete lowResModel;
61}
62
63
64/**
65 * this darws the tile in diefferent resolutions
66 */
67void Tile::draw()
68{
69  // draw the tile depending on the distance from the camera with different LOD (level of details)
70  float cameraDistance = fabs((State::getCameraNode()->getAbsCoor() - Vector(this->x, heightMapReference->offsetY , this->z) ).len());
71
72  if (cameraDistance < HM_LOD_HIGH_RES )
73  {
74    this->drawHighRes();
75  }
76  else if( cameraDistance < HM_LOD_LOW_RES)
77  {
78    this->drawLowRes();
79  }
80}
81
82
83/**
84 * loads a tile
85 */
86void Tile::load(int xOffset, int yOffset, int i2, int j2, VertexArrayModel* model, int sampleRate)
87{
88
89// #define heightMap this->heightMapReference->heightMap
90#define colors   this->heightMapReference->colors
91#define scaleX this->heightMapReference->scaleX
92#define scaleY this->heightMapReference->scaleY
93#define scaleZ this->heightMapReference->scaleZ
94#define shiftX this->heightMapReference->shiftX
95#define shiftY this->heightMapReference->shiftY
96#define shiftZ this->heightMapReference->shiftZ
97#define normalVectorField this->heightMapReference->normalVectorField
98
99
100  //FIXME: OLD implementation
101  this->x = this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((xOffset + i2) / 2)) * scaleX;
102  this->z = this->heightMapReference->offsetZ + ((yOffset + j2 ) / 2 ) * scaleZ;
103  //NEW:
104  this->setAbsCoor(this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((xOffset + i2) / 2)) * scaleX,
105                   0,
106                   this->heightMapReference->offsetZ + ((yOffset + j2 ) / 2 ) * scaleZ);
107
108
109  float height = 0;
110
111  float r = 0.0;
112  float g = 0.0;
113  float b = 0.0;
114
115
116  //if( this->heightMapReference->heightMap != NULL && this->heightMapReference->heightMap->format->BitsPerPixel == 8 )
117
118  SDL_LockSurface(this->heightMapReference->heightMap);
119  SDL_LockSurface(this->heightMapReference->colorMap);
120
121  for( int i = xOffset ; i <= i2  ; i +=sampleRate)
122  {
123    int w = 0;
124
125    // adjust the colors acoring to the color map
126    if( this->heightMapReference->hasColourMap)
127    {
128      r = colors[3 * w + 2 + 3 * i * this->heightMapReference->heightMap->w];
129      g = colors[3 * w + 1 + 3 * i * this->heightMapReference->heightMap->w];
130      b = colors[3 * w + 0 + 3 * i * this->heightMapReference->heightMap->w];
131    }
132
133    w = yOffset;
134
135//    PRINTF(0)("Values: i = %i, w = %i\n", i, w);
136
137    // add a vertex to the list
138    model->addVertex(scaleX * (this->heightMapReference->heightMap->h - i) + shiftX, shiftY, scaleZ * w + shiftZ); // Top Right
139    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].y,
140                     normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].z,
141                     normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].x);
142    model->addTexCoor((float)(yOffset-sampleRate) /(HM_TEX_RATE), (float)(i %this->heightMapReference->heightMap->h)/(HM_TEX_RATE));
143    model->addColor(r/255.0f, g/255.0f, b/255.0f);
144
145
146    for(int j = yOffset; j <= j2; j += sampleRate)
147    {
148      // adjust the colors acording to the color map
149      if( this->heightMapReference->hasColourMap)
150      {
151        r = colors[3 * j + 2 + 3 * i * this->heightMapReference->heightMap->w];
152        g = colors[3 * j + 1 + 3 * i * this->heightMapReference->heightMap->w];
153        b = colors[3 * j + 0 + 3 * i * this->heightMapReference->heightMap->w];
154      }
155      height =  (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + i * (this->heightMapReference->heightMap->w)];
156      height += (float)(unsigned char)this->heightMapReference->heights[j + 1 + sampleRate + (i + 1) *
157                                                                        this->heightMapReference->heightMap->w];
158      height += (float)(unsigned char)this->heightMapReference->heights[j - 1 + sampleRate + (i + 1) *
159                                                                        this->heightMapReference->heightMap->w];
160      height += (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + (i + 2) *
161                                                                        this->heightMapReference->heightMap->w];
162      height += (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + i * (this->heightMapReference->heightMap->w)];
163      height /= 5.0;
164
165      model->addVertex(scaleX * (this->heightMapReference->heightMap->h -i) + shiftX ,
166                       ((double)(height)*scaleY) + shiftY ,
167                       scaleZ*(j) + shiftZ); // Top Right
168      model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,
169                       normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].z,
170                       normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].x);
171      model->addTexCoor((float)(j) /(HM_TEX_RATE), (float)(i %this->heightMapReference->heightMap->h)/(HM_TEX_RATE));
172      model->addColor(r/255.0f, g/255.0f, b/255.0f);
173      //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %this->heightMapReference->h)/100.0);
174
175      w = j;
176    }
177    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
178    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].y,
179                     normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].z,
180                     normalVectorField[i% this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].x);
181    model->addTexCoor((float)(j2+sampleRate) /(HM_TEX_RATE), (float)(i %this->heightMapReference->heightMap->h)/(HM_TEX_RATE));
182    model->addColor(r/255.0f, g/255.0f, b/255.0f);
183  }
184
185  SDL_UnlockSurface(this->heightMapReference->heightMap);
186  int cnt = 0;
187
188  for( int i = xOffset; i < i2; i +=sampleRate)
189  {
190    for( int j = yOffset-sampleRate; j < j2  + 2 * sampleRate; j += sampleRate)
191    {
192      model->addIndice(cnt);
193      model->addIndice(cnt  + (j2 -yOffset + 3* sampleRate  )/ sampleRate );
194      cnt++;
195    }
196    model->newStripe();
197  }
198  cnt += (j2 -yOffset + 3* sampleRate)/ sampleRate;
199
200  for( int j = yOffset; j <= j2; j += sampleRate)
201  {
202    int i = xOffset;
203
204    // To be fixed
205    if(this->heightMapReference->hasColourMap)
206    {
207      r = (float)colors[3 * j + 2 + 3 * i * this->heightMapReference->heightMap->w];
208      g = (float)colors[3 * j + 1 + 3 * i * this->heightMapReference->heightMap->w];
209      b = (float)colors[3 * j + 0 + 3 * i * this->heightMapReference->heightMap->w];
210    }
211
212    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX ,
213                     shiftY ,
214                     scaleZ*(j) + shiftZ); // Top Right
215    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,
216                     normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].z,
217                     normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].x);
218    model->addTexCoor((float)j /(HM_TEX_RATE), (float)((i - sampleRate) %this->heightMapReference->heightMap->h)/(HM_TEX_RATE));
219    model->addColor(r/255.0f, g/255.0f, b/255.0f);
220  }
221
222
223  for(int j = yOffset  ; j <= j2    ;  j += sampleRate)
224  {
225    int i = xOffset;
226    height =  (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + i * this->heightMapReference->heightMap->w];
227    height += (float)(unsigned char)this->heightMapReference->heights[j + 1 + sampleRate + (i + 1) *
228                                                                      this->heightMapReference->heightMap->w];
229    height += (float)(unsigned char)this->heightMapReference->heights[j - 1 + sampleRate + (i + 1) *
230                                                                      this->heightMapReference->heightMap->w];
231    height += (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + (i + 2) *
232                                                                      this->heightMapReference->heightMap->w];
233    height += (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + i * this->heightMapReference->heightMap->w];
234    height=height/5.0;
235
236    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX ,
237                     ((double)(height)*scaleY) +shiftY ,
238                     scaleZ*(j) + shiftZ); // Top Right
239    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,
240                     normalVectorField[i % this->heightMapReference->heightMap->h][j% this->heightMapReference->heightMap->w].z,
241                     normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x);
242    model->addTexCoor((float)j /(HM_TEX_RATE), (float)(i %this->heightMapReference->heightMap->h)/(HM_TEX_RATE));
243    model->addColor(r/255.0f, g/255.0f, b/255.0f);
244  }
245
246
247  for(int j = yOffset; j <= j2; j += sampleRate)
248  {
249    int i = i2;
250    // To be fixed
251    if( this->heightMapReference->hasColourMap)
252    {
253      r = (float)colors[3 * j + 2 + 3 * i * this->heightMapReference->heightMap->w];
254      g = (float)colors[3 * j + 1 + 3 * i * this->heightMapReference->heightMap->w];
255      b = (float)colors[3 * j + 0 + 3 * i * this->heightMapReference->heightMap->w];
256    }
257
258    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX ,
259                     shiftY ,
260                     scaleZ*(j) + shiftZ); // Top Right
261    model->addNormal(normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].y,
262                     normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].z,
263                     normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x);
264    model->addTexCoor((float)j /(HM_TEX_RATE), (float)((i+ sampleRate) %this->heightMapReference->heightMap->h)/(HM_TEX_RATE));
265    model->addColor(r/255.0f, g/255.0f, b/255.0f);
266  }
267
268
269  for(int j = yOffset; j <= j2; j += sampleRate)
270  {
271    int i = i2;
272    height =  (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + i * this->heightMapReference->heightMap->w];
273    height += (float)(unsigned char)this->heightMapReference->heights[j + 1 + sampleRate + (i + 1)
274                                                                      * this->heightMapReference->heightMap->w];
275    height += (float)(unsigned char)this->heightMapReference->heights[j - 1 + sampleRate + (i + 1) *
276                                                                      this->heightMapReference->heightMap->w];
277    height += (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + (i + 2) *
278                                                                      this->heightMapReference->heightMap->w];
279    height +=  (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + i * this->heightMapReference->heightMap->w];
280    height /= 5.0;
281    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX ,
282                     ((double)(height)*scaleY) +shiftY ,
283                     scaleZ*(j) + shiftZ); // Top Right
284    model->addNormal(normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].y,
285                     normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].z,
286                     normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x);
287    model->addTexCoor((float)j /(HM_TEX_RATE), (float)(i %this->heightMapReference->heightMap->h)/(HM_TEX_RATE));
288    model->addColor(r/255.0f, g/255.0f, b/255.0f);
289  }
290
291  // link Boarder Stripe
292  for(int j = yOffset - sampleRate; j < j2; j += sampleRate)
293  {
294    model->addIndice(cnt);
295    model->addIndice(cnt + (j2 - yOffset + sampleRate) / sampleRate );
296    cnt++;
297  }
298  cnt++;
299
300
301  model->newStripe();
302
303
304  cnt += (j2-yOffset)/ sampleRate;
305  // link 2nd BoarderStripe
306  for(int j = yOffset-sampleRate; j < j2;  j += sampleRate)
307  {
308    model->addIndice(cnt);
309    model->addIndice(cnt + (j2 - yOffset + sampleRate) / sampleRate);
310    cnt++;
311  }
312
313  SDL_UnlockSurface(this->heightMapReference->colorMap);
314
315  model->finalize();
316
317// #undef heightMap
318        #undef colors
319        #undef scaleX
320        #undef scaleY
321        #undef scaleZ
322        #undef shiftX
323        #undef shiftY
324        #undef shiftZ
325        #undef normalVectorField
326}
327
328
329ObjectListDefinition(HeightMap);
330
331
332/**
333 * constructor
334 *  @param heightMapName file name of the height map
335 */
336HeightMap::HeightMap(const std::string& heightMapName)
337    : VertexArrayModel()
338{
339  this->init(heightMapName);
340
341  this->colorMap = NULL;
342}
343
344
345/**
346 * constructor
347 *  @param heightMapName file name of the height map
348 *  @param colorMapName file name of the color map
349 */
350HeightMap::HeightMap(const std::string& heightMapName, const std::string& colorMapName)
351    : VertexArrayModel()
352{
353  this->init(heightMapName);
354
355  this->colorMap = IMG_Load(colorMapName.c_str());
356  if( this->colorMap != NULL)
357  {
358    PRINTF(0)("loading Image %s\n", colorMapName.c_str());
359    PRINTF(0)("width : %i\n", this->colorMap->w);
360    PRINTF(0)("height : %i\n", this->colorMap->h);
361    PRINTF(0)("%i Byte(s) per Pixel \n", this->colorMap->format->BytesPerPixel);
362    PRINTF(0)("Rshift : %i\n", this->colorMap->format->Rshift);
363    PRINTF(0)("Bshift: %i\n", this->colorMap->format->Bshift);
364    PRINTF(0)("Gshift: %i\n", this->colorMap->format->Gshift);
365    PRINTF(0)("Rmask: %i\n", this->colorMap->format->Rmask);
366    PRINTF(0)("Gmask: %i\n", this->colorMap->format->Gmask);
367
368    this->colors = (unsigned char *) colorMap->pixels;
369    this->hasColourMap = true;
370  }
371  else
372  {
373    PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
374    this->hasColourMap = false;
375  }
376}
377
378
379/**
380 * deconstructor
381 */
382HeightMap::~HeightMap()
383{
384  if( heightMap)
385    delete heightMap;
386  if( colorMap)
387    delete colorMap;
388
389  if( this->tiles)
390  {
391    for( int i = 0; i < heightMap->h / HM_TILE_SIZE; i++) {
392      for( int j = 0; j < heightMap->w / HM_TILE_SIZE; j++) {
393        delete tiles [i][j];
394      }
395    }
396
397    for( int i = 0; i < heightMap->h / HM_TILE_SIZE; i++)
398      delete[] tiles[i];
399    delete[] tiles;
400  }
401
402  if( this->normalVectorField)
403  {
404    for(int i = 0; i < heightMap->h; i++)
405      delete[] normalVectorField[i];
406    delete[] normalVectorField;
407  }
408}
409
410
411/**
412 * this is the init function with stuff shared between all constructors
413 */
414void HeightMap::init(const std::string& heightMapName)
415{
416  this->registerObject(this, HeightMap::_objectList);
417
418  this->shiftX = 0;
419  this->shiftY = 0;
420  this->shiftZ = 0;
421
422  heightMap =  IMG_Load(heightMapName.c_str());
423  if( heightMap != NULL)
424  {
425    /*
426    WHAT about following checks:
427    - image size (rectangular?)
428    - image file type (bw?)
429    */
430    PRINTF(1)("loading Image %s\n", heightMapName.c_str());
431    PRINTF(1)("width : %i\n", heightMap->w);
432    PRINTF(1)("height : %i\n", heightMap->h);
433    PRINTF(1)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
434    PRINTF(1)("Rshift : %i\n", heightMap->format->Rshift);
435    PRINTF(1)("Bshift: %i\n", heightMap->format->Bshift);
436    PRINTF(1)("Gshift: %i\n", heightMap->format->Gshift);
437    PRINTF(1)("Rmask: %i\n", heightMap->format->Rmask);
438    PRINTF(1)("Gmask: %i\n", heightMap->format->Gmask);
439  }
440  else
441    PRINTF(1)("oops! couldn't load %s for some reason.\n", heightMapName.c_str());
442
443  this->generateNormalVectorField();
444
445  this->heights = (unsigned char*)heightMap->pixels;
446}
447
448
449/**
450 * this function loads the heightmap by creatin tiles
451 */
452void HeightMap::load()
453{
454  // create a dynamicly sized 2D-array for tiles
455  this->tiles =  new Tile**[this->heightMap->h / HM_TILE_SIZE];
456
457  for( int i = 0;i < heightMap->h / HM_TILE_SIZE; i++)
458    this->tiles [i]= new Tile*[this->heightMap->w / HM_TILE_SIZE];
459
460  // setup arrays
461  for( int i = 0; i < this->heightMap->h / HM_TILE_SIZE; i++)  {
462    for( int j = 0; j < this->heightMap->w / HM_TILE_SIZE; j++) {
463      this->tiles[i][j] = new Tile( i * HM_TILE_SIZE ,  j * HM_TILE_SIZE , (i+1) * HM_TILE_SIZE, (j+1) * HM_TILE_SIZE , this);
464    }
465  }
466}
467
468
469/**
470 * this function draws the height map
471 */
472void HeightMap::draw() const
473{
474  Vector v = State::getCameraNode()->getAbsCoor();
475
476  int i_max = (heightMap->h )/ HM_TILE_SIZE;
477  int j_max= (heightMap->) / HM_TILE_SIZE;
478
479
480
481  /* process the draw command to the tiles, FIXME: think of something more efficient*/
482  for( int i = 0; i < i_max; i++)  {
483    for( int j = 0; j < j_max; j++)  {
484      tiles[i][j]->draw();
485    }
486  }
487}
488
489
490/**
491 * this function generates the normal vector field
492 */
493void HeightMap::generateNormalVectorField()
494{
495  int delta = 1;
496  heights  = (unsigned char*) heightMap->pixels;
497
498  //Create a Dynamicly sized 2D-Array to store our normals
499  normalVectorField =  new Vector* [heightMap->h];
500  for(int i=0;i<heightMap->h;i++)
501    normalVectorField [i]= new (Vector [heightMap->w]);
502
503  // Initialize
504  for(int i=0; i< heightMap->h; i++)
505  {
506    for(int j = 0; j> heightMap->w; j++)
507    {
508      Vector v = Vector(0.0, 1.0, 0.0);
509      normalVectorField[i][j] = v;
510    }
511  }
512
513  // !!! Does not yet calculate the normals of some border points!!!!!
514
515  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
516  {
517    SDL_LockSurface(heightMap);
518    for(int i = 0 ; i < heightMap->h - 1  ; i ++)
519    {
520      for(int j = 0; j < heightMap->- 1  ;  j ++)
521      {
522
523
524        delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
525        Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
526
527        delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
528        Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
529
530
531        normalVectorField[i][j] = b.cross(a);
532        normalVectorField[i][j].normalize();
533
534      }
535    }
536    SDL_UnlockSurface(heightMap);
537
538  }
539}
540
541
542/**
543 * scales the height map about a vector
544 *  @param v scaling vector
545 */
546void HeightMap::scale(Vector v)
547{
548  scaleX = v.x;
549  scaleY = v.y;
550  scaleZ = v.z;
551  generateNormalVectorField();
552}
553
554
555/**
556 * sets the absolute coordinates of the height map
557 *  @param v the moving vector
558 */
559void HeightMap::setAbsCoor(Vector v)
560{
561  offsetX = v.x;
562  offsetY = v.y;
563  offsetZ = v.z;
564}
565
566
567/**
568 * returns the height at a given 2D coordinate
569 *  @param x x coordinate of the height map (world space)
570 *  @param y y coordinate of the height map (world space)
571 *  @return the height (z)
572 */
573float HeightMap::getHeight(float x, float y)
574{
575  x -= offsetX;
576  y -= offsetZ;
577
578  int xInt = (int)( x / scaleX);
579  x -= (float)((int)x);
580  xInt = heightMap->h - xInt;
581  int yInt = (int)( y / scaleZ);
582  y -= (float) ((int) y); /*yInt = heightMap->w - yInt;*/
583
584  //PRINTF(0)("xInt: %i, yInt: %i, x: %f, y: %f\n", xInt, yInt, x, y);
585
586  if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->)
587    return 0;
588  if( y >= 0.5*x)
589  {
590    // Check for ...
591  }
592
593  float height = heights[yInt + (xInt)*heightMap->w]*scaleY;
594
595  float a = normalVectorField[(xInt)][yInt].x;
596  float b = normalVectorField [(xInt)][yInt].z;
597  float c = normalVectorField [(xInt)][yInt].y;
598
599//  PRINTF(0)("a: %f \n" ,a);
600//  PRINTF(0)("b: %f \n" ,b);
601//  PRINTF(0)("c: %f \n" ,c);
602
603
604  height -= ( (a/c)*(x) + (b/c)*(y));
605
606  // PRINTF(0)("height: %f \n" ,height );
607  return (height + offsetZ);
608
609}
Note: See TracBrowser for help on using the repository browser.