AnimatLab  2
Test
OsgStructure.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "OsgMovableItem.h"
9 #include "OsgBody.h"
10 #include "OsgRigidBody.h"
11 #include "OsgJoint.h"
12 #include "OsgStructure.h"
13 #include "OsgDragger.h"
14 #include "OsgSimulator.h"
15 
16 namespace OsgAnimatSim
17 {
18  namespace Environment
19  {
20 
28 {
29  m_lpOsgBody = NULL;
30  SetThisPointers();
31 }
32 
40 {
41 }
42 
43 void OsgStructure::Body(RigidBody *lpBody)
44 {
45  Structure::Body(lpBody);
46  m_lpOsgBody = dynamic_cast<OsgMovableItem *>(lpBody);
47 
48  if(!m_lpOsgBody)
49  THROW_TEXT_ERROR(Osg_Err_lUnableToConvertToVsRigidBody, Osg_Err_strUnableToConvertToVsRigidBody, "ID: " + lpBody->Name());
50 }
51 
52 void OsgStructure::SetThisPointers()
53 {
54  OsgMovableItem::SetThisPointers();
55 
56  m_lpThisST = dynamic_cast<Structure *>(this);
57  if(!m_lpThisST)
58  THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined, "m_lpThisST, " + m_lpThisAB->Name());
59 }
60 
61 osg::MatrixTransform *OsgStructure::ParentOSG()
62 {
63  return GetOsgSimulator()->OSGRoot();
64 }
65 
66 void OsgStructure::Create()
67 {
68  CreateItem();
69 
70  Structure::Create();
71 }
72 
73 void OsgStructure::SetupPhysics()
74 {
75 }
76 
78 {
79  OsgMovableItem::Physics_ResetSimulation();
80 
81  Structure::ResetSimulation();
82 }
83 
84 void OsgStructure::UpdatePositionAndRotationFromMatrix()
85 {
86  OsgMovableItem::UpdatePositionAndRotationFromMatrix();
87 
88  if(m_lpOsgBody)
89  {
90  m_lpOsgBody->EndGripDrag();
91 
92  //Get the new world matrix from the root body and update our world position.
93  m_osgFinalMatrix = m_lpOsgBody->FinalMatrix();
94  Physics_UpdateAbsolutePosition();
95  }
96 }
97 
98 
99  } // Environment
100 } //OsgAnimatSim
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual RigidBody * Body()
Gets the root body.
Definition: Structure.cpp:115
Structure()
Default constructor.
Definition: Structure.cpp:53
virtual void ResetSimulation()
Resets the simulation back to time 0.
Declares the vortex structure class.