osgOceanScene.h
Go to the documentation of this file.
00001 /*
00002  * This source file is part of the osgOcean library
00003  *
00004  * Copyright (C) 2009 Kim Bale
00005  * Copyright (C) 2009 The University of Hull, UK
00006  *
00007  * This program is free software; you can redistribute it and/or modify it under
00008  * the terms of the GNU Lesser General Public License as published by the Free Software
00009  * Foundation; either version 3 of the License, or (at your option) any later
00010  * version.
00011 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00015  * http://www.gnu.org/copyleft/lesser.txt.
00016  *
00017  * Adapted to UWSim by Mario Prats
00018  */
00019 
00020 #pragma once
00021 #include <osg/Switch>
00022 #include <osg/TextureCubeMap>
00023 
00024 #include <osgText/Text>
00025 
00026 #include <osgOcean/OceanScene>
00027 #include <osgOcean/FFTOceanSurface>
00028 #include <osgOcean/FFTOceanSurfaceVBO>
00029 
00030 #include "SkyDome.h"
00031 #include "ConfigXMLParser.h"
00032 #include <osgOcean/ShaderManager>
00033 
00034 enum DrawMask
00035 {
00036   CAST_SHADOW = (0x1 << 30), RECEIVE_SHADOW = (0x1 << 29),
00037 };
00038 
00039 class osgOceanScene : public osg::Referenced
00040 {
00041 public:
00042   enum SCENE_TYPE
00043   {
00044     CLEAR, DUSK, CLOUDY
00045   };
00046   osg::ref_ptr<osg::MatrixTransform> localizedWorld;
00047 
00048 private:
00049   SCENE_TYPE _sceneType;
00050   bool _useVBO;
00051 
00052   osg::ref_ptr<osgText::Text> _modeText;
00053   osg::ref_ptr<osg::Group> _scene;
00054 
00055   osg::ref_ptr<osgOcean::OceanScene> _oceanScene;
00056   osg::ref_ptr<osgOcean::FFTOceanTechnique> _FFToceanSurface;
00057   osg::ref_ptr<osg::TextureCubeMap> _cubemap;
00058   osg::ref_ptr<SkyDome> _skyDome;
00059 
00060   std::vector<std::string> _cubemapDirs;
00061   std::vector<osg::Vec4f> _lightColors;
00062   std::vector<osg::Vec4f> _fogColors;
00063   std::vector<osg::Vec3f> _underwaterAttenuations;
00064   std::vector<osg::Vec4f> _underwaterDiffuse;
00065 
00066   osg::ref_ptr<osg::Light> _light;
00067 
00068   std::vector<osg::Vec3f> _sunPositions;
00069   std::vector<osg::Vec4f> _sunDiffuse;
00070   std::vector<osg::Vec4f> _waterFogColors;
00071 
00072   osg::ref_ptr<osg::Switch> _islandSwitch;
00073 
00074 public:
00075   osgOceanScene(double offsetp[3], double offsetr[3], const osg::Vec2f& windDirection = osg::Vec2f(1.0f, 1.0f),
00076                 float windSpeed = 12.f, float depth = 10000.f, float reflectionDamping = 0.35f, float scale = 1e-8,
00077                 bool isChoppy = true, float choppyFactor = -2.5f, float crestFoamHeight = 2.2f, bool useVBO = false,
00078                 const std::string& terrain_shader_basename = "terrain");
00079 
00080   void build(double offsetp[3], double offsetr[3], const osg::Vec2f& windDirection, float windSpeed, float depth,
00081              float reflectionDamping, float waveScale, bool isChoppy, float choppyFactor, float crestFoamHeight,
00082              bool useVBO, const std::string& terrain_shader_basename);
00083 
00084   void changeScene(SCENE_TYPE type);
00085 
00086   // Load the islands model
00087   // Here we attach a custom shader to the model.
00088   // This shader overrides the default shader applied by OceanScene but uses uniforms applied by OceanScene.
00089   // The custom shader is needed to add multi-texturing and bump mapping to the terrain.
00090   osg::Node* loadIslands(const std::string& terrain_shader_basename);
00091 
00092   osg::ref_ptr<osg::TextureCubeMap> loadCubeMapTextures(const std::string& dir);
00093 
00094   osg::Geode* sunDebug(const osg::Vec3f& position);
00095 
00096   inline osg::Vec4f intColor(unsigned r, unsigned g, unsigned b, unsigned a = 255)
00097   {
00098     float div = 1.f / 255.f;
00099     return osg::Vec4f(div * (float)r, div * (float)g, div * float(b), div * (float)a);
00100   }
00101 
00102   inline osgOcean::OceanScene::EventHandler* getOceanSceneEventHandler()
00103   {
00104     return _oceanScene->getEventHandler();
00105   }
00106 
00107   inline osgOcean::OceanTechnique* getOceanSurface(void)
00108   {
00109     return _FFToceanSurface.get();
00110   }
00111 
00112   inline osg::Group* getScene(void)
00113   {
00114     return _scene.get();
00115   }
00116 
00117   inline osgOcean::OceanScene* getOceanScene()
00118   {
00119     return _oceanScene.get();
00120   }
00121 
00122   osg::Light* getLight()
00123   {
00124     return _light.get();
00125   }
00126 
00127   osg::Node* addObject(osg::Transform *transform, std::string filename, Object *o = NULL);
00128 
00129   void addObject(osg::Transform *transform);
00130 
00131 };


uwsim
Author(s): Mario Prats
autogenerated on Mon Oct 6 2014 08:24:07