Main Page | Namespace List | Class List | File List | Class Members | File Members

water.h File Reference

#include <vector>

Go to the source code of this file.

Classes

struct  _S_WaterQuad

Functions

void initWater (int W, int H)
 Initialize the water surface.

void computeWater (float fTime)
 Compute water vertices and normals at a certain time instant.

void drawWaterQuads (const std::vector< _S_WaterQuad > &Qs)
 Draw all quads of the water surface.


Function Documentation

void computeWater float  fTime  ) 
 

Compute water vertices and normals at a certain time instant.

Call after camera initialization

Definition at line 145 of file water.cpp.

References computeHeight(), computeNormal(), g_CameraX, g_CameraY, g_CameraZ, g_H, g_hf, g_hf_normals, g_W, g_xe, g_ye, g_ze, and normal.

Referenced by initWater(), and timerCallback().

00146 {
00147   // Compute eye position
00148   g_xe = g_CameraX; // cos( g_fCameraX*M_PI/180.0f ) * g_fViewDistance;
00149   g_ze = g_CameraZ; //sin( g_fCameraX*M_PI/180.0f ) * g_fViewDistance;
00150   g_ye = g_CameraY;//cos( g_fCameraY*M_PI/180.0f ) * g_fViewDistance;
00151 
00152   // Init height field
00153   float *p = g_hf;
00154   for (int y=0; y<g_H; y++) {
00155     for (int x=0; x<g_W; x++) {
00156       *p = computeHeight( x,y, fTime );
00157       p++;
00158     }
00159   }
00160 
00161   // Init normals
00162   normal *pN = g_hf_normals;
00163   for (int y=0; y<g_H; y++) {
00164     for (int x=0; x<g_W; x++) {
00165       computeNormal( x,y, (*pN)[0], (*pN)[1], (*pN)[2] );
00166       pN++;
00167     }
00168   }
00169 }

void drawWaterQuads const std::vector< _S_WaterQuad > &  Qs  ) 
 

Draw all quads of the water surface.

Referenced by drawHeightField().

void initWater int  W,
int  H
 

Initialize the water surface.

Definition at line 93 of file water.cpp.

References computeWater(), fourier(), g_H, g_hf, g_hf_fc_im, g_hf_fc_re, g_hf_normals, g_W, and normal.

Referenced by initGL().

00094 {
00095   // Validate params
00096   assert( W>0 && W*H > 0 );
00097   // Clear old data
00098   delete[] g_hf;
00099   delete[] g_hf_normals;
00100   delete[] g_hf_fc_re;
00101   delete[] g_hf_fc_im;
00102 
00103   // Init new data
00104   g_W = W;
00105   g_H = H;
00106   g_hf = new float[W*H];
00107   g_hf_normals = new normal[W*H];
00108   g_hf_fc_re = new float[W*H];
00109   g_hf_fc_im = new float[W*H];
00110 
00111   for (int x=0; x<g_W; x++) {
00112     for (int y=0; y<g_H; y++) {
00113       complex<float> fc = fourier( x,y );
00114       g_hf_fc_re[x+y*g_W] = real(fc);
00115       g_hf_fc_im[x+y*g_W] = imag(fc);
00116     }
00117   }
00118   g_hf_fc_re[0] = 0;
00119   g_hf_fc_im[0] = 0;
00120 
00121   computeWater( 0.0f );
00122 }


Generated on Thu Jan 20 02:46:59 2005 for Main_Demo by doxygen 1.3.6