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
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.
18 * @file SkyCloudParticle.hpp
20 * Definition of a simple cloud particle class.
22 #ifndef __SKYCLOUDPARTICLE_HPP__
23 #define __SKYCLOUDPARTICLE_HPP__
29 //------------------------------------------------------------------------------
31 * @class SkyCloudParticle
32 * @brief A class for particles that make up a cloud.
34 * @todo <WRITE EXTENDED CLASS DESCRIPTION>
36 class SkyCloudParticle
39 inline SkyCloudParticle();
40 inline SkyCloudParticle(const Vec3f& pos,
42 const Vec4f& baseColor,
43 float rTransparency = 0);
44 inline ~SkyCloudParticle();
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; }
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; }
76 //! This operator is used to sort particle arrays from nearest to farthes.
77 bool operator<(const SkyCloudParticle& p) const
79 return (_rSquareSortDistance < p._rSquareSortDistance);
82 //! This operator is used to sort particle arrays from farthest to nearest.
83 bool operator>(const SkyCloudParticle& p) const
85 return (_rSquareSortDistance > p._rSquareSortDistance);
93 std::vector<Vec4f> _vecLitColors;
96 // for sorting particles during shading
97 float _rSquareSortDistance;
100 //------------------------------------------------------------------------------
101 // Function : SkyCloudParticle::SkyCloudParticle
103 //------------------------------------------------------------------------------
105 * @fn SkyCloudParticle::SkyCloudParticle()
106 * @brief Default constructor.
108 inline SkyCloudParticle::SkyCloudParticle()
111 _vecPosition(0, 0, 0),
112 _vecBaseColor(0, 0, 0, 1),
114 _rSquareSortDistance(0)
116 _vecLitColors.clear();
120 //------------------------------------------------------------------------------
121 // Function : SkyCloudParticle::SkyCloudParticle
123 //------------------------------------------------------------------------------
125 * @fn SkyCloudParticle::SkyCloudParticle(const Vec3f& pos, float rRadius, const Vec4f& baseColor, float rTransparency)
126 * @brief Constructor.
128 inline SkyCloudParticle::SkyCloudParticle(const Vec3f& pos,
130 const Vec4f& baseColor,
131 float rTransparency /* = 0 */)
133 _rTransparency(rTransparency),
135 _vecBaseColor(baseColor),
137 _rSquareSortDistance(0)
139 _vecLitColors.clear();
143 //------------------------------------------------------------------------------
144 // Function : SkyCloudParticle::~SkyCloudParticle
146 //------------------------------------------------------------------------------
148 * @fn SkyCloudParticle::~SkyCloudParticle()
151 inline SkyCloudParticle::~SkyCloudParticle()
153 _vecLitColors.clear();
157 //------------------------------------------------------------------------------
158 // Function : Vec4f& SkyCloudParticle::GetLitColor
160 //------------------------------------------------------------------------------
162 * @fn Vec4f& SkyCloudParticle::GetLitColor(unsigned int index) const
163 * @brief Returns the lit color specified by index.
165 * If the index is out of range, returns a zero vector.
167 inline const Vec4f& SkyCloudParticle::GetLitColor(unsigned int index) const
169 if (index <= _vecLitColors.size())
170 return _vecLitColors[index];
175 #endif //__SKYCLOUDPARTICLE_HPP__