Caelum
ImageStarfield.cpp
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 
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 
59  {
60  }
61 
62  void ImageStarfield::notifyCameraChanged (Ogre::Camera *cam) {
64  }
65 
66  void ImageStarfield::setFarRadius (Ogre::Real radius) {
68  mNode->setScale (Ogre::Vector3::UNIT_SCALE * radius);
69  }
70 
71  void ImageStarfield::setInclination (Ogre::Degree inc) {
72  mInclination = inc;
73  }
74 
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 
83  void ImageStarfield::setTexture (const Ogre::String &mapName) {
84  // Update the starfield material
85  mStarfieldMaterial->getBestTechnique ()->getPass (0)->getTextureUnitState (0)->setTextureName (mapName);
86  }
87 }
PrivateSceneNodePtr mNode
Reference to the dome node.
virtual void notifyCameraChanged(Ogre::Camera *cam)=0
Notify new camera conditions.
void setTexture(const Ogre::String &mapName)
Updates the starfield material.
ImageStarfield(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *caelumRootNode, const Ogre::String &textureName=DEFAULT_TEXTURE_NAME)
Constructor.
static const Ogre::String pointerToString(void *pointer)
Quickly format a pointer as a string; in hex.
static Ogre::MaterialPtr checkLoadMaterialClone(const Ogre::String &originalName, const Ogre::String &cloneName)
Creates a private clone of a material from a script.
static void generateSphericDome(const Ogre::String &name, int segments, DomeType domeType)
Creates a longitude-latitude sky dome.
void setInclination(Ogre::Degree inc)
Sets the starfield inclination.
virtual void setFarRadius(Ogre::Real radius)
Abstract method to set the radius for this elements Derived classes should override this and resize t...
static const Ogre::String STARFIELD_MATERIAL_NAME
Name of the starfield material.
virtual void notifyCameraChanged(Ogre::Camera *cam)
Handle camera change.
static const Ogre::String STARFIELD_DOME_NAME
Name of the spheric dome resource.
virtual ~ImageStarfield()
Destructor.
virtual void setFarRadius(Ogre::Real radius)
Handle far radius.
Ogre::Degree mInclination
Inclination of the starfield.
void update(const float time)
Updates the starfield position/orientation.
PrivateMaterialPtr mStarfieldMaterial
Reference to the (cloned) starfield material.
Caelum namespace.
Definition: Astronomy.cpp:24