2
This file is part of Caelum.
3
See http://www.ogre3d.org/wiki/index.php/Caelum
5
Copyright (c) 2008 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"
22
#include "CaelumExceptions.h"
27
const Ogre::String Moon::MOON_MATERIAL_NAME = "Caelum/PhaseMoon";
29
const Ogre::String Moon::MOON_BACKROUND_MATERIAL_NAME = "Caelum/MoonBackground";
32
Ogre::SceneManager *sceneMgr,
33
Ogre::SceneNode *caelumRootNode,
34
const Ogre::String& moonTextureName,
35
Ogre::Degree angularSize
37
BaseSkyLight(sceneMgr, caelumRootNode),
38
mAngularSize(angularSize)
40
// Clone moon face material.
41
mMoonMaterial = Ogre::MaterialManager::getSingletonPtr()->getByName(MOON_MATERIAL_NAME);
42
if (mMoonMaterial.isNull()) {
43
CAELUM_THROW_UNSUPPORED_EXCEPTION("Can't find moon material", "Moon");
45
mMoonMaterial = mMoonMaterial->clone(mMoonMaterial->getName() + Ogre::StringConverter::toString((size_t)this));
46
mMoonMaterial->load();
47
if (mMoonMaterial->getBestTechnique() == NULL) {
48
CAELUM_THROW_UNSUPPORED_EXCEPTION("Moon material not supported", "Moon");
51
// Clone moon back material.
52
mBackMaterial = Ogre::MaterialManager::getSingletonPtr()->getByName(MOON_BACKROUND_MATERIAL_NAME);
53
if (mBackMaterial.isNull()) {
54
CAELUM_THROW_UNSUPPORED_EXCEPTION("Can't find moon background material", "Moon");
56
mBackMaterial = mBackMaterial->clone(mBackMaterial->getName() + Ogre::StringConverter::toString((size_t)this));
57
mBackMaterial->load();
58
if (mBackMaterial->getBestTechnique() == NULL) {
59
CAELUM_THROW_UNSUPPORED_EXCEPTION("Moon background material not supported", "Moon");
62
getFpParams()->setIgnoreMissingParams(true);
63
setMoonTexture(moonTextureName);
65
mMoonBB = sceneMgr->createBillboardSet(
66
"Caelum/Moon/MoonBB/" + Ogre::StringConverter::toString((size_t)this), 1);
67
mMoonBB->setMaterialName (mMoonMaterial->getName());
68
mMoonBB->setCastShadows (false);
69
mMoonBB->setRenderQueueGroup (CAELUM_RENDER_QUEUE_MOON);
70
mMoonBB->setDefaultDimensions (1.0f, 1.0f);
71
mMoonBB->createBillboard (Ogre::Vector3::ZERO);
73
mBackBB = sceneMgr->createBillboardSet(
74
"Caelum/Moon/BackBB/" + Ogre::StringConverter::toString((size_t)this), 1);
75
mBackBB->setMaterialName (mBackMaterial->getName());
76
mBackBB->setCastShadows (false);
77
mBackBB->setRenderQueueGroup (CAELUM_RENDER_QUEUE_MOON_BACKGROUND);
78
mBackBB->setDefaultDimensions (1.0f, 1.0f);
79
mBackBB->createBillboard (Ogre::Vector3::ZERO);
81
mNode->attachObject (mMoonBB);
82
mNode->attachObject (mBackBB);
87
mMoonBB->_getManager ()->destroyBillboardSet (mMoonBB);
91
mBackBB->_getManager ()->destroyBillboardSet (mBackBB);
94
Ogre::MaterialManager::getSingletonPtr()->remove(mMoonMaterial->getHandle());
95
Ogre::MaterialManager::getSingletonPtr()->remove(mBackMaterial->getHandle());
98
void Moon::setBodyColour (const Ogre::ColourValue &colour) {
99
BaseSkyLight::setBodyColour(colour);
101
// Set moon material colour.
102
mMoonBB->getBillboard(0)->setColour(colour);
105
void Moon::setMoonTexture (const Ogre::String &textureName)
107
// Update the moon material
108
assert(mMoonMaterial->getBestTechnique ());
109
assert(mMoonMaterial->getBestTechnique ()->getPass (0));
110
assert(mMoonMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0));
111
mMoonMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (textureName);
112
mBackMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (textureName);
115
void Moon::setMoonTextureAngularSize(const Ogre::Degree& moonTextureAngularSize){
116
mAngularSize = moonTextureAngularSize;
119
void Moon::notifyCameraChanged (Ogre::Camera *cam) {
120
// This calls setFarRadius
121
BaseSkyLight::notifyCameraChanged(cam);
123
// Set moon position.
124
Ogre::Real moonDistance = mRadius - mRadius * Ogre::Math::Tan(mAngularSize);
125
mNode->setPosition(-mDirection * moonDistance);
127
// Set moon scaling in [1.0 ~ 1.2] range
128
float factor = 1.2f - mBodyColour.b * 0.2f;
129
float scale = factor * moonDistance * Ogre::Math::Tan(mAngularSize);
130
mNode->setScale (Ogre::Vector3::UNIT_SCALE * scale);
133
Ogre::GpuProgramParametersSharedPtr Moon::getFpParams () {
134
assert (!mMoonMaterial.isNull ());
135
assert (mMoonMaterial->getBestTechnique ());
136
assert (mMoonMaterial->getBestTechnique ()->getPass (0));
137
assert (mMoonMaterial->getBestTechnique ()->getPass( 0)->hasFragmentProgram ());
138
return mMoonMaterial->getBestTechnique ()->getPass (0)->getFragmentProgramParameters ();
141
void Moon::setPhase (Ogre::Real phase) {
142
getFpParams ()->setNamedConstant ("phase", phase);