00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CaelumPrecompiled.h"
00022 #include "Sun.h"
00023 #include "InternalUtilities.h"
00024
00025 namespace Caelum
00026 {
00027 const Ogre::String SphereSun::SUN_MATERIAL_NAME = "CaelumSphereSun";
00028
00029 SphereSun::SphereSun
00030 (
00031 Ogre::SceneManager *sceneMgr,
00032 Ogre::SceneNode *caelumRootNode,
00033 const Ogre::String &meshName
00034 ):
00035 BaseSkyLight(sceneMgr, caelumRootNode)
00036 {
00037 Ogre::String uniqueSuffix = "/" + InternalUtilities::pointerToString (this);
00038 mSunMaterial.reset (InternalUtilities::checkLoadMaterialClone (SUN_MATERIAL_NAME, SUN_MATERIAL_NAME + uniqueSuffix));
00039
00040 mSunEntity.reset (sceneMgr->createEntity ("Caelum/SphereSun" + uniqueSuffix, meshName));
00041 mSunEntity->setMaterialName (mSunMaterial->getName ());
00042 mSunEntity->setCastShadows (false);
00043 mSunEntity->setRenderQueueGroup (CAELUM_RENDER_QUEUE_SUN);
00044
00045 mNode->attachObject (mSunEntity.get ());
00046 }
00047
00048 SphereSun::~SphereSun () { }
00049
00050 void SphereSun::setBodyColour (const Ogre::ColourValue &colour) {
00051 BaseSkyLight::setBodyColour(colour);
00052
00053
00054 mSunMaterial->setSelfIllumination (colour);
00055 }
00056
00057 void SphereSun::notifyCameraChanged (Ogre::Camera *cam) {
00058
00059 CameraBoundElement::notifyCameraChanged(cam);
00060
00061
00062 Ogre::Real sunDistance = mRadius - mRadius * Ogre::Math::Tan (Ogre::Degree (0.01));
00063 mNode->setPosition(-mDirection * sunDistance);
00064
00065
00066 float factor = 2 - mBodyColour.b / 3;
00067 float scale = factor * sunDistance * Ogre::Math::Tan (Ogre::Degree (0.01));
00068 mNode->setScale (Ogre::Vector3::UNIT_SCALE * scale);
00069 }
00070
00071 const Ogre::String SpriteSun::SUN_MATERIAL_NAME = "CaelumSpriteSun";
00072
00073 SpriteSun::SpriteSun (
00074 Ogre::SceneManager *sceneMgr,
00075 Ogre::SceneNode *caelumRootNode,
00076 const Ogre::String &sunTextureName,
00077 const Ogre::Degree& sunTextureAngularSize
00078 ):
00079 BaseSkyLight(sceneMgr, caelumRootNode),
00080 mSunTextureAngularSize(sunTextureAngularSize)
00081 {
00082 Ogre::String uniqueSuffix = "/" + InternalUtilities::pointerToString (this);
00083
00084 mSunMaterial.reset (InternalUtilities::checkLoadMaterialClone (SUN_MATERIAL_NAME, SUN_MATERIAL_NAME + uniqueSuffix));
00085 setSunTexture (sunTextureName);
00086
00087 mSunBillboardSet.reset (sceneMgr->createBillboardSet ("Caelum/SpriteSun" + uniqueSuffix, 2));
00088 mSunBillboardSet->setMaterialName (mSunMaterial->getName());
00089 mSunBillboardSet->setCastShadows (false);
00090 mSunBillboardSet->setRenderQueueGroup (CAELUM_RENDER_QUEUE_SUN);
00091 mSunBillboardSet->setDefaultDimensions (1.0f, 1.0f);
00092 mSunBillboardSet->createBillboard (Ogre::Vector3::ZERO);
00093
00094 mNode->attachObject (mSunBillboardSet.get ());
00095 }
00096
00097 SpriteSun::~SpriteSun () { }
00098
00099 void SpriteSun::setBodyColour (const Ogre::ColourValue &colour) {
00100 BaseSkyLight::setBodyColour (colour);
00101
00102
00103 mSunBillboardSet->getBillboard (0)->setColour (colour);
00104 }
00105
00106 void SpriteSun::setSunTexture (const Ogre::String &textureName) {
00107
00108 assert(mSunMaterial->getBestTechnique ());
00109 assert(mSunMaterial->getBestTechnique ()->getPass (0));
00110 assert(mSunMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0));
00111 mSunMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (textureName);
00112 }
00113
00114 void SpriteSun::setSunTextureAngularSize(const Ogre::Degree& sunTextureAngularSize){
00115 mSunTextureAngularSize = sunTextureAngularSize;
00116 }
00117
00118 void SpriteSun::notifyCameraChanged (Ogre::Camera *cam) {
00119
00120 BaseSkyLight::notifyCameraChanged(cam);
00121
00122
00123 Ogre::Real sunDistance = mRadius - mRadius * Ogre::Math::Tan(mSunTextureAngularSize);
00124 mNode->setPosition (-mDirection * sunDistance);
00125
00126
00127 float factor = 1.2f - mBodyColour.b * 0.2f;
00128 float scale = factor * sunDistance * Ogre::Math::Tan(mSunTextureAngularSize);
00129 mNode->setScale (Ogre::Vector3::UNIT_SCALE * scale);
00130 }
00131 }