00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * 変換ライトヘッダ 00022 * @author Junpee 00023 */ 00024 00025 #ifndef TRANSLATION_LIGHT_H_ 00026 #define TRANSLATION_LIGHT_H_ 00027 00028 namespace Lamp{ 00029 class Scene; 00030 } 00031 00032 namespace LampForMaya{ 00033 00034 class TranslationAmbientLight; 00035 class TranslationDirectionalLight; 00036 class TranslationPointLight; 00037 00038 //------------------------------------------------------------------------------ 00039 /** 00040 * 変換ライト 00041 */ 00042 class TranslationLight{ 00043 friend class TranslationLightManager; 00044 public: 00045 /** 00046 * デストラクタ 00047 */ 00048 virtual ~TranslationLight(); 00049 00050 /** 00051 * 分析 00052 * @return 成功すればtrue 00053 */ 00054 virtual bool analyze() = 0; 00055 00056 /** 00057 * Lampへの変換 00058 * @param scene シーン 00059 * @return 成功すればtrue 00060 */ 00061 virtual bool convertToLamp(Scene* scene) = 0; 00062 00063 /** 00064 * オブジェクトの取得 00065 * @return オブジェクト 00066 */ 00067 virtual MObject getObject() const{ return object_; } 00068 00069 /** 00070 * 名前の取得 00071 * @return 名前 00072 */ 00073 virtual String getName() const{ return name_; } 00074 00075 //-------------------------------------------------------------------------- 00076 // RTTI 00077 //-------------------------------------------------------------------------- 00078 /** 00079 * アンビエントライトかどうか 00080 * @return アンビエントライトならtrue 00081 */ 00082 virtual bool isAmbientLight() const{ return false; } 00083 00084 /** 00085 * アンビエントライトへのキャスト 00086 * @return アンビエントライト。型が違えばNULLを返す。 00087 */ 00088 virtual TranslationAmbientLight* castAmbientLight() const{ 00089 if(isAmbientLight()){ 00090 return (TranslationAmbientLight*)this; 00091 } 00092 return NULL; 00093 } 00094 00095 //-------------------------------------------------------------------------- 00096 /** 00097 * ディレクショナルライトかどうか 00098 * @return ディレクショナルライトならtrue 00099 */ 00100 virtual bool isDirectionalLight() const{ return false; } 00101 00102 /** 00103 * ディレクショナルライトへのキャスト 00104 * @return ディレクショナルライト。型が違えばNULLを返す。 00105 */ 00106 virtual TranslationDirectionalLight* castDirectionalLight() const{ 00107 if(isDirectionalLight()){ 00108 return (TranslationDirectionalLight*)this; 00109 } 00110 return NULL; 00111 } 00112 00113 //-------------------------------------------------------------------------- 00114 /** 00115 * ポイントライトかどうか 00116 * @return ポイントライトならtrue 00117 */ 00118 virtual bool isPointLight() const{ return false; } 00119 00120 /** 00121 * ポイントライトへのキャスト 00122 * @return ポイントライト。型が違えばNULLを返す。 00123 */ 00124 virtual TranslationPointLight* castPointLight() const{ 00125 if(isPointLight()){ 00126 return (TranslationPointLight*)this; 00127 } 00128 return NULL; 00129 } 00130 00131 //-------------------------------------------------------------------------- 00132 00133 protected: 00134 /** 00135 * コンストラクタ 00136 * @param initializeDagPath 初期化するDagパス 00137 * @param initializeName 初期化する名前 00138 */ 00139 TranslationLight( 00140 const MDagPath& initializeDagPath, const String& initializeName); 00141 00142 /** 00143 * ライトの分析 00144 */ 00145 virtual bool analyzeLight(); 00146 00147 /** 00148 * レンジの計算 00149 * @param decayRate 減衰率 00150 * @return レンジ 00151 */ 00152 virtual float calcRange(int decayRate){ 00153 // 減衰無し 00154 if(decayRate == 0){ 00155 return 1.84467435e+019f; 00156 } 00157 // 輝度を強さとする 00158 float luminance = exportColor_.r * 0.298912f + 00159 exportColor_.g * 0.586611f + exportColor_.b * 0.114477f; 00160 // 一次減衰 00161 if(decayRate == 1){ 00162 return minimumLightPower * luminance; 00163 // 二次減衰 00164 }else if(decayRate == 2){ 00165 return Math::sqrt(minimumLightPower * luminance); 00166 } 00167 return 0.f; 00168 } 00169 00170 /// Dagパス 00171 MDagPath dagPath_; 00172 /// オブジェクト 00173 MObject object_; 00174 /// 名前 00175 String name_; 00176 /// ライトカラー 00177 Color3f color_; 00178 /// 出力カラー 00179 Color3f exportColor_; 00180 /// ライト強度 00181 float intensity_; 00182 /// ライトマスク 00183 int lightMask_; 00184 /// 表示フラグ 00185 bool visibility_; 00186 00187 /// 最小ライト強度 00188 static float minimumLightPower; 00189 00190 private: 00191 // コピーコンストラクタの隠蔽 00192 TranslationLight(const TranslationLight& copy); 00193 00194 // 代入コピーの隠蔽 00195 void operator =(const TranslationLight& copy); 00196 00197 }; 00198 00199 //------------------------------------------------------------------------------ 00200 } // End of namespace LampForMaya 00201 #endif // End of TRANSLATION_LIGHT_H_ 00202 //------------------------------------------------------------------------------ 00203