00001 #ifndef WATERSURFACE_H
00002 #define WATERSURFACE_H
00003
00004 #include <vrs/environment/config.h>
00005 #include <vrs/opengl/mappedvertexattributeshapegl.h>
00006 #include <vrs/color.h>
00007 #include <vrs/utils.h>
00008
00009 typedef VRS::VertexData<2, float> VertexData2f;
00010
00011 namespace VRS {
00012 template<typename T> class Iterator;
00013 class Facet;
00014 class Color;
00015 }
00016
00017 namespace EnvironmentRenderer {
00018
00022
00027 class VRS_ENV_API WaterSurface : public VRS::MappedVertexAttributeShapeGL {
00028 public:
00029 class Plane;
00030
00070
00071 WaterSurface(VRS::SO<VRS::Iterator<VRS::SO<VRS::Facet> > > surface,
00072 const VRS::Vector& flowDirection,
00073 const VRS::Color& waterColor = VRS::Color::slate_blue,
00074 float fresnelBias = 0.0f,
00075 const VertexData2f& reflectionScale = VertexData2f(0.2f, 0.2f),
00076 const VertexData2f& refractionScale = VertexData2f(0.2f, 0.2f),
00077 double junctionSize = 0.0,
00078 bool refracting = false,
00079 const VRS::Matrix& waveTf = VRS::Matrix::identity);
00080
00082 virtual VRS::Bounds boundingBox() const;
00083
00084
00085 VRS::SO<VRS::Iterator<VRS::SO<VRS::Facet> > > getSurface() const;
00086 void setSurface(VRS::SO<VRS::Iterator<VRS::SO<VRS::Facet> > > surface);
00087
00088
00089 const VRS::Vector& getFlowDirection() const;
00090 void setFlowDirection(const VRS::Vector& flowDirection);
00091
00092 void setReflectionScale(const VRS::VertexData<2, float>& scale);
00093 const VRS::VertexData<2, float>& getReflectionScale() const;
00094 void setRefractionScale(const VRS::VertexData<2, float>& scale);
00095 const VRS::VertexData<2, float>& getRefractionScale() const;
00096
00097 void setRefracting(bool enable);
00098 bool isRefracting();
00099
00100 void setFresnelBias(float bias);
00101 float getFresnelBias() const;
00102
00103 void setWaterColor(const VRS::Color& color);
00104 const VRS::Color& getWaterColor() const;
00105
00106 double getJunctionSize() const;
00107 void setJunctionSize(double size);
00108
00109 void setWaveTf(const VRS::Matrix& tf) { m_waveTransform = tf; }
00110 const VRS::Matrix& waveTf() const { return m_waveTransform; }
00111
00112 const Plane &getPlane() const;
00113
00114
00115 void setPlane(const Plane &p);
00116
00117 VRS_TYPEINFO(WaterSurface, VRS::Shape);
00118 VRS_SERIALIZABLE(WaterSurface);
00119
00120 class Plane
00121 {
00122 public:
00130 Plane(VRS::Vector normal = VRS::Vector(0.0, 1.0, 0.0), VRS::Vector anchor = VRS::Vector());
00131 Plane(const Plane& other);
00132 void setAnchor(VRS::Vector anchor);
00133 void setNormal(VRS::Vector normal);
00134 VRS::Vector getAnchor() const;
00135 VRS::Vector getNormal() const;
00136 VRS::Vector getTangent() const;
00137 VRS::Vector getBitangent() const;
00138 double getDistanceToOrigin() const;
00139 bool operator==(const Plane &other);
00140 bool operator!=(const Plane &other);
00141 bool operator<(const Plane &other);
00142 const Plane& operator=(const Plane &other);
00143
00144 private:
00145 void updateDistanceToOrigin();
00146 void updateTangentAndBitangent();
00147
00148 VRS::Vector m_anchor;
00149 VRS::Vector m_normal;
00150 VRS::Vector m_tangent;
00151 VRS::Vector m_bitangent;
00152 double m_distanceToOrigin;
00153 };
00154
00155 protected:
00156 WaterSurface();
00157 void createGeometry();
00158
00159 VRS::SO<VRS::Iterator<VRS::SO<VRS::Facet> > > m_surface;
00160 VRS::Vector m_flowDirection;
00161 VRS::VertexData<2, float> m_reflectionScale;
00162 VRS::VertexData<2, float> m_refractionScale;
00163 float m_fresnelBias;
00164 VRS::Color m_waterColor;
00165 VRS::Bounds m_boundingBox;
00166 Plane m_plane;
00167 double m_junctionSize;
00168 bool m_refracting;
00169 VRS::Matrix m_waveTransform;
00170 };
00171
00172 }
00173
00174 #include <vrs/environment/watersurface.inl>
00175
00176 #endif // WATERSURFACE_H
00177