AmbientLight.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _AMBIENTLIGHT_HH_
18 #define _AMBIENTLIGHT_HH_
19 
20 #include <OgreSimpleRenderable.h>
21 
23 #include "gazebo/util/system.hh"
24 
25 namespace gazebo
26 {
27  namespace rendering
28  {
29  // Renderable for rendering Ambient component and also to
30  // establish the depths
31  // Just instantiation is sufficient
32  // Note that instantiation is necessary to at least establish the depths
33  // even if the current ambient colour is 0
34  // its ambient colour is same as the scene's ambient colour
35  // XXX Could make this a singleton/make it private to the
36  // DeferredShadingSystem e.g.
37  template<class techniquePolicy>
39  : public Ogre::SimpleRenderable, public techniquePolicy
40  {
42  public: AmbientLight()
43  {
44  this->setRenderQueueGroup(Ogre::RENDER_QUEUE_2);
45 
46  this->mRenderOp.vertexData = new Ogre::VertexData();
47  this->mRenderOp.indexData = 0;
48 
49  GeomUtils::CreateQuad(mRenderOp.vertexData);
50 
51  this->mRenderOp.operationType =
52  Ogre::RenderOperation::OT_TRIANGLE_STRIP;
53  this->mRenderOp.useIndexes = false;
54 
55  // Set bounding
56  this->setBoundingBox(Ogre::AxisAlignedBox(-10000, -10000, -10000,
57  10000, 10000, 10000));
58  this->radius = 15000;
59 
60  this->matPtr = Ogre::MaterialManager::getSingleton().getByName(
61  this->GetMaterialPrefix() + "/AmbientLight");
62 
63  if (this->matPtr.isNull())
64  gzthrow("Is Null");
65 
66  this->matPtr->load();
67  }
68 
70  public: ~AmbientLight()
71  {
72  // need to release IndexData and vertexData created for renderable
73  delete this->mRenderOp.indexData;
74  delete this->mRenderOp.vertexData;
75  }
76 
78  public: virtual Ogre::Real getBoundingRadius(void) const
79  {
80  return this->radius;
81  }
82 
84  public: virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera*) const
85  {
86  return 0.0;
87  }
88 
90  public: virtual const Ogre::MaterialPtr &getMaterial(void) const
91  {
92  return this->matPtr;
93  }
94 
95  public: virtual void getWorldTransforms(Ogre::Matrix4 *_xform) const
96  {
97  *_xform = Ogre::Matrix4::IDENTITY;
98  }
99 
100  public: void UpdateFromCamera(Ogre::Camera *_camera)
101  {
102  Ogre::Technique* tech = this->getMaterial()->getBestTechnique();
103  Ogre::Vector3 farCorner = _camera->getViewMatrix(true) *
104  _camera->getWorldSpaceCorners()[4];
105 
106  for (uint16_t i = 0; i < tech->getNumPasses(); ++i)
107  {
108  Ogre::Pass *pass = tech->getPass(i);
109 
110  // get the vertex shader parameters
111  Ogre::GpuProgramParametersSharedPtr params =
112  pass->getVertexProgramParameters();
113 
114  // set the camera's far-top-right corner
115  if (params->_findNamedConstantDefinition("farCorner"))
116  params->setNamedConstant("farCorner", farCorner);
117 
118  params = pass->getFragmentProgramParameters();
119  if (params->_findNamedConstantDefinition("farCorner"))
120  params->setNamedConstant("farCorner", farCorner);
121  }
122  }
123 
124  protected: Ogre::Real radius;
125  protected: Ogre::MaterialPtr matPtr;
126  };
127  }
128 }
129 #endif
virtual const Ogre::MaterialPtr & getMaterial(void) const
Definition: AmbientLight.hh:90
#define gzthrow(msg)
This macro logs an error to the throw stream and throws an exception that contains the file name and ...
Definition: Exception.hh:39
~AmbientLight()
Destructor.
Definition: AmbientLight.hh:70
Ogre::Real radius
Definition: AmbientLight.hh:124
Ogre::MaterialPtr matPtr
Definition: AmbientLight.hh:125
AmbientLight()
Constructor.
Definition: AmbientLight.hh:42
virtual void getWorldTransforms(Ogre::Matrix4 *_xform) const
Definition: AmbientLight.hh:95
virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera *) const
Definition: AmbientLight.hh:84
Definition: AmbientLight.hh:38
static void CreateQuad(Ogre::VertexData *&_vertexData)
Fill up a fresh copy of VertexData with a normalized quad.
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
virtual Ogre::Real getBoundingRadius(void) const
Definition: AmbientLight.hh:78
void UpdateFromCamera(Ogre::Camera *_camera)
Definition: AmbientLight.hh:100