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 "CaelumExceptions.h"
00023 #include "InternalUtilities.h"
00024 #include "Moon.h"
00025 #include <memory>
00026
00027 namespace Caelum
00028 {
00029 const Ogre::String Moon::MOON_MATERIAL_NAME = "Caelum/PhaseMoon";
00030 const Ogre::String Moon::MOON_BACKGROUND_MATERIAL_NAME = "Caelum/MoonBackground";
00031
00032 Moon::Moon (
00033 Ogre::SceneManager *sceneMgr,
00034 Ogre::SceneNode *caelumRootNode,
00035 const Ogre::String& moonTextureName,
00036 Ogre::Degree angularSize
00037 ):
00038 BaseSkyLight(sceneMgr, caelumRootNode),
00039 mAngularSize(angularSize)
00040 {
00041 Ogre::String uniqueSuffix = "/" + InternalUtilities::pointerToString(this);
00042
00043
00044 mMoonMaterial.reset(InternalUtilities::checkLoadMaterialClone(MOON_MATERIAL_NAME, MOON_MATERIAL_NAME + uniqueSuffix));
00045 mBackMaterial.reset(InternalUtilities::checkLoadMaterialClone(MOON_BACKGROUND_MATERIAL_NAME, MOON_BACKGROUND_MATERIAL_NAME + uniqueSuffix));
00046
00047 assert (!mMoonMaterial.isNull ());
00048 assert (mMoonMaterial->getTechnique (0));
00049 assert (mMoonMaterial->getTechnique (0)->getPass (0));
00050 assert (mMoonMaterial->getTechnique (0)->getPass( 0)->hasFragmentProgram ());
00051 mParams.setup(mMoonMaterial->getBestTechnique ()->getPass (0)->getFragmentProgramParameters ());
00052
00053 setMoonTexture(moonTextureName);
00054
00055 mMoonBB.reset(sceneMgr->createBillboardSet("Caelum/Moon/MoonBB" + uniqueSuffix, 1));
00056 mMoonBB->setMaterialName (mMoonMaterial->getName());
00057 mMoonBB->setCastShadows (false);
00058 mMoonBB->setRenderQueueGroup (CAELUM_RENDER_QUEUE_MOON);
00059 mMoonBB->setDefaultDimensions (1.0f, 1.0f);
00060 mMoonBB->createBillboard (Ogre::Vector3::ZERO);
00061
00062 mBackBB.reset(sceneMgr->createBillboardSet("Caelum/Moon/BackBB" + uniqueSuffix, 1));
00063 mBackBB->setMaterialName (mBackMaterial->getName());
00064 mBackBB->setCastShadows (false);
00065 mBackBB->setRenderQueueGroup (CAELUM_RENDER_QUEUE_MOON_BACKGROUND);
00066 mBackBB->setDefaultDimensions (1.0f, 1.0f);
00067 mBackBB->createBillboard (Ogre::Vector3::ZERO);
00068
00069 mNode->attachObject (mMoonBB.get());
00070 mNode->attachObject (mBackBB.get());
00071 }
00072
00073 Moon::~Moon () {
00074 }
00075
00076 void Moon::setBodyColour (const Ogre::ColourValue &colour) {
00077 BaseSkyLight::setBodyColour(colour);
00078
00079
00080 mMoonBB->getBillboard(0)->setColour(colour);
00081 }
00082
00083 void Moon::setMoonTexture (const Ogre::String &textureName)
00084 {
00085
00086 assert(mMoonMaterial->getBestTechnique ());
00087 assert(mMoonMaterial->getBestTechnique ()->getPass (0));
00088 assert(mMoonMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0));
00089 mMoonMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (textureName);
00090 mBackMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (textureName);
00091 }
00092
00093 void Moon::setMoonTextureAngularSize(const Ogre::Degree& moonTextureAngularSize){
00094 mAngularSize = moonTextureAngularSize;
00095 }
00096
00097 void Moon::notifyCameraChanged (Ogre::Camera *cam) {
00098
00099 BaseSkyLight::notifyCameraChanged(cam);
00100
00101
00102 Ogre::Real moonDistance = mRadius - mRadius * Ogre::Math::Tan(mAngularSize);
00103 mNode->setPosition(-mDirection * moonDistance);
00104
00105
00106 float factor = 1.2f - mBodyColour.b * 0.2f;
00107 float scale = factor * moonDistance * Ogre::Math::Tan(mAngularSize);
00108 mNode->setScale (Ogre::Vector3::UNIT_SCALE * scale);
00109 }
00110
00111 void Moon::Params::setup(Ogre::GpuProgramParametersSharedPtr fpParams)
00112 {
00113 this->fpParams = fpParams;
00114 this->phase.bind(fpParams, "phase");
00115 }
00116
00117 void Moon::setPhase (Ogre::Real phase) {
00118 mParams.phase.set(mParams.fpParams, phase);
00119 }
00120
00121 void Moon::setQueryFlags (uint flags) {
00122 mMoonBB->setQueryFlags (flags);
00123 mBackBB->setQueryFlags (flags);
00124 }
00125
00126 uint Moon::getQueryFlags () const {
00127 assert (mMoonBB->getQueryFlags () == mBackBB->getQueryFlags ());
00128 return mMoonBB->getQueryFlags ();
00129 }
00130
00131 void Moon::setVisibilityFlags (uint flags) {
00132 mMoonBB->setVisibilityFlags (flags);
00133 mBackBB->setVisibilityFlags (flags);
00134 }
00135
00136 uint Moon::getVisibilityFlags () const {
00137 assert (mMoonBB->getVisibilityFlags () == mBackBB->getVisibilityFlags ());
00138 return mMoonBB->getVisibilityFlags ();
00139 }
00140 }