OpenWalnut 1.2.5

WGEUtils.h

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 #include <boost/lexical_cast.hpp>
00032 
00033 #include <osg/Array>
00034 #include <osg/Vec3>
00035 #include <osg/Vec4>
00036 #include <osg/Camera>
00037 
00038 #include "../common/WColor.h"
00039 #include "../common/WAssert.h"
00040 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
00041 
00042 #include "WExportWGE.h"
00043 
00044 namespace wge
00045 {
00046     /**
00047      * Transforms a direction given via two points into a RGB color.
00048      *
00049      * \param pos1 First point
00050      * \param pos2 Second point
00051      *
00052      * \return converts a vector to a color
00053      */
00054     WColor getRGBAColorFromDirection( const WPosition &pos1, const WPosition &pos2 );
00055 
00056     /**
00057      * Converts a whole vector of WPositions into an osg::Vec3Array.
00058      *
00059      * \param posArray The given positions vector
00060      *
00061      * \return Refernce to the same vector but as osg::Vec3Array.
00062      */
00063     osg::ref_ptr< osg::Vec3Array > WGE_EXPORT osgVec3Array( const std::vector< WPosition >& posArray );
00064 
00065     /**
00066      * Converts screen coordinates into Camera coordinates.
00067      *
00068      * \param screen the screen coordinates
00069      * \param camera The matrices of this camera will used for unprojecting.
00070      *
00071      * \return un-projects a screen coordinate back to world space
00072      */
00073     osg::Vec3 WGE_EXPORT unprojectFromScreen( const osg::Vec3 screen, osg::ref_ptr< osg::Camera > camera  );
00074 
00075     /**
00076      * creates the same color as the atlas colormap shader from the index
00077      *
00078      * \param index unsigned char that indexes the color
00079      * \return the color
00080      */
00081     WColor WGE_EXPORT createColorFromIndex( int index );
00082 
00083     /**
00084      * creates a rgb WColor from a HSV value
00085      * \param h hue
00086      * \param s saturation
00087      * \param v value
00088      * \return the color
00089      */
00090     WColor WGE_EXPORT createColorFromHSV( int h, float s = 1.0, float v = 1.0 );
00091 
00092     /**
00093      * creates the nth color of a partition of the hsv color circle
00094      *
00095      * \param n number of the color
00096      * \return the color
00097      */
00098     WColor WGE_EXPORT getNthHSVColor( int n );
00099 }
00100 
00101 inline WColor wge::getRGBAColorFromDirection( const WPosition &pos1, const WPosition &pos2 )
00102 {
00103     WPosition direction( normalize( pos2 - pos1 ) );
00104     return WColor( std::abs( direction[0] ), std::abs( direction[1] ), std::abs( direction[2] ), 1.0f );
00105 }
00106 
00107 #endif  // WGEUTILS_H
00108 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends