00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc. 00002 // 00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., 00004 // and considered a trade secret as defined under civil and criminal statutes. 00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of 00006 // unauthorized use or misappropriation of its trade secrets. Use of this information 00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under 00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use. 00009 00010 // HUtilityShadow.h : interface of the HUtilityShadow classes 00011 // Set of utility methods for shadow creations 00012 00017 #ifndef _HUTILITYSHADOW_H 00018 #define _HUTILITYSHADOW_H 00019 00020 #ifdef H_PACK_8 00021 #pragma pack(push) 00022 #pragma pack(8) 00023 #endif 00024 00025 #include "HTools.h" 00026 00027 00028 class HBaseView; 00029 class HPixelRGB; 00030 class HPixelRGBA; 00031 00032 00036 enum ShadowPlaneType 00037 { 00038 XZ_PLANE, 00039 XY_PLANE, 00040 YZ_PLANE 00041 }; 00042 00043 00045 00093 class MVO_API HShadow 00094 { 00095 public: 00096 00102 HShadow(HC_KEY ModelSegmentKey, HC_KEY ShadowBaseSegmentKey, float *ObjectModellingMatrix = 0); 00103 00107 void CalculateTotalModelExtents(); 00108 00110 void GetModelExtents(HPoint &ObjectBoundingMin, HPoint &ObjectBoundingMax) 00111 { 00112 ObjectBoundingMin = m_ObjectBoundingMin; 00113 ObjectBoundingMax = m_ObjectBoundingMax; 00114 } 00115 00117 void GetShadowLightPos(HPoint &lightpos) { lightpos = m_ShadowLightPos; } 00119 void GetShadowGroundPlane(HPlane &plane) { plane = m_ShadowGroundPlane; } 00121 HC_KEY GetShadowKey() { return m_ShadowSegmentKey; } 00122 00124 void SetShadowLightPos(HPoint lightpos) { m_ShadowLightPos = lightpos; } 00126 void SetShadowGroundPlane(HPlane plane) { m_ShadowGroundPlane = plane; } 00127 00129 void SetShadowBrightness(int ShadowBrightness) { m_ShadowBrightness = ShadowBrightness; } 00131 int GetShadowBrightness() { return m_ShadowBrightness; } 00132 00133 protected: 00134 bool m_bFirstCoordinate; 00136 HC_KEY m_ModelSegmentKey; 00137 HC_KEY m_ShadowSegmentKey; 00138 int m_ShadowBrightness; 00140 HPoint m_ShadowLightPos; 00141 HPlane m_ShadowGroundPlane; 00143 HPoint m_ObjectBoundingMin; 00144 HPoint m_ObjectBoundingMax; 00146 float m_ObjectModellingMatrix[16]; 00154 void ShowModellingMatrix(HC_KEY segkey, float * oldmatrix, float * newmatrix); 00155 00163 void ComputeObjectExtents(HPoint &min, HPoint &max, HPoint *points, int numpoints); 00164 00170 void RotateToGroundPlane(HPlane plane, float *matrix); 00171 00178 void ShadowMatrix2(float *matrix, HPlane plane, HPoint d); 00179 00183 HC_KEY IsolateShell(); 00184 00188 void RestoreShell(); 00189 00190 00195 bool HasShell(HC_KEY segKey); 00196 00197 private: 00198 void CalculateModelExtents(HC_KEY SegKey, float *totalmatrix); 00199 void SetIdentityMatrix(float *matrix); 00200 void ShadowMatrix(float *mm, HPlane plane, HPoint light); 00201 00202 00203 }; 00204 00206 00209 class MVO_API HSmoothShadow : public HShadow 00210 { 00211 00212 public: 00217 HSmoothShadow(HC_KEY ModelSegmentKey, HC_KEY ShadowBaseSegmentKey, bool UseOglShadow = false); 00218 virtual ~HSmoothShadow(); 00222 void CleanUp(); 00223 00230 void Create(ShadowPlaneType ptype, int TextureSize = 0, int FilterSize = -1, int *filter = 0); 00231 00235 void Create(); 00236 00238 int GetFilterSize() { return m_FilterSize; } 00239 00241 int GetTextureSize() { return m_TextureSize; } 00242 00247 void SetTextureSize(int TextureSize) { m_TextureSize = TextureSize; } 00248 00254 void SetFilter(int *filter, int FilterSize) { m_filter = filter; m_FilterSize = FilterSize; } 00255 00258 void UnDefineShadowTexture(); 00261 static void UnDefineAllShadowTextures(HC_KEY modelsegmentkey); 00262 00267 void SetAllowOpenglShadow(bool AllowOpenglShadow) { m_bAllowOpenglShadow = AllowOpenglShadow; } 00268 protected: 00269 int m_TextureSize; 00270 int m_FilterSize; 00271 int *m_filter; 00272 HC_KEY m_ImageKey; 00273 HPoint m_ShadowBoundingMin; 00274 HPoint m_ShadowBoundingMax; 00275 char m_texname[MVO_SMALL_BUFFER_SIZE]; 00276 bool m_bAllowOpenglShadow; 00277 00280 void CalculateTotalShadowExtents(); 00281 00287 void CalculateShadowExtents(HC_KEY segkey,float *totalmatrix); 00288 00292 void CreateSoftShadow(); 00293 00297 void CreateShadowTexture(); 00298 00307 void SmoothImage(HPixelRGB *origImage, HPixelRGBA **smoothImage, int width, int height, int filterSize, int *filter); 00308 00309 private: 00310 void CalculateOneShadowExtent(HC_KEY shellkey, float *modellingMatrix); 00311 00312 }; 00313 00314 00316 class MVO_API HHardShadow : public HShadow 00317 { 00318 00319 public: 00321 HHardShadow(HC_KEY ModelSegmentKey, HC_KEY ShadowBaseSegmentKey) : HShadow(ModelSegmentKey, ShadowBaseSegmentKey) {} 00322 00323 virtual ~HHardShadow() {}; 00324 00325 00330 void Create(ShadowPlaneType ptype); 00331 00335 virtual void Create(); 00336 00337 protected: 00338 00342 void CreateHardShadow(); 00343 00344 }; 00345 00346 00347 00348 #ifdef H_PACK_8 00349 #pragma pack(pop) 00350 #endif 00351 00352 #endif 00353 00354 00355