00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OpenSpace3D 00004 For the latest info, see http://www.openspace3d.com 00005 00006 Copyright (c) 2010 I-maginer 00007 00008 This program is free software; you can redistribute it and/or modify it under 00009 the terms of the GNU Lesser General Public License as published by the Free Software 00010 Foundation; either version 2 of the License, or (at your option) any later 00011 version. 00012 00013 This program is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License along with 00018 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00019 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00020 http://www.gnu.org/copyleft/lesser.txt 00021 00022 You may alternatively use this source under the terms of a specific version of 00023 the OpenSpace3D Unrestricted License provided you have obtained such a license from 00024 I-maginer. 00025 ----------------------------------------------------------------------------- 00026 */ 00027 00035 #include "SO3SkyLight.h" 00036 #include "SO3Environment.h" 00037 #include "SO3Scene.h" 00038 00039 namespace SO3 00040 { 00041 00042 SSkyLight::SSkyLight(SEnvironment* parent, std::string skyLightName) : SData(skyLightName) 00043 { 00044 parentEnvironment = parent; 00045 ogreSceneManager = parent->GetScene()->GetOgreScenePointer(); 00046 lastJulDay = 0; 00047 00048 // No scene node needed to render the light. 00049 ogreSkyLight = ogreSceneManager->createLight(skyLightName +"/Light"); 00050 ogreSkyLight->setType(Ogre::Light::LT_DIRECTIONAL); 00051 ogreSkyLight->setVisible(false); 00052 } 00053 00054 SSkyLight::SSkyLight() : SData("") 00055 { 00056 // Forbiden (private) 00057 } 00058 00059 SSkyLight::~SSkyLight() 00060 { 00061 if(ogreSkyLight) 00062 { 00063 ogreSceneManager->destroyLight(ogreSkyLight); 00064 ogreSkyLight = 0; 00065 } 00066 00067 ogreSceneManager = 0; 00068 parentEnvironment = 0; 00069 } 00070 00071 SEnvironment* SSkyLight::GetEnvironment() 00072 { 00073 return parentEnvironment; 00074 } 00075 00076 void SSkyLight::Update() 00077 { 00078 // Update only when necessary 00079 double julDay = parentEnvironment->GetUniversalClock()->GetJulianDay(); 00080 if((lastJulDay == 0)||(lastJulDay != julDay)) 00081 { 00082 SetLightDirection(ComputeDirectionImpl(julDay)); 00083 lastJulDay = julDay; 00084 } 00085 } 00086 00087 const Ogre::Vector3 SSkyLight::GetLightDirection() const 00088 { 00089 return ogreSkyLight->getDirection(); 00090 } 00091 00092 void SSkyLight::SetLightDirection(const Ogre::Vector3& direction) 00093 { 00094 ogreSkyLight->setDirection(direction); 00095 } 00096 00097 const Ogre::ColourValue SSkyLight::GetLightColour() const 00098 { 00099 return Ogre::ColourValue::Black; 00100 } 00101 00102 void SSkyLight::SetLightColour(const Ogre::ColourValue& newColour) 00103 { 00104 // TODO 00105 } 00106 00107 const Ogre::Vector3 SSkyLight::MakeDirection(Ogre::Degree azimuth, Ogre::Degree altitude) 00108 { 00109 Ogre::Vector3 res; 00110 res.z = Ogre::Math::Cos(azimuth) * Ogre::Math::Cos(altitude); // North 00111 res.x = -Ogre::Math::Sin(azimuth) * Ogre::Math::Cos(altitude); // East 00112 res.y = -Ogre::Math::Sin(altitude); // Zenith 00113 return res; 00114 } 00115 00116 }
1.6.3