2
This file is part of Caelum.
3
See http://www.ogre3d.org/wiki/index.php/Caelum
5
Copyright (c) 2006-2007 Caelum team. See Contributors.txt for details.
7
Caelum is free software: you can redistribute it and/or modify
8
it under the terms of the GNU Lesser General Public License as published
9
by the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
12
Caelum is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU Lesser General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public License
18
along with Caelum. If not, see <http://www.gnu.org/licenses/>.
21
#include "CaelumPrecompiled.h"
27
//========================================================================================================================
28
// Sphere Sun - deprecated, use Sprite Sun instead
29
//========================================================================================================================
31
const Ogre::String SphereSun::SUN_MATERIAL_NAME = "CaelumSphereSun";
33
SphereSun::SphereSun (Ogre::SceneManager *sceneMgr, Ogre::SceneNode *caelumRootNode, const Ogre::String &meshName) : BaseSkyLight(sceneMgr, caelumRootNode) {
34
mSunMaterial = Ogre::MaterialManager::getSingletonPtr()->getByName(SUN_MATERIAL_NAME);
35
mSunMaterial = mSunMaterial->clone(SUN_MATERIAL_NAME + Ogre::StringConverter::toString((size_t)this));
37
mSunEntity = sceneMgr->createEntity ("CaelumSun", meshName);
38
mSunEntity->setMaterialName (mSunMaterial->getName());
39
mSunEntity->setCastShadows (false);
40
mSunEntity->setRenderQueueGroup (CAELUM_RENDER_QUEUE_SUN);
41
mNode->attachObject (mSunEntity);
44
SphereSun::~SphereSun () {
46
mNode->detachObject (mSunEntity);
49
mSunEntity->_getManager ()->destroyEntity (mSunEntity);
52
Ogre::MaterialManager::getSingletonPtr()->remove(mSunMaterial->getHandle());
55
void SphereSun::setBodyColour (const Ogre::ColourValue &colour) {
56
BaseSkyLight::setBodyColour(colour);
58
// Set sun material colour.
59
mSunMaterial->setSelfIllumination (colour);
62
void SphereSun::notifyCameraChanged (Ogre::Camera *cam) {
63
// This calls setFarRadius
64
CameraBoundElement::notifyCameraChanged(cam);
67
Ogre::Real sunDistance = mRadius - mRadius * Ogre::Math::Tan (Ogre::Degree (0.01));
68
mNode->setPosition(-mDirection * sunDistance);
70
// Set sun scaling in [1.6(6) ~ 2.0] range.
71
float factor = 2 - mBodyColour.b / 3;
72
float scale = factor * sunDistance * Ogre::Math::Tan (Ogre::Degree (0.01));
73
mNode->setScale (Ogre::Vector3::UNIT_SCALE * scale);
76
//========================================================================================================================
78
//========================================================================================================================
80
const Ogre::String SpriteSun::SUN_MATERIAL_NAME = "CaelumSpriteSun";
82
SpriteSun::SpriteSun ( Ogre::SceneManager *sceneMgr,
83
Ogre::SceneNode *caelumRootNode,
84
const Ogre::String &sunTextureName,
85
const Ogre::Degree& sunTextureAngularSize)
86
: BaseSkyLight(sceneMgr, caelumRootNode)
87
, mSunTextureAngularSize(sunTextureAngularSize)
89
mSunMaterial = Ogre::MaterialManager::getSingletonPtr()->getByName(SUN_MATERIAL_NAME);
90
mSunMaterial = mSunMaterial->clone(SUN_MATERIAL_NAME + Ogre::StringConverter::toString((size_t)this));
92
assert(!mSunMaterial.isNull());
93
setSunTexture(sunTextureName);
95
mSunBillboardSet = sceneMgr->createBillboardSet("CaelumSpriteSun", 2);
96
mSunBillboardSet->setMaterialName (mSunMaterial->getName());
97
mSunBillboardSet->setCastShadows (false);
98
mSunBillboardSet->setRenderQueueGroup (CAELUM_RENDER_QUEUE_SUN);
99
mSunBillboardSet->setDefaultDimensions(1.0f, 1.0f);
100
mSunBillboardSet->createBillboard(Ogre::Vector3::ZERO);
102
mNode->attachObject (mSunBillboardSet);
105
SpriteSun::~SpriteSun () {
107
mNode->detachObject (mSunBillboardSet);
109
if (mSunBillboardSet) {
110
mSunBillboardSet->_getManager ()->destroyBillboardSet (mSunBillboardSet);
111
mSunBillboardSet = 0;
113
Ogre::MaterialManager::getSingletonPtr()->remove(mSunMaterial->getHandle());
116
void SpriteSun::setBodyColour (const Ogre::ColourValue &colour) {
117
BaseSkyLight::setBodyColour(colour);
119
// Set sun material colour.
120
mSunBillboardSet->getBillboard(0)->setColour(colour);
123
void SpriteSun::setSunTexture (const Ogre::String &textureName) {
124
// Update the sun material
125
assert(mSunMaterial->getBestTechnique ());
126
assert(mSunMaterial->getBestTechnique ()->getPass (0));
127
assert(mSunMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0));
128
mSunMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (textureName);
131
void SpriteSun::setSunTextureAngularSize(const Ogre::Degree& sunTextureAngularSize){
132
mSunTextureAngularSize = sunTextureAngularSize;
135
void SpriteSun::notifyCameraChanged (Ogre::Camera *cam) {
136
// This calls setFarRadius
137
BaseSkyLight::notifyCameraChanged(cam);
140
Ogre::Real sunDistance = mRadius - mRadius * Ogre::Math::Tan(mSunTextureAngularSize);
141
mNode->setPosition(-mDirection * sunDistance);
143
// Set sun scaling in [1.0 ~ 1.2] range
144
float factor = 1.2f - mBodyColour.b * 0.2f;
145
float scale = factor * sunDistance * Ogre::Math::Tan(mSunTextureAngularSize);
146
mNode->setScale (Ogre::Vector3::UNIT_SCALE * scale);
149
} // namespace caelum