00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00029
00030 #ifndef _3D_COMMONS_H
00031 #define _3D_COMMONS_H
00032
00033 #include <PVLE/Export.h>
00034
00035 #include <utility>
00036 #include <osg/Vec3>
00037 #include <osg/Vec4>
00038 #include <osg/Matrix>
00039
00040 #include <boost/filesystem/path.hpp>
00041
00042 namespace osg {
00043 class Node;
00044 class Group;
00045 class Geode;
00046 class Geometry;
00047 class Transform;
00048 class Projection;
00049 class Drawable;
00050 class Stateset;
00051 class MatrixTransform;
00052 class Material;
00053 class Image;
00054 class HeightField;
00055 }
00056
00057 namespace osgText {
00058 class Text;
00059 class Font;
00060 }
00061
00066 PVLE_EXPORT osg::Transform * createSkySphere(const boost::filesystem::path & texturePath, float detailRatio = 0.5f);
00067
00069 class PVLE_EXPORT CloudParams {
00070 public:
00072 CloudParams();
00073
00074 unsigned int numSprites;
00075 boost::filesystem::path imagePath;
00076
00077 float ratio;
00078 float density;
00079 float spriteSizeMin;
00080 float spriteSizeMax;
00081
00082
00083 const osg::Vec3 axis;
00084 osg::Vec4f lowColor;
00085 osg::Vec4f hiColor;
00086 float alphaOffsetMin;
00087 float alphaOffsetMax;
00088 float skewVMin;
00089 float skewVMax;
00090 float skewHMin;
00091 float skewHMax;
00092 float colorScaleRand;
00093 };
00094
00096 PVLE_EXPORT osg::Geode * createCloud(const CloudParams & params);
00098 PVLE_EXPORT osg::Geode * createCloud(const boost::filesystem::path & imagePath, unsigned int numSprites = 100);
00099
00101 PVLE_EXPORT osg::Geometry * createAxisDrawable(const osg::Vec3& corner, const osg::Vec3& xdir, const osg::Vec3& ydir, const osg::Vec3& zdir);
00102
00104 PVLE_EXPORT osg::Geometry * createSegmentDrawable(const osg::Vec3 & p1, const osg::Vec3 & p2, float width = 3, const osg::Vec4 & color1 = osg::Vec4(1,1,1,1), const osg::Vec4 & color2 = osg::Vec4(-1,-1,-1,-1));
00105
00107 PVLE_EXPORT osg::Geode * createAxis(float axisSize);
00108
00110 PVLE_EXPORT osg::Geode * createSegment(const osg::Vec3 & p1, const osg::Vec3 & p2, float width = 3, const osg::Vec4 & color1 = osg::Vec4(1,1,1,1), const osg::Vec4 & color2 = osg::Vec4(-1,-1,-1,-1));
00111
00113 PVLE_EXPORT osgText::Text * createText(osgText::Font * pFont, float height = 20.f, const osg::Vec3f & position = osg::Vec3f(0,0,0), const osg::Vec4f & color = osg::Vec4f(.5f, .5f, .5f, 1));
00114
00117 PVLE_EXPORT osg::Geometry * createSquare(const osg::Vec3& corner, const osg::Vec3& width, const osg::Vec3& height, osg::Image* image = NULL, unsigned int nbTextureCoords = 1, bool invertYTexCoords = false);
00118
00120 inline osg::Geometry * createSquareFor2D(const osg::Vec3& corner2D, const osg::Vec3& boxSize2D, osg::Image* image = NULL, unsigned int nbTextureCoords = 1, bool invertYTexCoords = false) {
00121 return createSquare(corner2D, osg::Vec3(boxSize2D.x(),0,0), osg::Vec3(0,-boxSize2D.y(),0), image, nbTextureCoords, !invertYTexCoords);
00122 }
00123
00125 inline osg::Geometry * createSquareFor2D(const osg::Vec3& corner2D, float boxSize2DX, float boxSize2DY, osg::Image* image = NULL, unsigned int nbTextureCoords = 1, bool invertYTexCoords = false) {
00126 return createSquareFor2D(corner2D, osg::Vec3(boxSize2DX,boxSize2DY,0), image, nbTextureCoords, invertYTexCoords);
00127 }
00128
00131 PVLE_EXPORT void updateSquare(osg::Geometry * pGeometry, const osg::Vec3& width, const osg::Vec3& height);
00132
00135 PVLE_EXPORT void updateSquare(osg::Geometry * pGeometry, const osg::Vec3& corner, const osg::Vec3& width, const osg::Vec3& height);
00136
00139 inline void updateSquareFor2D(osg::Geometry * pGeometry, float width, float height) {
00140 updateSquare(pGeometry, osg::Vec3(width,0,0), osg::Vec3(0,-height,0));
00141 }
00142
00145 inline void updateSquareFor2D(osg::Geometry * pGeometry, const osg::Vec3& corner, float width, float height) {
00146 updateSquare(pGeometry, corner, osg::Vec3(width,0,0), osg::Vec3(0,-height,0));
00147 }
00148
00150 PVLE_EXPORT std::pair<osg::Projection*, osg::MatrixTransform*> create2DProjection(const osg::Matrix & orthoProjectionMatrix);
00151
00153 PVLE_EXPORT osg::Projection * encapsulateIn2DProjection(osg::Node * pNode, const osg::Matrix & orthoProjectionMatrix);
00154
00155 PVLE_EXPORT void setHudStatset(osg::StateSet * pStateset);
00156
00158 PVLE_EXPORT void setColor(osg::StateSet * pStateSet, const osg::Vec4 & color);
00160 PVLE_EXPORT void setColor(osg::Node * pNode, const osg::Vec4 & color);
00161
00163 PVLE_EXPORT osg::MatrixTransform * createShapeGeode(osg::Shape * shape, float tesselationDetailRatio = 0);
00165 PVLE_EXPORT osg::MatrixTransform * createShapeGeodeBox(const osg::Vec3 & size);
00167 PVLE_EXPORT osg::MatrixTransform * createShapeGeodeSphere(const float radius, float tesselationDetailRatio = 0);
00169 PVLE_EXPORT osg::MatrixTransform * createShapeGeodeCapsule(const float radius, const float length, float tesselationDetailRatio = 0);
00171 PVLE_EXPORT osg::MatrixTransform * createShapeGeodeCylinder(const float radius, const float length, float tesselationDetailRatio = 0);
00172
00177 PVLE_EXPORT osg::HeightField * readHeightMap(const boost::filesystem::path & path, const float vScale = 1.f, const float hScale = 3000.f);
00178
00179
00180 #endif // _3D_COMMONS_H