8 #include "OsgMovableItem.h"
10 #include "OsgRigidBody.h"
14 #include "OsgUserData.h"
15 #include "OsgUserDataVisitor.h"
16 #include "OsgDragger.h"
17 #include "OsgSimulator.h"
50 {
Std_TraceMsg(0,
"Caught Error in desctructor of VsBox\r\n",
"", -1,
false,
true);}
53 void OsgLight::SetThisPointers()
55 OsgMovableItem::SetThisPointers();
57 m_lpThisLI =
dynamic_cast<Light *
>(
this);
59 THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined,
"m_lpThisLI, " + m_lpThisAB->Name());
62 osg::MatrixTransform *OsgLight::ParentOSG()
64 return GetOsgSimulator()->OSGRoot();
71 if(GetOsgSimulator() && GetOsgSimulator()->OSGRoot())
73 osg::StateSet *rootStateSet = GetOsgSimulator()->OSGRoot()->getOrCreateStateSet();
76 rootStateSet->setMode( GetGlLight(), osg::StateAttribute::ON );
78 rootStateSet->setMode( GetGlLight(), osg::StateAttribute::OFF );
82 void OsgLight::Position(CStdFPoint &oPoint,
bool bUseScaling,
bool bFireChangeEvent,
bool bUpdateMatrix)
84 Light::Position(oPoint, bUseScaling, bFireChangeEvent, bUpdateMatrix);
87 if(m_osgLight.valid())
90 m_osgLight->setPosition(position);
96 Light::Ambient(aryColor);
99 if(m_osgLight.valid())
102 m_osgLight->setAmbient(color);
108 Light::Diffuse(aryColor);
111 if(m_osgLight.valid())
114 m_osgLight->setDiffuse(color);
120 Light::Specular(aryColor);
123 if(m_osgLight.valid())
126 m_osgLight->setSpecular(specular);
130 void OsgLight::SetAttenuation()
132 if(m_osgLight.valid())
139 m_osgLight->setLinearAttenuation(fltAtten);
142 m_osgLight->setLinearAttenuation(0);
147 m_osgLight->setQuadraticAttenuation(fltAtten);
150 m_osgLight->setQuadraticAttenuation(0);
154 int OsgLight::GetGlLight()
179 void OsgLight::SetupLighting()
188 m_osgLight->setAmbient(ambient);
189 m_osgLight->setDiffuse(diffuse);
190 m_osgLight->setSpecular(specular);
191 m_osgLight->setPosition(position);
194 m_osgLightSource =
new osg::LightSource;
195 m_osgLightSource->setLight(m_osgLight.get());
196 GetOsgSimulator()->OSGRoot()->addChild(m_osgLightSource.get());
202 void OsgLight::SetupGraphics()
204 OsgMovableItem::SetupGraphics();
209 void OsgLight::CreateGraphicsGeometry()
214 void OsgLight::DeleteGraphics()
216 OsgMovableItem::DeleteGraphics();
218 if(m_osgLightSource.valid() && GetOsgSimulator() && GetOsgSimulator()->OSGRoot())
220 if(GetOsgSimulator()->OSGRoot()->containsNode(m_osgLightSource.get()))
221 GetOsgSimulator()->OSGRoot()->removeChild(m_osgLightSource.get());
223 osg::StateSet *rootStateSet = GetOsgSimulator()->OSGRoot()->getOrCreateStateSet();
224 rootStateSet->setMode( GetGlLight(), osg::StateAttribute::OFF );
227 m_osgLight.release();
228 m_osgLightSource.release();
231 void OsgLight::Create()
241 OsgMovableItem::Physics_ResetSimulation();
243 Light::ResetSimulation();
246 void OsgLight::Physics_Resize()
249 if(m_osgNode.valid())
251 osg::Geode *osgGroup = NULL;
255 osgGroup =
dynamic_cast<osg::Geode *
>(m_osgNode.get());
258 THROW_TEXT_ERROR(Osg_Err_lNodeNotGeode, Osg_Err_strNodeNotGeode, m_lpThisAB->Name());
260 if(osgGroup && osgGroup->containsDrawable(m_osgGeometry.get()))
261 osgGroup->removeDrawable(m_osgGeometry.get());
263 m_osgGeometry.release();
266 CreateGraphicsGeometry();
267 m_osgGeometry->setName(m_lpThisAB->Name() +
"_Geometry");
270 osgGroup->addDrawable(m_osgGeometry.get());
273 if(m_osgDragger.valid())
274 m_osgDragger->SetupMatrix();
277 if(m_osgNodeGroup.valid())
280 osgVisitor->traverse(*m_osgNodeGroup);
287 void OsgLight::Physics_SetColor()
289 SetColor(*m_lpThisMI->Ambient(), *m_lpThisMI->Diffuse(), *m_lpThisMI->Specular(), m_lpThisMI->Shininess());
virtual bool Enabled()
Tells whether this light is enabled.
osg::ref_ptr< osg::MatrixTransform > m_osgGeometryRotationMT
CStdColor m_vAmbient
The ambient color to apply to this part. It is specified as red, green, blue, and alpha...
Declares the vortex Light class.
float m_fltQuadraticAttenDistance
The quadratic attenuation distance.
float m_fltLinearAttenDistance
The linear attenuation distance.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual CStdColor * Ambient()
Gets the ambient color value.
virtual CStdColor * Specular()
Gets the specular color.
int m_iLightNum
Zero-based index of the light number. OSG only allows 8 lights.
virtual float Radius()
Gets the radius.
virtual int LongtitudeSegments()
Gets the longtitude segments.
CStdColor m_vDiffuse
The diffuse color to apply to this part. It is specified as red, green, blue, and alpha...
float m_fltConstantAttenRatio
The constant attenuation ratio.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
virtual CStdFPoint Position()
Gets the local position. (m_oPosition)
CStdColor m_vSpecular
The specular color to apply to this part. It is specified as red, green, blue, and alpha...
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
CStdFPoint m_oPosition
These are rotation and position coords relative to the parent if this is a body part.
virtual int LatitudeSegments()
Gets the latitude segments.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual CStdColor * Diffuse()
Gets the diffuse color.
virtual ~OsgLight()
Destructor.
Light(void)
Default constructor.
Declares the vortex structure class.
OsgLight()
Default constructor.
osg::Geometry ANIMAT_OSG_PORT * CreateSphereGeometry(int latres, int longres, float radius)