00001 /* 00002 This file is part of Caelum. 00003 See http://www.ogre3d.org/wiki/index.php/Caelum 00004 00005 Copyright (c) 2006-2008 Caelum team. See Contributors.txt for details. 00006 00007 Caelum is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published 00009 by the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 Caelum is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with Caelum. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "CaelumPrecompiled.h" 00022 #include "ImageStarfield.h" 00023 #include "GeometryFactory.h" 00024 00025 namespace caelum { 00026 00027 const Ogre::String ImageStarfield::STARFIELD_DOME_NAME = "CaelumStarfieldDome"; 00028 00029 const Ogre::String ImageStarfield::STARFIELD_MATERIAL_NAME = "CaelumStarfieldMaterial"; 00030 00031 ImageStarfield::ImageStarfield (Ogre::SceneManager *sceneMgr, Ogre::SceneNode *caelumRootNode, const Ogre::String &textureName) { 00032 mInclination = Ogre::Degree (0); 00033 00034 mStarfieldMaterial = Ogre::MaterialManager::getSingleton().getByName(STARFIELD_MATERIAL_NAME); 00035 mStarfieldMaterial = mStarfieldMaterial->clone(STARFIELD_MATERIAL_NAME + Ogre::StringConverter::toString((size_t)this)); 00036 mStarfieldMaterial->load(); 00037 setTexture (textureName); 00038 00039 sceneMgr->getRenderQueue()->getQueueGroup(CAELUM_RENDER_QUEUE_STARFIELD)->setShadowsEnabled(false); 00040 00041 GeometryFactory::generateSphericDome (STARFIELD_DOME_NAME, 32, GeometryFactory::DT_STARFIELD); 00042 Ogre::Entity *ent = sceneMgr->createEntity ("StarfieldDome", STARFIELD_DOME_NAME); 00043 ent->setMaterialName (mStarfieldMaterial->getName()); 00044 ent->setRenderQueueGroup (CAELUM_RENDER_QUEUE_STARFIELD); 00045 ent->setCastShadows (false); 00046 00047 mNode = caelumRootNode->createChildSceneNode (); 00048 mNode->attachObject (ent); 00049 } 00050 00051 ImageStarfield::~ImageStarfield () { 00052 if (mNode) { 00053 // Detach and destroy attached entity. 00054 Ogre::Entity *ent = static_cast<Ogre::Entity *>(mNode->detachObject ("StarfieldDome")); 00055 ent->_getManager ()->destroyEntity (ent); 00056 00057 // Destroy the node 00058 static_cast<Ogre::SceneNode *>(mNode->getParent ())->removeAndDestroyChild (mNode->getName ()); 00059 mNode = 0; 00060 00061 Ogre::MaterialManager::getSingletonPtr()->remove(mStarfieldMaterial->getHandle()); 00062 } 00063 } 00064 00065 void ImageStarfield::notifyCameraChanged (Ogre::Camera *cam) { 00066 CameraBoundElement::notifyCameraChanged (cam); 00067 } 00068 00069 void ImageStarfield::setFarRadius (Ogre::Real radius) { 00070 CameraBoundElement::setFarRadius(radius); 00071 mNode->setScale (Ogre::Vector3::UNIT_SCALE * radius); 00072 } 00073 00074 void ImageStarfield::setInclination (Ogre::Degree inc) { 00075 mInclination = inc; 00076 } 00077 00078 void ImageStarfield::update (const float time) { 00079 Ogre::Quaternion orientation = Ogre::Quaternion::IDENTITY; 00080 orientation = orientation * Ogre::Quaternion (Ogre::Radian (mInclination + Ogre::Degree (90)), Ogre::Vector3::UNIT_X); 00081 orientation = orientation * Ogre::Quaternion (Ogre::Radian (-time * 2 * Ogre::Math::PI), Ogre::Vector3::UNIT_Y); 00082 00083 mNode->setOrientation (orientation); 00084 } 00085 00086 void ImageStarfield::setTexture (const Ogre::String &mapName) { 00087 // Update the starfield material 00088 mStarfieldMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (mapName); 00089 } 00090 00091 } // namespace caelum