1 /*
2 This file is part of Caelum.
3 See http://www.ogre3d.org/wiki/index.php/Caelum
4 
5 Copyright (c) 2006-2008 Caelum team. See Contributors.txt for details.
6 
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.
11 
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.
16 
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/>.
19 */
20 
21 #include "CaelumPrecompiled.h"
22 #include "ImageStarfield.h"
23 #include "InternalUtilities.h"
24 
25 namespace Caelum
26 {
27     const Ogre::String ImageStarfield::STARFIELD_DOME_NAME = "CaelumStarfieldDome";
28     const Ogre::String ImageStarfield::STARFIELD_MATERIAL_NAME = "CaelumStarfieldMaterial";
29     const Ogre::String ImageStarfield::DEFAULT_TEXTURE_NAME = "Starfield.jpg";
30 
ImageStarfield(Ogre::SceneManager * sceneMgr,Ogre::SceneNode * caelumRootNode,const Ogre::String & textureName)31     ImageStarfield::ImageStarfield
32     (
33         Ogre::SceneManager *sceneMgr,
34         Ogre::SceneNode *caelumRootNode,
35         const Ogre::String &textureName/* = DEFAULT_TEXUTRE_NAME*/
36     )
37     {
38         mInclination = Ogre::Degree (0);
39 
40         String uniqueSuffix = "/" + InternalUtilities::pointerToString (this);
41 
42         mStarfieldMaterial.reset (InternalUtilities::checkLoadMaterialClone (STARFIELD_MATERIAL_NAME, STARFIELD_MATERIAL_NAME + uniqueSuffix));
43         setTexture (textureName);
44 
45         sceneMgr->getRenderQueue ()->getQueueGroup (CAELUM_RENDER_QUEUE_STARFIELD)->setShadowsEnabled (false);
46 
47         InternalUtilities::generateSphericDome (STARFIELD_DOME_NAME, 32, InternalUtilities::DT_IMAGE_STARFIELD);
48 
49         mEntity.reset(sceneMgr->createEntity ("Caelum/StarfieldDome" + uniqueSuffix, STARFIELD_DOME_NAME));
50         mEntity->setMaterialName (mStarfieldMaterial->getName());
51         mEntity->setRenderQueueGroup (CAELUM_RENDER_QUEUE_STARFIELD);
52         mEntity->setCastShadows (false);
53 
54         mNode.reset (caelumRootNode->createChildSceneNode ());
55         mNode->attachObject (mEntity.get ());
56     }
57 
~ImageStarfield()58     ImageStarfield::~ImageStarfield ()
59     {
60     }
61 
notifyCameraChanged(Ogre::Camera * cam)62     void ImageStarfield::notifyCameraChanged (Ogre::Camera *cam) {
63         CameraBoundElement::notifyCameraChanged (cam);
64     }
65 
setFarRadius(Ogre::Real radius)66     void ImageStarfield::setFarRadius (Ogre::Real radius) {
67         CameraBoundElement::setFarRadius(radius);
68         mNode->setScale (Ogre::Vector3::UNIT_SCALE * radius);
69     }
70 
setInclination(Ogre::Degree inc)71     void ImageStarfield::setInclination (Ogre::Degree inc) {
72         mInclination = inc;
73     }
74 
update(const float time)75     void ImageStarfield::update (const float time) {
76         Ogre::Quaternion orientation = Ogre::Quaternion::IDENTITY;
77         orientation = orientation * Ogre::Quaternion (Ogre::Radian (mInclination + Ogre::Degree (90)), Ogre::Vector3::UNIT_X);
78         orientation = orientation * Ogre::Quaternion (Ogre::Radian (-time * 2 * Ogre::Math::PI), Ogre::Vector3::UNIT_Y);
79 
80         mNode->setOrientation (orientation);
81     }
82 
setTexture(const Ogre::String & mapName)83     void ImageStarfield::setTexture (const Ogre::String &mapName) {
84         // Update the starfield material
85         mStarfieldMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (mapName);
86     }
87 }
88