8 #include "VsMovableItem.h"
11 #include "VsMotorizedJoint.h"
12 #include "VsRigidBody.h"
15 #include "VsSimulator.h"
16 #include "VsOsgUserData.h"
17 #include "VsOsgUserDataVisitor.h"
18 #include "VsDragger.h"
51 {
Std_TraceMsg(0,
"Caught Error in desctructor of VsBox\r\n",
"", -1,
false,
true);}
54 void VsLight::SetThisPointers()
56 VsMovableItem::SetThisPointers();
58 m_lpThisLI =
dynamic_cast<Light *
>(
this);
60 THROW_TEXT_ERROR(Vs_Err_lThisPointerNotDefined, Vs_Err_strThisPointerNotDefined,
"m_lpThisLI, " + m_lpThisAB->Name());
63 osg::Group *VsLight::ParentOSG()
65 return GetVsSimulator()->OSGRoot();
72 if(GetVsSimulator() && GetVsSimulator()->OSGRoot())
74 osg::StateSet *rootStateSet = GetVsSimulator()->OSGRoot()->getOrCreateStateSet();
77 rootStateSet->setMode( GetGlLight(), osg::StateAttribute::ON );
79 rootStateSet->setMode( GetGlLight(), osg::StateAttribute::OFF );
83 void VsLight::Position(CStdFPoint &oPoint,
bool bUseScaling,
bool bFireChangeEvent,
bool bUpdateMatrix)
85 Light::Position(oPoint, bUseScaling, bFireChangeEvent, bUpdateMatrix);
88 if(m_osgLight.valid())
91 m_osgLight->setPosition(position);
97 Light::Ambient(aryColor);
100 if(m_osgLight.valid())
103 m_osgLight->setAmbient(color);
109 Light::Diffuse(aryColor);
112 if(m_osgLight.valid())
115 m_osgLight->setDiffuse(color);
121 Light::Specular(aryColor);
124 if(m_osgLight.valid())
127 m_osgLight->setSpecular(specular);
131 void VsLight::SetAttenuation()
133 if(m_osgLight.valid())
140 m_osgLight->setLinearAttenuation(fltAtten);
143 m_osgLight->setLinearAttenuation(0);
148 m_osgLight->setQuadraticAttenuation(fltAtten);
151 m_osgLight->setQuadraticAttenuation(0);
155 int VsLight::GetGlLight()
180 void VsLight::SetupLighting()
190 m_osgLight->setAmbient(ambient);
191 m_osgLight->setDiffuse(diffuse);
192 m_osgLight->setSpecular(specular);
193 m_osgLight->setPosition(position);
195 m_osgLightSource =
new osg::LightSource;
196 m_osgLightSource->setLight(m_osgLight.get());
197 GetVsSimulator()->OSGRoot()->addChild(m_osgLightSource.get());
203 void VsLight::SetupGraphics()
205 VsMovableItem::SetupGraphics();
210 void VsLight::CreateGraphicsGeometry()
215 void VsLight::DeleteGraphics()
217 VsMovableItem::DeleteGraphics();
219 if(m_osgLightSource.valid() && GetVsSimulator() && GetVsSimulator()->OSGRoot())
221 if(GetVsSimulator()->OSGRoot()->containsNode(m_osgLightSource.get()))
222 GetVsSimulator()->OSGRoot()->removeChild(m_osgLightSource.get());
224 osg::StateSet *rootStateSet = GetVsSimulator()->OSGRoot()->getOrCreateStateSet();
225 rootStateSet->setMode( GetGlLight(), osg::StateAttribute::OFF );
228 m_osgLight.release();
229 m_osgLightSource.release();
232 void VsLight::Create()
242 VsMovableItem::Physics_ResetSimulation();
244 Light::ResetSimulation();
247 void VsLight::Physics_Resize()
250 if(m_osgNode.valid())
252 osg::Geode *osgGroup =
dynamic_cast<osg::Geode *
>(m_osgNode.get());
254 THROW_TEXT_ERROR(Vs_Err_lNodeNotGeode, Vs_Err_strNodeNotGeode, m_lpThisAB->Name());
256 if(osgGroup && osgGroup->containsDrawable(m_osgGeometry.get()))
257 osgGroup->removeDrawable(m_osgGeometry.get());
259 m_osgGeometry.release();
262 CreateGraphicsGeometry();
263 m_osgGeometry->setName(m_lpThisAB->Name() +
"_Geometry");
266 osgGroup->addDrawable(m_osgGeometry.get());
269 if(m_osgDragger.valid())
270 m_osgDragger->SetupMatrix();
273 if(m_osgNodeGroup.valid())
276 osgVisitor->traverse(*m_osgNodeGroup);
283 void VsLight::Physics_SetColor()
285 SetColor(*m_lpThisMI->Ambient(), *m_lpThisMI->Diffuse(), *m_lpThisMI->Specular(), m_lpThisMI->Shininess());
virtual bool Enabled()
Tells whether this light is enabled.
VsLight()
Default constructor.
CStdColor m_vAmbient
The ambient color to apply to this part. It is specified as red, green, blue, and alpha...
float m_fltQuadraticAttenDistance
The quadratic attenuation distance.
float m_fltLinearAttenDistance
The linear attenuation distance.
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.
osg::Geometry * CreateSphereGeometry(int latres, int longres, float radius)
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.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
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 CStdColor * Diffuse()
Gets the diffuse color.
Declares the vortex Light class.
Light(void)
Default constructor.
virtual ~VsLight()
Destructor.
Declares the vortex structure class.