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
00030
00031 #ifndef _3D_UTILITY_H
00032 #define _3D_UTILITY_H
00033
00034 #include <PVLE/Export.h>
00035 #include <osg/Node>
00036 #include <osg/NodeCallback>
00037
00038 #include <osg/Vec3f>
00039 #include <osg/Vec4f>
00040 #include <osg/Vec3d>
00041 #include <osg/Vec4d>
00042 #include <osg/Quat>
00043
00045 namespace osg {
00046 class Image;
00047 class HeightField;
00048
00050 inline Vec3f operator* (const Vec3f & v, const Quat & q) { return q*v; }
00052 inline Vec3d operator* (const Vec3d & v, const Quat & q) { return q*v; }
00054 inline Vec4f operator* (const Vec4f & v, const Quat & q) { return v*Matrixf(q); }
00056 inline Vec4d operator* (const Vec4d & v, const Quat & q) { return v*Matrixd(q); }
00057 }
00058
00059 inline osg::Vec3f invertY(const osg::Vec3f & v) { return osg::Vec3f(v.x(), -v.y(), v.z()); }
00060 inline osg::Vec3d invertY(const osg::Vec3d & v) { return osg::Vec3d(v.x(), -v.y(), v.z()); }
00061 inline osg::Vec4f invertY(const osg::Vec4f & v) { return osg::Vec4f(v.x(), -v.y(), v.z(), v.w()); }
00062 inline osg::Vec4d invertY(const osg::Vec4d & v) { return osg::Vec4d(v.x(), -v.y(), v.z(), v.w()); }
00063
00064 inline osg::Vec3f multX(const osg::Vec3f & v, float r) { return osg::Vec3f(v.x()*r, v.y(), v.z()); }
00065 inline osg::Vec3d multX(const osg::Vec3d & v, double r) { return osg::Vec3d(v.x()*r, v.y(), v.z()); }
00066 inline osg::Vec4f multX(const osg::Vec4f & v, float r) { return osg::Vec4f(v.x()*r, v.y(), v.z(), v.w()); }
00067 inline osg::Vec4d multX(const osg::Vec4d & v, double r) { return osg::Vec4d(v.x()*r, v.y(), v.z(), v.w()); }
00068
00069 inline osg::Vec3f multY(const osg::Vec3f & v, float r) { return osg::Vec3f(v.x(), v.y()*r, v.z()); }
00070 inline osg::Vec3d multY(const osg::Vec3d & v, double r) { return osg::Vec3d(v.x(), v.y()*r, v.z()); }
00071 inline osg::Vec4f multY(const osg::Vec4f & v, float r) { return osg::Vec4f(v.x(), v.y()*r, v.z(), v.w()); }
00072 inline osg::Vec4d multY(const osg::Vec4d & v, double r) { return osg::Vec4d(v.x(), v.y()*r, v.z(), v.w()); }
00073
00074 inline osg::Vec3f multZ(const osg::Vec3f & v, float r) { return osg::Vec3f(v.x(), v.y(), v.z()*r); }
00075 inline osg::Vec3d multZ(const osg::Vec3d & v, double r) { return osg::Vec3d(v.x(), v.y(), v.z()*r); }
00076 inline osg::Vec4f multZ(const osg::Vec4f & v, float r) { return osg::Vec4f(v.x(), v.y(), v.z()*r, v.w()); }
00077 inline osg::Vec4d multZ(const osg::Vec4d & v, double r) { return osg::Vec4d(v.x(), v.y(), v.z()*r, v.w()); }
00078
00079 inline osg::Vec4f multW(const osg::Vec4f & v, float r) { return osg::Vec4f(v.x(), v.y(), v.z(), v.w()*r); }
00080 inline osg::Vec4d multW(const osg::Vec4d & v, double r) { return osg::Vec4d(v.x(), v.y(), v.z(), v.w()*r); }
00081
00082
00083 inline osg::Vec3f toVec3(const osg::Vec4f & v) { return osg::Vec3f(v.x(), v.y(), v.z()); }
00084 inline osg::Vec3d toVec3(const osg::Vec4d & v) { return osg::Vec3d(v.x(), v.y(), v.z()); }
00085
00086
00088 PVLE_EXPORT float computeAngle(const osg::Vec3f & v1, const osg::Vec3f & v2, const osg::Vec3f reference);
00089 PVLE_EXPORT double computeAngle(const osg::Vec3d & v1, const osg::Vec3d & v2, const osg::Vec3d reference);
00090
00092
00094
00095
00097 PVLE_EXPORT bool hasUpdateCallbackType(const osg::Node & node, const std::type_info & type);
00098
00102 PVLE_EXPORT osg::Image * createNormalMap(const osg::Image* image);
00103
00108 PVLE_EXPORT osg::Image * createHeightColorization(const osg::HeightField * pHF);
00109
00111 PVLE_EXPORT osg::StateSet* create1DTextureHeightColorization(const osg::HeightField * pHF);
00112
00114 PVLE_EXPORT void spotLightProcessing(osg::Image * pImage, float cutoff, float exponent, float constantAttenuation, float linearAttenuation, float quadraticAttenuation, float distFactor);
00115
00117 inline osg::Vec4::value_type luminance(const osg::Vec4 & color) { return (color.x() + color.y() + color.z()) / 3.f * color.w(); }
00118
00119
00120 #include <osg/GraphicsContext>
00121
00125 PVLE_EXPORT osg::GraphicsContext::ScreenSettings getClosestFullscreenResolution(const osg::GraphicsContext::ScreenIdentifier & si, const osg::GraphicsContext::ScreenSettings & resolution);
00126 PVLE_EXPORT std::ostream& operator<<(std::ostream& stream, const osg::GraphicsContext::ScreenSettings& settings);
00127
00128
00129 #include <boost/filesystem/path.hpp>
00130 #include <osgDB/ReaderWriter>
00131
00133 namespace osgDB {
00135 PVLE_EXPORT osg::Image * readImageFile(const boost::filesystem::path & path, const osgDB::ReaderWriter::Options* options);
00137 PVLE_EXPORT osg::Image * readImageFile(const boost::filesystem::path & path);
00139 PVLE_EXPORT void writeImageFile(const osg::Image & image, const boost::filesystem::path & path);
00140
00142 PVLE_EXPORT osg::Node * readNodeFile(const boost::filesystem::path & path, const osgDB::ReaderWriter::Options* options);
00144 PVLE_EXPORT osg::Node * readNodeFile(const boost::filesystem::path & path);
00146 PVLE_EXPORT void writeNodeFile(const osg::Node & node, const boost::filesystem::path & path);
00147 }
00148
00149
00150 #endif // _3D_UTILITY_H