AnimatLab  2
Test
OsgOrganism.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 "OsgOrganism.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 
33 OsgOrganism::~OsgOrganism()
34 {
35 }
36 
37 void OsgOrganism::Body(RigidBody *lpBody)
38 {
39  Organism::Body(lpBody);
40  m_lpOsgBody = dynamic_cast<OsgMovableItem *>(lpBody);
41 
42  if(!m_lpOsgBody)
43  THROW_TEXT_ERROR(Osg_Err_lUnableToConvertToVsRigidBody, Osg_Err_strUnableToConvertToVsRigidBody, "ID: " + lpBody->Name());
44 }
45 
46 void OsgOrganism::SetThisPointers()
47 {
48  OsgMovableItem::SetThisPointers();
49 
50  m_lpThisST = dynamic_cast<Structure *>(this);
51  if(!m_lpThisST)
52  THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined, "m_lpThisST, " + m_lpThisAB->Name());
53 
54  m_lpThisOG = dynamic_cast<Organism *>(this);
55  if(!m_lpThisOG)
56  THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined, "m_lpThisOG, " + m_lpThisAB->Name());
57 }
58 
59 osg::MatrixTransform *OsgOrganism::ParentOSG()
60 {
61  return GetOsgSimulator()->OSGRoot();
62 }
63 
64 void OsgOrganism::Create()
65 {
66  CreateItem();
67 
68  Organism::Create();
69 }
70 
71 void OsgOrganism::SetupPhysics()
72 {
73 }
74 
76 {
77  OsgMovableItem::Physics_ResetSimulation();
78 
79  Organism::ResetSimulation();
80 }
81 
82 void OsgOrganism::UpdatePositionAndRotationFromMatrix()
83 {
84  OsgMovableItem::UpdatePositionAndRotationFromMatrix();
85 
86  if(m_lpOsgBody)
87  {
88  m_lpOsgBody->EndGripDrag();
89 
90  //Get the new world matrix from the root body and update our world position.
91  m_osgFinalMatrix = m_lpOsgBody->FinalMatrix();
92  Physics_UpdateAbsolutePosition();
93  }
94 }
95 
96  } // Environment
97 } //OsgAnimatSim
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
OsgOrganism()
Default constructor.
Definition: OsgOrganism.cpp:27
virtual RigidBody * Body()
Gets the root body.
Definition: Structure.cpp:115
Organism()
Default constructor.
Definition: Organism.cpp:50
Structure()
Default constructor.
Definition: Structure.cpp:53
Declares the vortex organism class.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: OsgOrganism.cpp:75