PageRenderTime 46ms CodeModel.GetById 14ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/opengles/src/Light.h

http://ftk.googlecode.com/
C++ Header | 182 lines | 94 code | 42 blank | 46 comment | 0 complexity | b8f2258d4332bef2272071b45dc442db MD5 | raw file
  1#ifndef EGL_LIGHT_H
  2#define EGL_LIGHT_H 1
  3
  4// ==========================================================================
  5//
  6// Light.h			Light Class for 3D Rendering Library
  7//
  8// --------------------------------------------------------------------------
  9//
 10// 09-14-2003		Hans-Martin Will	initial version
 11//
 12// --------------------------------------------------------------------------
 13//
 14// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
 15// 
 16// Redistribution and use in source and binary forms, with or without 
 17// modification, are permitted provided that the following conditions are 
 18// met:
 19// 
 20//	 *  Redistributions of source code must retain the above copyright
 21// 		notice, this list of conditions and the following disclaimer. 
 22//   *	Redistributions in binary form must reproduce the above copyright
 23// 		notice, this list of conditions and the following disclaimer in the 
 24// 		documentation and/or other materials provided with the distribution. 
 25// 
 26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 27// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 29// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 30// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 31// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 32// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 33// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 34// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 35// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 36// THE POSSIBILITY OF SUCH DAMAGE.
 37//
 38// ==========================================================================
 39
 40
 41
 42#include "OGLES.h"
 43#include "linalg.h"
 44#include "FractionalColor.h"
 45
 46
 47namespace EGL {
 48
 49	class Material;
 50
 51
 52	class Light {
 53
 54	public:
 55		Light();
 56
 57		void SetAmbientColor(const FractionalColor & color);
 58		FractionalColor GetAmbientColor() const;
 59
 60		void SetDiffuseColor(const FractionalColor & color);
 61		FractionalColor GetDiffuseColor() const;
 62
 63		void SetSpecularColor(const FractionalColor & color);
 64		FractionalColor GetSpecularColor() const;
 65
 66		void SetPosition(const Vec4D & position);
 67		Vec4D GetPosition() const;
 68
 69		void SetDirection(const Vec3D & direction);
 70		Vec3D GetNormalizedDirection() const;
 71		Vec3D GetDirection() const;
 72
 73		void SetConstantAttenuation(EGL_Fixed attenuation);
 74		EGL_Fixed GetConstantAttenuation() const;
 75
 76		void SetLinearAttenuation(EGL_Fixed attenuation);
 77		EGL_Fixed GetLinearAttenuation() const;
 78
 79		void SetQuadraticAttenuation(EGL_Fixed attenuation);
 80		EGL_Fixed GetQuadraticAttenuation() const;
 81
 82		void SetSpotExponent(EGL_Fixed exponent);
 83		EGL_Fixed GetSpotExponent() const;
 84
 85		void SetSpotCutoff(EGL_Fixed cutoff);
 86		EGL_Fixed GetSpotCutoff() const;
 87
 88		void InitWithMaterial(const Material& material);
 89
 90		// one-sided lightning
 91		// TO DO:
 92		// create version for: light at infinity or light at location
 93		// spot light vs. point light
 94		// color material vs. material color
 95		void AccumulateLight(const Vec4D& vertexCoords, const Vec3D& vertexNormal, 
 96			const Material& currMaterial, FractionalColor& result);
 97
 98		void AccumulateLight(const Vec4D& vertexCoords, const Vec3D& vertexNormal, 
 99			const Material& currMaterial, const FractionalColor& currentColor, FractionalColor& result);
100
101
102		// two-sided lightning
103		// TO DO:
104		// create version for: light at infinity or light at location
105		// spot light vs. point light
106		// color material vs. material color
107		void AccumulateLight2(const Vec4D& vertexCoords, const Vec3D& vertexNormal, 
108			const Material& currMaterial, FractionalColor& result, 
109			FractionalColor& result2);
110
111		void AccumulateLight2(const Vec4D& vertexCoords, const Vec3D& vertexNormal, 
112			const Material& currMaterial, const FractionalColor& currentColor, FractionalColor& result, 
113			FractionalColor& result2);
114
115	private:
116		FractionalColor			m_AmbientColor;
117		FractionalColor			m_DiffuseColor;
118		FractionalColor			m_SpecularColor;
119		Vec4D					m_Position;
120		Vec3D					m_NormalizedSpotDirection;
121		Vec3D					m_SpotDirection;
122		EGL_Fixed				m_ConstantAttenuation;
123		EGL_Fixed				m_LinearAttenuation;
124		EGL_Fixed				m_QuadraticAttenuation;
125		EGL_Fixed				m_SpotExponent;
126		EGL_Fixed				m_SpotCutoff;
127		EGL_Fixed				m_CosineSpotCutoff;
128
129		// effective color contributions for current material settings
130		FractionalColor			m_EffectiveAmbientColor;
131		FractionalColor			m_EffectiveDiffuseColor;
132		FractionalColor			m_EffectiveSpecularColor;
133	};
134
135
136	inline FractionalColor Light :: GetAmbientColor() const {
137		return m_AmbientColor;
138	}
139
140	inline FractionalColor Light :: GetDiffuseColor() const {
141		return m_DiffuseColor;
142	}
143
144	inline FractionalColor Light :: GetSpecularColor() const {
145		return m_SpecularColor;
146	}
147
148	inline Vec4D Light :: GetPosition() const {
149		return m_Position;
150	}
151
152	inline Vec3D Light :: GetNormalizedDirection() const {
153		return m_NormalizedSpotDirection;
154	}
155
156	inline Vec3D Light :: GetDirection() const {
157		return m_SpotDirection;
158	}
159
160	inline EGL_Fixed Light :: GetConstantAttenuation() const {
161		return m_ConstantAttenuation;
162	}
163
164	inline EGL_Fixed Light :: GetLinearAttenuation() const {
165		return m_LinearAttenuation;
166	}
167
168	inline EGL_Fixed Light :: GetQuadraticAttenuation() const {
169		return m_QuadraticAttenuation;
170	}
171
172	inline EGL_Fixed Light :: GetSpotExponent() const {
173		return m_SpotExponent;
174	}
175
176	inline EGL_Fixed Light :: GetSpotCutoff() const {
177		return m_SpotCutoff;
178	}
179
180}
181
182#endif //ndef EGL_LIGHT_H