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 "ImageStarfield.h"
00023 #include "InternalUtilities.h"
00024
00025 namespace Caelum
00026 {
00027 const Ogre::String ImageStarfield::STARFIELD_DOME_NAME = "CaelumStarfieldDome";
00028 const Ogre::String ImageStarfield::STARFIELD_MATERIAL_NAME = "CaelumStarfieldMaterial";
00029 const Ogre::String ImageStarfield::DEFAULT_TEXTURE_NAME = "Starfield.jpg";
00030
00031 ImageStarfield::ImageStarfield
00032 (
00033 Ogre::SceneManager *sceneMgr,
00034 Ogre::SceneNode *caelumRootNode,
00035 const Ogre::String &textureName
00036 )
00037 {
00038 mInclination = Ogre::Degree (0);
00039
00040 String uniqueSuffix = "/" + InternalUtilities::pointerToString (this);
00041
00042 mStarfieldMaterial.reset (InternalUtilities::checkLoadMaterialClone (STARFIELD_MATERIAL_NAME, STARFIELD_MATERIAL_NAME + uniqueSuffix));
00043 setTexture (textureName);
00044
00045 sceneMgr->getRenderQueue ()->getQueueGroup (CAELUM_RENDER_QUEUE_STARFIELD)->setShadowsEnabled (false);
00046
00047 InternalUtilities::generateSphericDome (STARFIELD_DOME_NAME, 32, InternalUtilities::DT_IMAGE_STARFIELD);
00048
00049 mEntity.reset(sceneMgr->createEntity ("Caelum/StarfieldDome" + uniqueSuffix, STARFIELD_DOME_NAME));
00050 mEntity->setMaterialName (mStarfieldMaterial->getName());
00051 mEntity->setRenderQueueGroup (CAELUM_RENDER_QUEUE_STARFIELD);
00052 mEntity->setCastShadows (false);
00053
00054 mNode.reset (caelumRootNode->createChildSceneNode ());
00055 mNode->attachObject (mEntity.get ());
00056 }
00057
00058 ImageStarfield::~ImageStarfield ()
00059 {
00060 }
00061
00062 void ImageStarfield::notifyCameraChanged (Ogre::Camera *cam) {
00063 CameraBoundElement::notifyCameraChanged (cam);
00064 }
00065
00066 void ImageStarfield::setFarRadius (Ogre::Real radius) {
00067 CameraBoundElement::setFarRadius(radius);
00068 mNode->setScale (Ogre::Vector3::UNIT_SCALE * radius);
00069 }
00070
00071 void ImageStarfield::setInclination (Ogre::Degree inc) {
00072 mInclination = inc;
00073 }
00074
00075 void ImageStarfield::update (const float time) {
00076 Ogre::Quaternion orientation = Ogre::Quaternion::IDENTITY;
00077 orientation = orientation * Ogre::Quaternion (Ogre::Radian (mInclination + Ogre::Degree (90)), Ogre::Vector3::UNIT_X);
00078 orientation = orientation * Ogre::Quaternion (Ogre::Radian (-time * 2 * Ogre::Math::PI), Ogre::Vector3::UNIT_Y);
00079
00080 mNode->setOrientation (orientation);
00081 }
00082
00083 void ImageStarfield::setTexture (const Ogre::String &mapName) {
00084
00085 mStarfieldMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (mapName);
00086 }
00087 }