TrueReality  v0.1.1912
SkyBoxNode.cpp
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 
23 
24 #include <osg/Depth>
25 #include <osgDB/ReadFile>
26 #include <osgUtil/CullVisitor>
27 
28 namespace trCore::SceneObjects
29 {
32  {
33  setCullingActive(false);
34  getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
35  getStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
36  getStateSet()->setRenderBinDetails(INT_MIN, "RenderBin");
37  }
38 
40  bool SkyBoxNode::computeLocalToWorldMatrix(osg::Matrix & matrix, osg::NodeVisitor * nv) const
41  {
42  if (nv && nv->getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
43  {
44  osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
45  matrix.preMult(osg::Matrix::translate(cv->getEyeLocal()));
46  return true;
47  }
48  else
49  {
50  return BaseClass::computeLocalToWorldMatrix(matrix, nv);
51  }
52  }
53 
55  bool SkyBoxNode::computeWorldToLocalMatrix(osg::Matrix & matrix, osg::NodeVisitor * nv) const
56  {
57  if (nv && nv->getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
58  {
59  osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
60  matrix.postMult(osg::Matrix::translate(cv->getEyeLocal()));
61  return true;
62  }
63  else
64  {
65  return BaseClass::computeWorldToLocalMatrix(matrix, nv);
66  }
67  }
68 
70  bool SkyBoxNode::LoadFile(std::string fileName)
71  {
72  mNode = osgDB::readNodeFile(fileName);
73  if (mNode.Valid())
74  {
75  addChild(mNode);
76  return true;
77  }
78  else
79  {
80  return false;
81  }
82  }
83 
86  {
87  }
88 }
Namespace that contains controls for sample scene objects.
Matrixf Matrix
Definition: Matrix.h:33
bool LoadFile(std::string fileName)
Loads a geometry file.
Definition: SkyBoxNode.cpp:70
virtual bool computeWorldToLocalMatrix(osg::Matrix &matrix, osg::NodeVisitor *nv) const override
Calculates the world to local matrix.
Definition: SkyBoxNode.cpp:55
virtual bool computeLocalToWorldMatrix(osg::Matrix &matrix, osg::NodeVisitor *nv) const override
Calculates the local to world matrix.
Definition: SkyBoxNode.cpp:40
bool Valid() const
Returns True if the smart pointer has a valid internal pointer set.
Definition: SmrtPtr.h:103
SkyBoxNode()
Adds an easy and swappable access to the base class.
Definition: SkyBoxNode.cpp:31
trBase::SmrtPtr< osg::Node > mNode
Definition: SkyBoxNode.h:94