Re: [osg-users] [3rdparty] osgOcean collision detection
Hi all, Just a note to let you all know that the changes to allow height checks against the ocean surface have been checked in, and the oceanExample will demonstrate this when started with the --testCollision command line argument, i.e. oceanExample --testCollision Thanks to Dimitrios Filiagos, Jan Ciger and Jean-Claude Monnin for developing, submitting and testing the changes! J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi all, Just drop me an e-mail off-list and I can send you a simple hack for testing it - e.g. a buoy bobbing on the water surface or something similar. Dimitrios sent me an example over the weekend, and I've been able to test the changes I've made with his example. Seems to work well. I'm just waiting on Dimitrios to confirm that the boat model he sent can be redistributed without problems and then I'll be able to check in the changes. J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi, you can certainly redistribute the boat model. Please be my guest!!! Thanks Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=18229#18229 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hello, Jean-Sébastien Guay jean-sebastien.g...@cm-labs.com wrote: Hi Jan, While I was at it, I started integrating the changes for getting the ocean surface height at a position. I went with a combination of Jean-Claude's and Dimitrios' code, with a few small modifications. The only problem is I have no way of testing it (it builds, thus it works by definition, right? :-) ). Would it be possible (for either you, Dimitrios, or Jean-Claude) to make a very simple test using the oceanExample as base code, perhaps just making the Cessna from OSG-Data float on the water the way you want? Then I could test if the modifications I made work. I really dislike committing work-in-progress code... So I'd prefer to do it that way. Right, of course. I have a bit of code that makes an object bob on the surface, but my code is likely a bit different from Dimitrios's, so it would need to be changed based on what you have done. Is there a place where I can get your changes? Ideally, just make an experimental branch, commit it there and once it is tested, merge into the trunk. That is fairly easy to do with SVN. I totally agree. OceanTechnique (and thus FFTOceanSurface) already had getSurfaceHeight(), so I added this method as getSurfaceHeightAt() and added comments explaining that the former gets the average height, whereas the latter gets it at a specific position. Great! That will make my life simpler. Regards, Jan signature.asc Description: This is a digitally signed message part. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Jan, Right, of course. I have a bit of code that makes an object bob on the surface, but my code is likely a bit different from Dimitrios's, so it would need to be changed based on what you have done. Likely it's just the method name that would change. I don't mind doing that. Is there a place where I can get your changes? Ideally, just make an experimental branch, commit it there and once it is tested, merge into the trunk. That is fairly easy to do with SVN. I'll try to get that done before the end of the day. J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Jean-Sébastien Guay jean-sebastien.g...@cm-labs.com wrote: Is there a place where I can get your changes? Ideally, just make an experimental branch, commit it there and once it is tested, merge into the trunk. That is fairly easy to do with SVN. I'll try to get that done before the end of the day. Just drop me an e-mail off-list and I can send you a simple hack for testing it - e.g. a buoy bobbing on the water surface or something similar. Regard, Jan signature.asc Description: This is a digitally signed message part. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Jan, While I was at it, I started integrating the changes for getting the ocean surface height at a position. I went with a combination of Jean-Claude's and Dimitrios' code, with a few small modifications. The only problem is I have no way of testing it (it builds, thus it works by definition, right? :-) ). Would it be possible (for either you, Dimitrios, or Jean-Claude) to make a very simple test using the oceanExample as base code, perhaps just making the Cessna from OSG-Data float on the water the way you want? Then I could test if the modifications I made work. I really dislike committing work-in-progress code... So I'd prefer to do it that way. Therefore the function needs to be exposed at the abstract OceanTechnique level already, not only in the FFTOceanSurface. It even makes sense - the sea surface height is likely not going to be dependent on which simulation technique you use to implement it. I have put a pure virtual function in the OceanTechnique which is then redefined in the FFTOceanSurface. I totally agree. OceanTechnique (and thus FFTOceanSurface) already had getSurfaceHeight(), so I added this method as getSurfaceHeightAt() and added comments explaining that the former gets the average height, whereas the latter gets it at a specific position. J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Dimitrios Filiagos dfili...@yahoo.com wrote: One other thing what is the functionality of _isDirty and buid() in Jean Claudes code ? It will save me a lot of time. isDirty forces a rebuild of the data structures and build() does the actual construction of the surface. Your original code didn't have it and I was seeing a crash when a callback was trying to determine the height of the surface before the arrays were initialized. This avoids it. Regards, Jan signature.asc Description: This is a digitally signed message part. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi, you 're right now I understand why I had some crashes from time to time Thanks! Cheers, Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=18014#18014 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi, here's the code for normal interpolation I promised osg::Vec3f OceanTile::normBiLinearInterp(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; osg::Vec3f s00 = getNormal(ix,iy); osg::Vec3f s01 = getNormal(ix + 1,iy); osg::Vec3f s10 = getNormal(ix,iy + 1); osg::Vec3f s11 = getNormal(ix + 1,iy + 1); return s00*(1.f - dx)*(1.f-dy) + s01*dx*(1.f-dy) + s10*(1.f - dx)*dy + s11*dx*dy; } and the code for getSurfaceDataAt() osg::Vec4f FFTOceanSurface::getSurfaceDataAt(float x, float y) { if(_isDirty) build(); const unsigned int SAMPLE_SIZE = 5; //ocean surface coordinates float oceanX, oceanY; //value to return osg::Vec4f surfData(0.0f,0.0f,0.0f,0.0f); //df osg::Vec3f tileOffset; //translate x, y to oceanSurface origin coordinates oceanX = -_startPos.x() + x; oceanY = _startPos.y() - y; //calculate the corresponding tile on the ocean surface unsigned int ix/*tile_x*/ = oceanX/_tileResolution; unsigned int iy/*tile_y*/ = oceanY/_tileResolution ; //This might not be corect but I don't want to ruin data encapsulation of OceanDataType class unsigned int frame = _oldFrame; //Test if the tile is valid if(ix _numTiles iy _numTiles){ const OceanTile data = _mipmapData[_oldFrame][0];//curData[ tile-getLevel() ]; float tile_x = oceanX - ix * _tileResolution; float tile_y = oceanY - iy * _tileResolution; osg::Vec3f norm = data.normBiLinearInterp(tile_x, tile_y); surfData.x() = norm.x(); surfData.y() = norm.y(); surfData.z() = norm.z(); surfData.w() = data.biLinearInterp(tile_x, tile_y); } return surfData; } then you can position an object on the ocean surface by doing something like: osg::Vec4f data(m_oceanSurface-getSurfaceDataAt (x,y)); then data.w() is the height and as rotation you can use something like: (data.x()*180.0f/PI,data.y()*180.0f/PI,(1.0f - data.z())*180.0f/PI) Cheers, Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=18049#18049 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Dimitrios Filiagos dfili...@yahoo.com wrote: Hi, here's the code for normal interpolation I promised Cool, this looks good. Jean-Se, Kim, could we get these things merged in, please? Right now I am maintaining my own patch based on Dimitrios's code, but this is really useful. Of course, the function needs to be exposed in the higher-level classes too, so that we can actually get to it from the viewer. Regards, Jan signature.asc Description: This is a digitally signed message part. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Jan, Dimitrios, Cool, this looks good. Jean-Se, Kim, could we get these things merged in, please? Right now I am maintaining my own patch based on Dimitrios's code, but this is really useful. Of course, the function needs to be exposed in the higher-level classes too, so that we can actually get to it from the viewer. Send us the whole files of what you need and I'll have a look for sure. I'm not the one who needs this so I don't want to start guessing in which classes you need access to this... J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi, Jean-Sébastien Guay jean-sebastien.g...@cm-labs.com wrote: Send us the whole files of what you need and I'll have a look for sure. I'm not the one who needs this so I don't want to start guessing in which classes you need access to this... J-S I need it in the following two: OceanScene and then OceanTechnique. I am attaching the two modified headers. My FFTOceanSurface.cpp and its header contain a similar function float getSeaHeight(float x, float y) as the one Dimitrios originally posted. I am not sending those, because I think his latest version is better and has the normal calculation too which mine doesn't. These changes allow to retrieve the sea surface height from the viewer, with just a pointer to OceanScene instance. Regards, Jan /* * This source file is part of the osgOcean library * * Copyright (C) 2009 Kim Bale * Copyright (C) 2009 The University of Hull, UK * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free Software * Foundation; either version 3 of the License, or (at your option) any later * version. * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * http://www.gnu.org/copyleft/lesser.txt. */ #pragma once #include osgOcean/Export #include osg/Geode #include osgUtil/CullVisitor #include osgGA/GUIEventHandler namespace osgOcean { class OSGOCEAN_EXPORT OceanTechnique : public osg::Geode { public: OceanTechnique( void ); OceanTechnique( const OceanTechnique copy, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY ); virtual const char* libraryName() const { return osgOcean; } virtual const char* className() const { return OceanTechnique; } virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_castconst OceanTechnique*(obj) != 0; } virtual void build( void ); virtual void stopAnimation( void ){ _isAnimating = false; } virtual void startAnimation( void ){ _isAnimating = true; } bool isAnimating( void ) const{ return _isAnimating; } virtual float getSurfaceHeight(void) const; inline bool isDirty(void) const{ return _isDirty; } inline void dirty(void){ _isDirty=true; } /** Check if the ocean surface is visible or not. Basic test is very simple, subclasses can do a better test. */ bool isVisible( osgUtil::CullVisitor cv, bool eyeAboveWater ); /** Base class for the OceanTechnique event handler. Subclasses of * OceanTechnique can subclass this to provide support for * manipulating their particular properties, calling the base class * handle() to inherit the base class's events (or not as desired). * If subclasses subclass this handler, they need to override * getEventHandler() in order for it to return the right concrete * event handler instance. */ class EventHandler : public osgGA::GUIEventHandler { public: EventHandler(OceanTechnique* oceanSurface); virtual bool handle(const osgGA::GUIEventAdapter ea, osgGA::GUIActionAdapter aa, osg::Object*, osg::NodeVisitor*); virtual void getUsage(osg::ApplicationUsage usage) const; protected: OceanTechnique* _oceanSurface; }; /** Virtual constructor for OceanTechnique::EventHandler - override in * derived classes to return subclass-specific handler if needed. */ virtual EventHandler* getEventHandler() { if (!_eventHandler.valid()) _eventHandler = new EventHandler(this); return _eventHandler.get(); } /* * JC hacks */ virtual float getSeaHeightAt(float x, float y) = 0; protected: virtual ~OceanTechnique(void){}; protected: bool _isDirty; bool _isAnimating; osg::ref_ptrEventHandler _eventHandler; }; } /* * This source file is part of the osgOcean library * * Copyright (C) 2009 Kim Bale * Copyright (C) 2009 The University of Hull, UK * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free Software * Foundation; either version 3 of the License, or (at your option) any later * version. * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. *
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Jan, Dimitrios, On the face of it this all looks good, but I'll take some time to review and test the code at the weekend, but as J-S says could you send the whole files where the changes are made as it makes my life a lot easier to test. Of course, the function needs to be exposed in the higher-level classes too, so that we can actually get to it from the viewer. Jan - I'm not sure what is meant by get to it from the viewer here? Cheers, Kim. 2009/10/7 Jan Ciger jan.ci...@gmail.com Dimitrios Filiagos dfili...@yahoo.com wrote: Hi, here's the code for normal interpolation I promised Cool, this looks good. Jean-Se, Kim, could we get these things merged in, please? Right now I am maintaining my own patch based on Dimitrios's code, but this is really useful. Of course, the function needs to be exposed in the higher-level classes too, so that we can actually get to it from the viewer. Regards, Jan ___ 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
Re: [osg-users] [3rdparty] osgOcean collision detection
Kim Bale kcb...@googlemail.com wrote: Jan - I'm not sure what is meant by get to it from the viewer here? I am accessing the code like this within my viewer's main loop: // osgOcean::OceanTechnique *ocean; float height = ocean-getSeaHeightAt(pos.x(), pos.y()); ... Therefore the function needs to be exposed at the abstract OceanTechnique level already, not only in the FFTOceanSurface. It even makes sense - the sea surface height is likely not going to be dependent on which simulation technique you use to implement it. I have put a pure virtual function in the OceanTechnique which is then redefined in the FFTOceanSurface. Regards, Jan signature.asc Description: This is a digitally signed message part. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi all, the code that Jean Claude posted works like a sweet. I also wrote a function similar to biLinearInterp to interpolate the normals of 4 vertices. I renamed the function getHeightAt(x,y) to getSurfaceDataAt(x,y) that return an osg::Vec4f now. The x,y,z represent the interpolated normal and the w the surface height. Now when you apply rotation and translation (only the height) to an object you might except from seeing the object to follow the motion of the waves you can see it rotate a little bit, like it should be in real life. I will post the code soon. One other thing what is the functionality of _isDirty and buid() in Jean Claudes code ? It will save me a lot of time. Thanks! Cheers, Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=17992#17992 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
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
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Jean-Claude, Thanks for code snippet, this does seem to be a popular bit of functionality so I'll go through it and work out the best way to integrate it. To avoid these windows header conflicts, would it be possible to change Not a problem I'll make those changes to the trunk today. Cheers, Kim. 2009/10/5 Jean-Claude Monnin jc_mon...@emailplus.org: 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 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Jean-Claude Monnin jc_mon...@emailplus.org wrote: 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. You are my hero :) I was fighting with Dimitros's code to do this over the weekend and couldn't make the interpolation work right. I think that the mipmap choice was the issue. Thanks for posting this! BTW, I have implemented a callback that resizes the osgOcean when the window size changes and I am getting crashes there from time to time when resizing the window. Is anyone else seeing this? Regards, Jan signature.asc Description: This is a digitally signed message part. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
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
Re: [osg-users] [3rdparty] osgOcean collision detection
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
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Kim, yesterday I realized that my object goes up and down from the water because: a) it is smaller than the distance of two vertices of the grid b) the vertice displacement that takes place to simulate the wave on larger objects it works fine! I used the linear interpolation function of OceanTile it seems to work ok but I am still testing. Thanks! Cheers, Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=17757#17757 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi, it seems to work fine but I am still testing. For big models of height 2.0 and more works fine, for smaller height models there are frames that goes above water, just a little though and also on some other frames just below the surface, especially on high wind speeds. This behavior might be correct but I 'll try to make it more realistic. For bigger models the behavior is OK. I am thinking of using the surface normal to calculate the models pitch and roll, but it will take sometime . Thanks! Cheers, Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=17697#17697 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Dimitrios, Glad to hear you got it working. I have a couple of further hints for you. You may find that the accuracy is improved if you use _oldFrame without the increment. The variable name is a little misleading as it is actually stores the id for the current frame, if you look at the update function in FFTOceanSurface it is assigned after the vertices have been updated and is used purely to prevent updates of the vertices if the frame hasn't changed. This does depend on whether you're calling getHeight before or after that function is called. You could also try using a bilinear interpolation between the four closest vertices, There should be to copy the the interpolation function in the MipmapData class which I use to smooth out the vertices for the different mipmap levels. Regards, Kim. 2009/9/29 Dimitrios Filiagos dfili...@yahoo.com: Hi, it seems to work fine but I am still testing. For big models of height 2.0 and more works fine, for smaller height models there are frames that goes above water, just a little though and also on some other frames just below the surface, especially on high wind speeds. This behavior might be correct but I 'll try to make it more realistic. For bigger models the behavior is OK. I am thinking of using the surface normal to calculate the models pitch and roll, but it will take sometime . Thanks! Cheers, Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=17697#17697 ___ 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
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Dimitrios, I tried to write a function during the weekend. It works but the result is not so accurate. The floating objects are going up and down but they're not completely synchronized with the ocean surface. It seems that they are moving on a different phase or something. Here's my code Sorry, but since I'm not working on this right now as I mentioned before, I can't spend too much time helping you out with this... But one thing I found odd: unsigned int frame = ++_oldFrame; This will increment _oldFrame in place, and ALSO store the result in frame. So if _oldFrame was 1 before this line, it will be 2 after and the frame variable will also contain 2. Is this what you want? I don't think that you should be incrementing _oldFrame on each call of your function, it might change how the ocean surface is rendered... Try frame = _oldFrame + 1 instead. Other than that I don't see anything suspect in your code, but it's hard to debug things by email - you have the code in front of you and a test case that doesn't give the right results, so you're best placed to debug it... J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi, I checked the _oldFrame and you are absolutely right. Thanks! Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=17686#17686 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Dimitrios, I checked the _oldFrame and you are absolutely right. So does that mean that my suggestion fixed it for you? J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Kim Bale, your hints are valuable. As I've seen so far I need to know the height on a specific point on sea surface. I wrote a function in FFTOceanSurface passing the x,y of a point. That function finds the corresponding ocean tile and retrives the closest vertice using the getVertex of OceanTile function. That way I can program my objects on the sea surface to maintain that height from the sea zero level on every frame. I haven't done yet (actually it doesn't work so far) but I believe I am going to the right direction. I' ll make a post when I have good news. Thank you! Cheers, Dimitrios -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=17647#17647 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [3rdparty] osgOcean collision detection
Hi Dimitrios, I wrote a function in FFTOceanSurface passing the x,y of a point. That function finds the corresponding ocean tile and retrives the closest vertice using the getVertex of OceanTile function. That's good. We could add another function that would return a weighted average of the closest 4 points, which would be more accurate but also slower. Finally we could also add a function that returns a 2D array of heights given an axis-aligned bounding box which is the (x1, y1, x2, y2) of where on the grid your object is. This would allow the collision detection to do what it wants with the points. Those 3 functions would flesh out the API for one-way interaction (water - object). As I told Jan, I'm not working on this right now, but will in the near future. Let me know if you get something working, we can share the workload that way :-) J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org