Main Page | Modules | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

adsoheightmap.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * $Id: adsoheightmap.h,v 1.6 2003/06/27 08:36:41 schou Exp $
00003  * Author: Jakob Schou Jensen <schou@sourceforge.net>
00004  * Licence: GPL
00005  *
00006  * Description: Adso height map
00007  *
00008  ****************************************************************************/
00009 
00010 #ifndef ADSOHEIGHTMAP_H
00011 #define ADSOHEIGHTMAP_H
00012 #include <stdio.h>
00013 #include <adsobase.h>
00014 #include <adsomath.h>
00015 
00017 class AdsoHeightMap {
00018   float *array;
00019   int w,h;
00020   float dp,dt;
00021 
00022 public:
00023   float height(v3f pos){
00024     s2f p = s2f(pos);
00025     return height(p.t,p.p);
00026   }
00027 
00028   float height(float t, float p){
00029     float t0,p0,q,r;
00030     float v0,v1,v2,v3;
00031     int ti0,pi0;
00032     
00033     if(t<0) t = 0;
00034     if(t>=M_PI) t = (float)(M_PI-1e-10);
00035     
00036     t0 = floor(t/dt);
00037     p0 = floor((p+(float)M_PI)/dp);
00038     q = (p+(float)M_PI)/dp-p0;
00039     r = t/dt-t0;
00040 
00041     ti0 = (int)t0;
00042     pi0 = (int)p0;
00043 
00044     if(ti0>=h-1) return array[w*(h-1)];
00045 
00046     v0 = array[pi0%w+w*ti0];
00047     v1 = array[(pi0+1)%w+w*ti0];
00048     v2 = array[pi0%w+w*(ti0+1)];
00049     v3 = array[(pi0+1)%w+w*(ti0+1)];
00050 
00051     return v0*(1.0f-q)*(1.0f-r) + v1*q*(1.0f-r) + v2*(1.0f-q)*r + v3*q*r;
00052   }
00053 
00054   v3f slope(v3f pos){
00055     s2f p = s2f(pos);
00056     return slope(p.t,p.p);
00057   }
00058 
00059   v3f slope(float t, float p);
00060 
00061   int width(){ return w; }
00062   int height(){ return h; }
00063 
00064   int save(FILE *file);
00065   int load(FILE *file);
00066 
00067   AdsoHeightMap(float *a, int sw, int sh){
00068     array=a;
00069     w=sw;
00070     h=sh;
00071     dp=2.0f*(float)M_PI/w;
00072     dt=(float)M_PI/h;
00073   }
00074 
00075   AdsoHeightMap(){
00076     array=0;
00077   }
00078 };
00079 
00080 #endif

Generated on Mon Jul 21 10:44:47 2003 for Rover by doxygen 1.3.2