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 DIRECTIONAL_LIHGT_H_ 00026 #define DIRECTIONAL_LIHGT_H_ 00027 00028 #include <Graphics/Light/GlobalLight.h> 00029 00030 namespace Lamp{ 00031 00032 //------------------------------------------------------------------------------ 00033 /** 00034 * ディレクショナルライト 00035 */ 00036 class DirectionalLight : public GlobalLight{ 00037 friend class LightManager; 00038 public: 00039 //-------------------------------------------------------------------------- 00040 /** 00041 * コピー 00042 * @param copyMask コピーマスク 00043 * @return コピーされたシーンリーフ 00044 */ 00045 virtual SceneLeaf* copy(u_int copyMask = 0) const{ 00046 return copyDirectionalLight(); 00047 } 00048 00049 /** 00050 * コピー 00051 * @return コピーされたライト 00052 */ 00053 virtual Light* copyLight() const{ return copyDirectionalLight(); } 00054 00055 /** 00056 * ディレクショナルライトのコピー 00057 * @return コピーされたモデル 00058 */ 00059 virtual DirectionalLight* copyDirectionalLight() const; 00060 00061 //-------------------------------------------------------------------------- 00062 /** 00063 * ライト色の設定 00064 * @param color ライト色 00065 */ 00066 virtual void setColor(const Color3f& color){ 00067 diffuseColor_ = specularColor_ = color; 00068 } 00069 00070 /** 00071 * ライト色の取得 00072 * @return ライト色 00073 */ 00074 virtual Color3f getColor() const{ 00075 Color3f result(Math::maximum(diffuseColor_.r, specularColor_.r), 00076 Math::maximum(diffuseColor_.g, specularColor_.g), 00077 Math::maximum(diffuseColor_.b, specularColor_.b)); 00078 return result; 00079 } 00080 00081 //-------------------------------------------------------------------------- 00082 /** 00083 * ディフューズライト色の設定 00084 * @param color ディフューズライト色 00085 */ 00086 virtual void setDiffuseColor(const Color3f& color){ diffuseColor_ = color; } 00087 00088 /** 00089 * ディフューズライト色の取得 00090 * @return ディフューズライト色 00091 */ 00092 virtual const Color3f& getDiffuseColor() const{ return diffuseColor_; } 00093 00094 //-------------------------------------------------------------------------- 00095 /** 00096 * スペキュラライト色の設定 00097 * @param color スペキュラライト色 00098 */ 00099 virtual void setSpecularColor(const Color3f& color){ 00100 specularColor_ = color; 00101 } 00102 00103 /** 00104 * スペキュラライト色の取得 00105 * @return スペキュラライト色 00106 */ 00107 virtual const Color3f& getSpecularColor() const{ return specularColor_; } 00108 00109 //-------------------------------------------------------------------------- 00110 /** 00111 * ライトの方向設定 00112 * @param direction ライトの方向 00113 */ 00114 virtual void setDirection(const Vector3& direction){ 00115 direction_ = direction; 00116 // 正規化しておく 00117 direction_.normalize(); 00118 } 00119 00120 /** 00121 * ライトの方向取得 00122 * @return ライトの方向 00123 */ 00124 virtual const Vector3& getDirection() const{ return direction_; } 00125 00126 /** 00127 * ライトのワールド方向取得 00128 * @return ライトのワールド方向 00129 */ 00130 virtual const Vector3& getWorldDirection() const{ 00131 Assert(getParent() != NULL); 00132 return worldDirection_; 00133 } 00134 00135 //-------------------------------------------------------------------------- 00136 /** 00137 * ディレクショナルライトかどうか 00138 * @return ディレクショナルライトならtrue 00139 */ 00140 virtual bool isDirectionalLight() const{ return true; } 00141 00142 protected: 00143 //-------------------------------------------------------------------------- 00144 /** 00145 * コンストラクタ 00146 * @param name 名前 00147 * @param scene シーン 00148 */ 00149 DirectionalLight(const String& name, Scene* scene); 00150 00151 /** 00152 * デストラクタ 00153 */ 00154 virtual ~DirectionalLight(); 00155 00156 //-------------------------------------------------------------------------- 00157 /** 00158 * 走査 00159 * @param parentMatrix 親行列 00160 * @param parentEnabled 親が有効か 00161 * @param parentScaled 親がスケールを使用しているか 00162 * @param parentChanged 親に変更があったか 00163 */ 00164 virtual void traverse(const Matrix34& parentMatrix, bool parentEnabled, 00165 bool parentScaled, bool parentChanged); 00166 00167 //-------------------------------------------------------------------------- 00168 private: 00169 // ディフューズカラー 00170 Color3f diffuseColor_; 00171 // スペキュラカラー 00172 Color3f specularColor_; 00173 // 方向 00174 Vector3 direction_; 00175 // ワールド方向 00176 Vector3 worldDirection_; 00177 00178 }; 00179 00180 //------------------------------------------------------------------------------ 00181 } // End of namespace Lamp 00182 #endif // End of DIRECTIONAL_LIHGT_H_ 00183 //------------------------------------------------------------------------------ 00184