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 const Ogre::String ImageStarfield::DEFAULT_TEXTURE_NAME = "Starfield.jpg"; 00032 00033 ImageStarfield::ImageStarfield 00034 ( 00035 Ogre::SceneManager *sceneMgr, 00036 Ogre::SceneNode *caelumRootNode, 00037 const Ogre::String &textureName/* = DEFAULT_TEXUTRE_NAME*/ 00038 ): 00039 mNode(0), 00040 mEntity(0) 00041 { 00042 mInclination = Ogre::Degree (0); 00043 00044 String uniqueId = Ogre::StringConverter::toString((size_t)this); 00045 00046 mStarfieldMaterial = Ogre::MaterialManager::getSingleton().getByName(STARFIELD_MATERIAL_NAME); 00047 mStarfieldMaterial = mStarfieldMaterial->clone(STARFIELD_MATERIAL_NAME + uniqueId); 00048 mStarfieldMaterial->load(); 00049 setTexture (textureName); 00050 00051 sceneMgr->getRenderQueue()->getQueueGroup(CAELUM_RENDER_QUEUE_STARFIELD)->setShadowsEnabled(false); 00052 00053 GeometryFactory::generateSphericDome (STARFIELD_DOME_NAME, 32, GeometryFactory::DT_STARFIELD); 00054 00055 mEntity = sceneMgr->createEntity ("Caelum/StarfieldDome/" + uniqueId, STARFIELD_DOME_NAME); 00056 mEntity->setMaterialName (mStarfieldMaterial->getName()); 00057 mEntity->setRenderQueueGroup (CAELUM_RENDER_QUEUE_STARFIELD); 00058 mEntity->setCastShadows (false); 00059 00060 mNode = caelumRootNode->createChildSceneNode (); 00061 mNode->attachObject (mEntity); 00062 } 00063 00064 ImageStarfield::~ImageStarfield () 00065 { 00066 if (mEntity) { 00067 mEntity->_getManager ()->destroyMovableObject (mEntity); 00068 mEntity = 0; 00069 } 00070 00071 if (mNode) { 00072 mNode->getCreator ()->destroySceneNode (mNode->getName ()); 00073 mNode = 0; 00074 } 00075 00076 if (!mStarfieldMaterial.isNull ()) { 00077 Ogre::MaterialManager::getSingletonPtr ()->remove (mStarfieldMaterial->getHandle()); 00078 mStarfieldMaterial.setNull (); 00079 } 00080 } 00081 00082 void ImageStarfield::notifyCameraChanged (Ogre::Camera *cam) { 00083 CameraBoundElement::notifyCameraChanged (cam); 00084 } 00085 00086 void ImageStarfield::setFarRadius (Ogre::Real radius) { 00087 CameraBoundElement::setFarRadius(radius); 00088 mNode->setScale (Ogre::Vector3::UNIT_SCALE * radius); 00089 } 00090 00091 void ImageStarfield::setInclination (Ogre::Degree inc) { 00092 mInclination = inc; 00093 } 00094 00095 void ImageStarfield::update (const float time) { 00096 Ogre::Quaternion orientation = Ogre::Quaternion::IDENTITY; 00097 orientation = orientation * Ogre::Quaternion (Ogre::Radian (mInclination + Ogre::Degree (90)), Ogre::Vector3::UNIT_X); 00098 orientation = orientation * Ogre::Quaternion (Ogre::Radian (-time * 2 * Ogre::Math::PI), Ogre::Vector3::UNIT_Y); 00099 00100 mNode->setOrientation (orientation); 00101 } 00102 00103 void ImageStarfield::setTexture (const Ogre::String &mapName) { 00104 // Update the starfield material 00105 mStarfieldMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (mapName); 00106 } 00107 }