ScummVM API documentation
Light3D.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_LIGHT3D_H
29 #define HPL_LIGHT3D_H
30 
31 #include "common/list.h"
32 #include "hpl1/engine/graphics/GraphicsTypes.h"
33 #include "hpl1/engine/graphics/Renderable.h"
34 #include "hpl1/engine/scene/Entity3D.h"
35 #include "hpl1/engine/scene/Light.h"
36 #include "hpl1/std/set.h"
37 
38 class TiXmlElement;
39 
40 namespace hpl {
41 
42 enum eLight3DType {
43  eLight3DType_Point,
44  eLight3DType_Spot,
45  eLight3DType_LastEnum
46 };
47 
48 enum eShadowVolumeType {
49  eShadowVolumeType_None,
50  eShadowVolumeType_ZPass,
51  eShadowVolumeType_ZFail,
52  eShadowVolumeType_LastEnum,
53 };
54 
55 class iLowLevelGraphics;
56 class cRenderSettings;
57 class cCamera3D;
58 class cFrustum;
59 class iGpuProgram;
60 class iTexture;
61 class cTextureManager;
62 class cResources;
63 class cFileSearcher;
64 class cBillboard;
65 class cSectorVisibilityContainer;
66 
67 typedef Hpl1::Std::set<iRenderable *> tCasterCacheSet;
68 typedef tCasterCacheSet::iterator tCasterCacheSetIt;
69 
70 //------------------------------------------
71 
72 kSaveData_ChildClass(iRenderable, iLight3D) {
73  kSaveData_ClassInit(iLight3D) public : tString msFalloffMap;
74  cContainerList<int> mlstBillboardIds;
75 
76  cColor mDiffuseColor;
77  cColor mSpecularColor;
78  float mfIntensity;
79  float mfFarAttenuation;
80  float mfNearAttenuation;
81  float mfSourceRadius;
82 
83  bool mbCastShadows;
84  bool mbAffectMaterial;
85 
86  cColor mColAdd;
87  float mfRadiusAdd;
88  cColor mDestCol;
89  float mfDestRadius;
90  float mfFadeTime;
91 
92  bool mbFlickering;
93  tString msFlickerOffSound;
94  tString msFlickerOnSound;
95  tString msFlickerOffPS;
96  tString msFlickerOnPS;
97  float mfFlickerOnMinLength;
98  float mfFlickerOffMinLength;
99  float mfFlickerOnMaxLength;
100  float mfFlickerOffMaxLength;
101  cColor mFlickerOffColor;
102  float mfFlickerOffRadius;
103  bool mbFlickerFade;
104  float mfFlickerOnFadeLength;
105  float mfFlickerOffFadeLength;
106 
107  cColor mFlickerOnColor;
108  float mfFlickerOnRadius;
109 
110  bool mbFlickerOn;
111  float mfFlickerTime;
112  float mfFlickerStateLength;
113 };
114 
115 //------------------------------------------
116 
117 class iLight3D : public iLight, public iRenderable {
118  typedef iRenderable super;
119 
120 public:
121  iLight3D(tString asName, cResources *apResources);
122  virtual ~iLight3D();
123 
124  void UpdateLogic(float afTimeStep);
125 
126  virtual void SetFarAttenuation(float afX);
127  virtual void SetNearAttenuation(float afX);
128 
129  cVector3f GetLightPosition();
130 
131  virtual bool BeginDraw(cRenderSettings *apRenderSettings, iLowLevelGraphics *apLowLevelGraphics);
132  virtual void EndDraw(cRenderSettings *apRenderSettings, iLowLevelGraphics *apLowLevelGraphics);
133 
134  bool CheckObjectIntersection(iRenderable *apObject);
135 
136  void AddShadowCaster(iRenderable *apObject, cFrustum *apFrustum, bool abStatic, cRenderList *apRenderList);
137  bool HasStaticCasters();
138  void ClearCasters(bool abClearStatic);
139 
140  void SetAllStaticCastersAdded(bool abX) { mbStaticCasterAdded = abX; }
141  bool AllStaticCastersAdded() { return mbStaticCasterAdded; }
142 
143  eLight3DType GetLightType() { return mLightType; }
144 
145  // iEntity implementation
146  tString GetEntityType() { return "iLight3D"; }
147 
148  bool IsVisible();
149  void SetVisible(bool abVisible);
150 
151  iTexture *GetFalloffMap();
152  void SetFalloffMap(iTexture *apTexture);
153 
154  // Renderable implementation:
155  iMaterial *GetMaterial() { return NULL; }
156  iVertexBuffer *GetVertexBuffer() { return NULL; }
157 
158  bool IsShadowCaster() { return false; }
159  eRenderableType GetRenderType() { return eRenderableType_Light; }
160 
161  cBoundingVolume *GetBoundingVolume();
162 
163  int GetMatrixUpdateCount() { return GetTransformUpdateCount(); }
164 
165  cMatrixf *GetModelMatrix(cCamera3D *apCamera);
166 
167  inline void RenderShadow(iRenderable *apObject, cRenderSettings *apRenderSettings, iLowLevelGraphics *apLowLevelGraphics);
168 
169  void LoadXMLProperties(const tString asFile);
170 
171  void AttachBillboard(cBillboard *apBillboard);
172  void RemoveBillboard(cBillboard *apBillboard);
173  Common::Array<cBillboard *> *GetBillboardVec() { return &mvBillboards; }
174 
175  inline iTexture *GetTempTexture(size_t alIdx) { return mvTempTextures[alIdx]; }
176  inline void SetTempTexture(size_t alIdx, iTexture *apTex) { mvTempTextures[alIdx] = apTex; }
177 
178  void SetOnlyAffectInSector(bool abX) { mbOnlyAffectInInSector = abX; }
179  bool GetOnlyAffectInSector() { return mbOnlyAffectInInSector; }
180 
181  // SaveObject implementation
182  virtual iSaveData *CreateSaveData();
183  virtual void SaveToSaveData(iSaveData *apSaveData);
184  virtual void LoadFromSaveData(iSaveData *apSaveData);
185  virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
186 
187 protected:
188  void OnFlickerOff();
189  void OnFlickerOn();
190  void OnSetDiffuse();
191 
192  virtual cSectorVisibilityContainer *CreateSectorVisibility() = 0;
193  virtual void ExtraXMLProperties(TiXmlElement *apMainElem) {}
194  virtual void UpdateBoundingVolume() = 0;
195  virtual bool CreateClipRect(cRect2l &aCliprect, cRenderSettings *apRenderSettings, iLowLevelGraphics *apLowLevelGraphics) = 0;
196 
197  eLight3DType mLightType;
198 
199  cTextureManager *mpTextureManager;
200  cFileSearcher *mpFileSearcher;
201 
202  iTexture *mpFalloffMap;
203 
204  iTexture *mvTempTextures[3];
205 
206  Common::Array<cBillboard *> mvBillboards;
207 
208  cMatrixf mtxTemp;
209 
210  tCasterCacheSet m_setStaticCasters;
211  tCasterCacheSet m_setDynamicCasters;
212 
213  bool mbStaticCasterAdded;
214 
215  bool mbOnlyAffectInInSector;
216 
217  int mlSectorVisibilityCount;
218  cSectorVisibilityContainer *mpVisSectorCont;
219 
220  unsigned int *mpIndexArray;
221 };
222 
225 
226 } // namespace hpl
227 
228 #endif // HPL_LIGHT3D_H
Definition: AI.h:36
Definition: Game.h:91
Definition: str.h:59
Definition: Renderer3D.h:77
int GetMatrixUpdateCount()
Definition: Light3D.h:163
Definition: VertexBuffer.h:90
Definition: array.h:52
Definition: Light3D.h:117
Definition: Texture.h:88
virtual iSaveData * CreateSaveData()
Definition: BoundingVolume.h:71
virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame)
Definition: Renderable.h:70
Definition: FileSearcher.h:43
Definition: Light.h:38
Definition: BillBoard.h:78
virtual void SaveToSaveData(iSaveData *apSaveData)
Definition: SaveGame.h:111
Definition: SectorVisibility.h:136
Definition: TextureManager.h:47
Definition: RenderList.h:145
Definition: Resources.h:160
Definition: Entity3D.h:81
Definition: tinyxml.h:864
Definition: list_intern.h:51
Definition: Material.h:203
virtual void LoadFromSaveData(iSaveData *apSaveData)
Definition: SaveGame.h:183
Definition: LowLevelGraphics.h:200
Definition: Camera3D.h:53
Definition: Frustum.h:57