00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00069 if(!parentScaled){
00070 globalRange_ = range_;
00071 }else{
00072
00073
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 }
00089