]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/SkyCloudParticle.hpp
A first attempt at making the clouds3d endian aware. Almost there.
[simgear.git] / simgear / scene / sky / clouds3d / SkyCloudParticle.hpp
1 //------------------------------------------------------------------------------
2 // File : SkyCloudParticle.hpp
3 //------------------------------------------------------------------------------
4 // SkyWorks : Copyright 2002 Mark J. Harris and
5 //                                              The University of North Carolina at Chapel Hill
6 //------------------------------------------------------------------------------
7 // Permission to use, copy, modify, distribute and sell this software and its 
8 // documentation for any purpose is hereby granted without fee, provided that 
9 // the above copyright notice appear in all copies and that both that copyright 
10 // notice and this permission notice appear in supporting documentation. 
11 // Binaries may be compiled with this software without any royalties or 
12 // restrictions. 
13 //
14 // The author(s) and The University of North Carolina at Chapel Hill make no 
15 // representations about the suitability of this software for any purpose. 
16 // It is provided "as is" without express or implied warranty.
17 /**
18  * @file SkyCloudParticle.hpp
19  * 
20  * Definition of a simple cloud particle class.
21  */
22 #ifndef __SKYCLOUDPARTICLE_HPP__
23 #define __SKYCLOUDPARTICLE_HPP__
24
25 #include "vec3f.hpp"
26 #include "vec4f.hpp"
27 #include <vector>
28
29 //------------------------------------------------------------------------------
30 /**
31  * @class SkyCloudParticle
32  * @brief A class for particles that make up a cloud.
33  * 
34  * @todo <WRITE EXTENDED CLASS DESCRIPTION>
35  */
36 class SkyCloudParticle
37 {
38 public:
39   inline SkyCloudParticle();
40   inline SkyCloudParticle(const Vec3f& pos, 
41                           float rRadius, 
42                           const Vec4f& baseColor, 
43                           float rTransparency = 0);
44   inline ~SkyCloudParticle();
45
46   //! Returns the radius of the particle.
47   float               GetRadius() const               { return _rRadius;        }
48   //! Returns the transparency of the particle.
49   float               GetTransparency() const         { return _rTransparency;  }
50   //! Returns the position of the particle.
51   const Vec3f&        GetPosition() const             { return _vecPosition;  }
52   //! Returns the base color of the particle.  This is often used for ambient color.
53   const Vec4f&        GetBaseColor() const            { return _vecBaseColor; }
54   //! Returns the number of light contributions to this particle's color.
55   unsigned int        GetNumLitColors() const         { return _vecLitColors.size();  }
56   //! Returns the light contribution to the color of this particle from light @a index.
57   inline const Vec4f& GetLitColor(unsigned int index) const;
58   //! Returns the square distance from the sort position used for the operator< in sorts / splits.
59   float               GetSquareSortDistance() const   { return _rSquareSortDistance; }
60
61   //! Sets the radius of the particle.
62   void                SetRadius(float rad)            { _rRadius      = rad;    }
63   //! Returns the transparency of the particle.
64   void                SetTransparency(float trans)    { _rTransparency = trans; }
65   //! Sets the position of the particle.
66   void                SetPosition(const Vec3f& pos)   { _vecPosition  = pos;  }
67   //! Sets the base color of the particle.  This is often used for ambient color.
68   void                SetBaseColor(const Vec4f& col)  { _vecBaseColor = col;  }
69   //! Sets the light contribution to the color of this particle from light @a index.
70   void                AddLitColor(const Vec4f& col)   { _vecLitColors.push_back(col); }
71   //! Clears the list of light contributions.
72   void                ClearLitColors()                { _vecLitColors.clear();        }
73   //! Sets the square distance from the sort position used for the operator< in sorts.
74   void                SetSquareSortDistance(float rSquareDistance) { _rSquareSortDistance = rSquareDistance; }
75
76   //! This operator is used to sort particle arrays from nearest to farthes.
77   bool operator<(const SkyCloudParticle& p) const
78         {
79     return (_rSquareSortDistance < p._rSquareSortDistance);
80         }
81
82   //! This operator is used to sort particle arrays from farthest to nearest.
83   bool operator>(const SkyCloudParticle& p) const
84   {
85     return (_rSquareSortDistance > p._rSquareSortDistance);
86   }
87   
88 protected: 
89   float               _rRadius;
90   float               _rTransparency;
91   Vec3f               _vecPosition;
92   Vec4f               _vecBaseColor;
93   std::vector<Vec4f>  _vecLitColors;
94   Vec3f               _vecEye; 
95
96   // for sorting particles during shading
97   float               _rSquareSortDistance;
98 };
99
100 //------------------------------------------------------------------------------
101 // Function               : SkyCloudParticle::SkyCloudParticle
102 // Description      : 
103 //------------------------------------------------------------------------------
104 /**
105  * @fn SkyCloudParticle::SkyCloudParticle()
106  * @brief Default constructor.
107  */ 
108 inline SkyCloudParticle::SkyCloudParticle()
109 : _rRadius(0),
110   _rTransparency(0),
111   _vecPosition(0, 0, 0),
112   _vecBaseColor(0, 0, 0, 1),
113   _vecEye(0, 0, 0),
114   _rSquareSortDistance(0)
115 {
116   _vecLitColors.clear();
117 }
118
119
120 //------------------------------------------------------------------------------
121 // Function               : SkyCloudParticle::SkyCloudParticle
122 // Description      : 
123 //------------------------------------------------------------------------------
124 /**
125  * @fn SkyCloudParticle::SkyCloudParticle(const Vec3f& pos, float rRadius, const Vec4f& baseColor, float rTransparency)
126  * @brief Constructor.
127  */ 
128 inline SkyCloudParticle::SkyCloudParticle(const Vec3f& pos, 
129                                           float rRadius, 
130                                           const Vec4f& baseColor,
131                                           float rTransparency /* = 0 */)
132 : _rRadius(rRadius),
133   _rTransparency(rTransparency),
134   _vecPosition(pos),
135   _vecBaseColor(baseColor),
136   _vecEye(0, 0, 0),
137   _rSquareSortDistance(0)
138 {
139   _vecLitColors.clear();
140 }
141
142
143 //------------------------------------------------------------------------------
144 // Function               : SkyCloudParticle::~SkyCloudParticle
145 // Description      : 
146 //------------------------------------------------------------------------------
147 /**
148  * @fn SkyCloudParticle::~SkyCloudParticle()
149  * @brief Destructor.
150  */ 
151 inline SkyCloudParticle::~SkyCloudParticle()
152 {
153   _vecLitColors.clear();
154 }
155
156
157 //------------------------------------------------------------------------------
158 // Function               : Vec4f& SkyCloudParticle::GetLitColor
159 // Description      : 
160 //------------------------------------------------------------------------------
161 /**
162  * @fn Vec4f& SkyCloudParticle::GetLitColor(unsigned int index) const
163  * @brief Returns the lit color specified by index.
164  * 
165  * If the index is out of range, returns a zero vector.
166  */ 
167 inline const Vec4f& SkyCloudParticle::GetLitColor(unsigned int index) const
168 {
169   if (index <= _vecLitColors.size())
170     return _vecLitColors[index];
171   else
172     return Vec4f::ZERO;
173 }
174
175 #endif //__SKYCLOUDPARTICLE_HPP__