~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/core/graphicsEngine/WGEUtils.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
10
// OpenWalnut is free software: you can redistribute it and/or modify
 
11
// it under the terms of the GNU Lesser General Public License as published by
 
12
// the Free Software Foundation, either version 3 of the License, or
 
13
// (at your option) any later version.
 
14
//
 
15
// OpenWalnut is distributed in the hope that it will be useful,
 
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
// GNU Lesser General Public License for more details.
 
19
//
 
20
// You should have received a copy of the GNU Lesser General Public License
 
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#ifndef WGEUTILS_H
 
26
#define WGEUTILS_H
 
27
 
 
28
#include <string>
 
29
#include <vector>
 
30
 
 
31
#include <boost/lexical_cast.hpp>
 
32
 
 
33
#include <osg/Array>
 
34
#include <osg/Vec3>
 
35
#include <osg/Vec4>
 
36
#include <osg/Camera>
 
37
 
 
38
#include "../common/WColor.h"
 
39
#include "../common/WAssert.h"
 
40
#include "../common/math/linearAlgebra/WLinearAlgebra.h"
 
41
 
 
42
#include "WExportWGE.h"
 
43
 
 
44
namespace wge
 
45
{
 
46
    /**
 
47
     * Transforms a direction given via two points into a RGB color.
 
48
     *
 
49
     * \param pos1 First point
 
50
     * \param pos2 Second point
 
51
     *
 
52
     * \return converts a vector to a color
 
53
     */
 
54
    WColor getRGBAColorFromDirection( const WPosition &pos1, const WPosition &pos2 );
 
55
 
 
56
    /**
 
57
     * Converts a whole vector of WPositions into an osg::Vec3Array.
 
58
     *
 
59
     * \param posArray The given positions vector
 
60
     *
 
61
     * \return Refernce to the same vector but as osg::Vec3Array.
 
62
     */
 
63
    osg::ref_ptr< osg::Vec3Array > WGE_EXPORT osgVec3Array( const std::vector< WPosition >& posArray );
 
64
 
 
65
    /**
 
66
     * Converts screen coordinates into Camera coordinates.
 
67
     *
 
68
     * \param screen the screen coordinates
 
69
     * \param camera The matrices of this camera will used for unprojecting.
 
70
     *
 
71
     * \return un-projects a screen coordinate back to world space
 
72
     */
 
73
    osg::Vec3 WGE_EXPORT unprojectFromScreen( const osg::Vec3 screen, osg::ref_ptr< osg::Camera > camera  );
 
74
 
 
75
    /**
 
76
     * creates the same color as the atlas colormap shader from the index
 
77
     *
 
78
     * \param index unsigned char that indexes the color
 
79
     * \return the color
 
80
     */
 
81
    WColor WGE_EXPORT createColorFromIndex( int index );
 
82
 
 
83
    /**
 
84
     * creates a rgb WColor from a HSV value
 
85
     * \param h hue
 
86
     * \param s saturation
 
87
     * \param v value
 
88
     * \return the color
 
89
     */
 
90
    WColor WGE_EXPORT createColorFromHSV( int h, float s = 1.0, float v = 1.0 );
 
91
 
 
92
    /**
 
93
     * creates the nth color of a partition of the hsv color circle
 
94
     *
 
95
     * \param n number of the color
 
96
     * \return the color
 
97
     */
 
98
    WColor WGE_EXPORT getNthHSVColor( int n );
 
99
}
 
100
 
 
101
inline WColor wge::getRGBAColorFromDirection( const WPosition &pos1, const WPosition &pos2 )
 
102
{
 
103
    WPosition direction( normalize( pos2 - pos1 ) );
 
104
    return WColor( std::abs( direction[0] ), std::abs( direction[1] ), std::abs( direction[2] ), 1.0f );
 
105
}
 
106
 
 
107
#endif  // WGEUTILS_H
 
108