OpenWalnut 1.3.1
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGEUTILS_H 00026 #define WGEUTILS_H 00027 00028 #include <string> 00029 #include <vector> 00030 00031 00032 #include <osg/Array> 00033 #include <osg/Vec3> 00034 #include <osg/Vec4> 00035 #include <osg/Camera> 00036 00037 #include "../common/WColor.h" 00038 #include "../common/WAssert.h" 00039 #include "../common/math/linearAlgebra/WLinearAlgebra.h" 00040 00041 namespace wge 00042 { 00043 /** 00044 * Enable transparency for the given node. This enabled blending and sets the node to the transparency bin. 00045 * 00046 * \param node the node 00047 */ 00048 void enableTransparency( osg::ref_ptr< osg::Node > node ); 00049 00050 /** 00051 * Transforms a direction given via two points into a RGB color. 00052 * 00053 * \param pos1 First point 00054 * \param pos2 Second point 00055 * 00056 * \return converts a vector to a color 00057 */ 00058 WColor getRGBAColorFromDirection( const WPosition &pos1, const WPosition &pos2 ); 00059 00060 /** 00061 * Converts a whole vector of WPositions into an osg::Vec3Array. 00062 * 00063 * \param posArray The given positions vector 00064 * 00065 * \return Refernce to the same vector but as osg::Vec3Array. 00066 */ 00067 osg::ref_ptr< osg::Vec3Array > osgVec3Array( const std::vector< WPosition >& posArray ); 00068 00069 /** 00070 * Converts screen coordinates into Camera coordinates. 00071 * 00072 * \param screen the screen coordinates 00073 * \param camera The matrices of this camera will used for unprojecting. 00074 * 00075 * \return un-projects a screen coordinate back to world space 00076 */ 00077 osg::Vec3 unprojectFromScreen( const osg::Vec3 screen, osg::ref_ptr< osg::Camera > camera ); 00078 00079 /** 00080 * Converts screen coordinates into Camera coordinates. 00081 * \note this method can be useful to work with vectors (w component 0) 00082 * 00083 * \param screen the screen coordinates 00084 * \param camera The matrices of this camera will used for unprojecting. 00085 * 00086 * \return un-projects a screen coordinate back to world space 00087 */ 00088 osg::Vec4 unprojectFromScreen( const osg::Vec4 screen, osg::ref_ptr< osg::Camera > camera ); 00089 00090 /** 00091 * creates the same color as the atlas colormap shader from the index 00092 * 00093 * \param index unsigned char that indexes the color 00094 * \return the color 00095 */ 00096 WColor createColorFromIndex( int index ); 00097 00098 /** 00099 * creates a rgb WColor from a HSV value 00100 * \param h hue 00101 * \param s saturation 00102 * \param v value 00103 * \return the color 00104 */ 00105 WColor createColorFromHSV( int h, float s = 1.0, float v = 1.0 ); 00106 00107 /** 00108 * creates the nth color of a partition of the hsv color circle 00109 * 00110 * \param n number of the color 00111 * \return the color 00112 */ 00113 WColor getNthHSVColor( int n ); 00114 } 00115 00116 inline WColor wge::getRGBAColorFromDirection( const WPosition &pos1, const WPosition &pos2 ) 00117 { 00118 WPosition direction( normalize( pos2 - pos1 ) ); 00119 return WColor( std::abs( direction[0] ), std::abs( direction[1] ), std::abs( direction[2] ), 1.0f ); 00120 } 00121 00122 #endif // WGEUTILS_H 00123