Hi all, I also need to query the height of the ocean. Based on Dimitrios posted code, I modified it to do a bi-linear interpolation. Below is the code I would like to share. Should there be general interest in height query of the ocean, then it would be good to put this or similar code in the repository. Note: This method always gets the height from the highest detail mipmap.
float FFTOceanSurface::getHeightAt(float x, float y ) { if(_isDirty) build(); // Translate x, y to oceanSurface origin coordinates float oceanX = -_startPos.x() + x; float oceanY = _startPos.y() - y; // Calculate the corresponding tile on the ocean surface unsigned int ix = oceanX/_tileResolution; unsigned int iy = oceanY/_tileResolution ; // Test if the tile is valid if( ix < _numTiles && iy < _numTiles ) { // Select the tile for the specific frame const OceanTile& data = _mipmapData[_oldFrame][0]; // Calculate the coordinates on the specific tile we're intersted float tile_x = oceanX - ix*_tileResolution; float tile_y = oceanY - iy*_tileResolution; // Do the bi-linear interpolation return data.biLinearInterp(tile_x, tile_y); } else { return 0.f; } } float OceanTile::biLinearInterp(float x, float y ) const { float dx = x/_spacing; float dy = y/_spacing; unsigned int ix = dx; unsigned int iy = dy; dx -= ix; dy -= iy; float s00 = getVertex(ix , iy ).z(); float s01 = getVertex(ix+1, iy ).z(); float s10 = getVertex(ix , iy+1).z(); float s11 = getVertex(ix+1, iy+1).z(); return s00*(1.f-dx)*(1.f-dy) + s01*dx*(1.f-dy) + s10*(1.f-dx)*dy + s11*dx*dy; } Other topic: When you include <windows.h> before <osgOcean/OceanScene> there is a conflict with the macro near/far of the windows header (line 261 and 275 of OceanScene). I can't change the include order in my project so I had to use some undef pragmas to successfully compile the code. To avoid these windows header conflicts, would it be possible to change OceanScene headers from: inline void setDOFNear( float near ) { _dofNear = near; ... inline void setDOFFar(float far ) { _dofFar = far; to inline void setDOFNear( float dofNear ) { _dofNear = dofNear; ... inline void setDOFFar(float dofFar ) { _dofFar = dofFar; Regards, Jean-Claude On Wed, 30 Sep 2009 09:33 +0100, "Kim Bale" <kcb...@googlemail.com> wrote: > Hi Dimitrios, > > The interpolation function in OceanTile works on indices fetching the > vertices from the vertex array within it. So you pass it the 4 unique > row/column indices that make up the surrounding four points and then a > row and a column index for the target point (tx & ty). > > For your application you'll need to make a modified version that takes > in x,y coords rather than indices but the mathematical approach is the > same. > > Regards, > > Kim. > > > > 2009/9/30 Dimitrios Filiagos <dfili...@yahoo.com>: > > Hi, > > I saw the Update function and understood that you're absolutely right! > > I saw more accurate results also! > > Yesterday I changed the function to retrieve the normal too. Now with the > > normal I can make the models not only to move up and down but rotate also > > when a wave passes. > > > > I will try to use biLinearInterp to interpolate the height between four > > vertices. For that function you must provide the indices (x,y) of three > > vertices? Is that correct? > > > > > > Thanks > > > > Cheers, > > Dimitrios > > > > ------------------ > > Read this topic online here: > > http://forum.openscenegraph.org/viewtopic.php?p=17735#17735 > > > > > > > > > > > > _______________________________________________ > > osg-users mailing list > > osg-users@lists.openscenegraph.org > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Jean-Claude Monnin jc_mon...@emailplus.org _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org