Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

PointLight.cpp

Go to the documentation of this file.
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 #include "LampBasic.h"
00026 #include "Graphics/Light/PointLight.h"
00027 #include "Graphics/Scene/Scene.h"
00028 #include "Graphics/Light/LightManager.h"
00029 
00030 namespace Lamp{
00031 
00032 //------------------------------------------------------------------------------
00033 // コンストラクタ
00034 PointLight::PointLight(const String& name, Scene* scene) :
00035     LocalLight(name, scene), diffuseColor_(Color3f::white),
00036     specularColor_(Color3f::white), position_(0.f, 0.f, 0.f),
00037     worldPosition_(0.f, 0.f, 0.f), range_(Limit::floatMaxSqrt),
00038     globalRange_(Limit::floatMaxSqrt), attenuation0_(1.f), attenuation1_(0.f),
00039     attenuation2_(0.f), squaredCameraDistance_(0.f){
00040 }
00041 //------------------------------------------------------------------------------
00042 // デストラクタ
00043 PointLight::~PointLight(){
00044 }
00045 //------------------------------------------------------------------------------
00046 // ポイントライトのコピー
00047 PointLight* PointLight::copyPointLight() const{
00048     LightManager* manager = scene_->getLightManager();
00049     PointLight* copyLight =
00050         manager->createPointLight(manager->rename(name_));
00051     // ライトの値コピー
00052     copyLightValue(copyLight);
00053     // メンバのコピー
00054     copyLight->setDiffuseColor(diffuseColor_);
00055     copyLight->setSpecularColor(specularColor_);
00056     copyLight->setPosition(position_);
00057     copyLight->setRange(range_);
00058     copyLight->setAttenuation(attenuation0_, attenuation1_, attenuation2_);
00059     return copyLight;
00060 }
00061 //------------------------------------------------------------------------------
00062 // 走査
00063 void PointLight::traverse(const Matrix34& parentMatrix,
00064     bool parentEnabled, bool parentScaled, bool parentChanged){
00065     Light::traverse(parentMatrix, parentEnabled, parentScaled, parentChanged);
00066     // 位置をワールド座標に変換
00067     worldPosition_ = parentMatrix * position_;
00068     // ライトに対するスケールの判断微妙。Assert(false);で止めたほうがいいかも
00069     if(!parentScaled){
00070         globalRange_ = range_;
00071     }else{
00072         // スケールがかかっていた場合は半径を各軸の最大値にする
00073         // ベクトル(1,0,0),(0,1,0),(0,0,1)を変換して最長の長さを半径に乗算
00074         float maxSquardLength = 0.f;
00075         for(int i = 0; i < 3; i++){
00076             float squaredLength =
00077                 parentMatrix.m[0][i] * parentMatrix.m[0][i] +
00078                 parentMatrix.m[1][i] * parentMatrix.m[1][i] +
00079                 parentMatrix.m[2][i] * parentMatrix.m[2][i];
00080             if(squaredLength > maxSquardLength){
00081                 maxSquardLength = squaredLength;
00082             }
00083         }
00084         globalRange_ = range_ * Math::sqrt(maxSquardLength);
00085     }
00086 }
00087 //------------------------------------------------------------------------------
00088 } // End of namespace Lamp
00089 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:33 2005 for Lamp by doxygen 1.3.2