AnimatLab  2
Test
VsFluidPlane.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "VsMovableItem.h"
9 #include "VsBody.h"
10 #include "VsJoint.h"
11 #include "VsMotorizedJoint.h"
12 #include "VsRigidBody.h"
13 #include "VsFluidPlane.h"
14 #include "VsSimulator.h"
15 #include "VsDragger.h"
16 
17 namespace VortexAnimatSim
18 {
19  namespace Environment
20  {
21  namespace Bodies
22  {
23 
31 {
32  SetThisPointers();
33  m_vxFluidPlane = NULL;
34 }
35 
43 {
44  try
45  {
46  DeleteGraphics();
47  DeletePhysics();
48  }
49  catch(...)
50  {Std_TraceMsg(0, "Caught Error in desctructor of VsFluidPlane/\r\n", "", -1, false, true);}
51 }
52 
53 void VsFluidPlane::CreateGraphicsGeometry()
54 {
55  m_osgGeometry = CreateBoxGeometry(m_ptSize.x, m_ptSize.y, 0.1f, (m_ptSize.x/GridX()), (m_ptSize.y/GridY()), 0.1f);
56 }
57 
58 void VsFluidPlane::CreatePhysicsGeometry()
59 {
60 }
61 
63 {
64  CreateGeometry();
65 
66  //Create the geometry and osg drawable nodes.
67  m_eControlType = VxEntity::kControlNode; //This is not a dynamic part.
68 
69  VsRigidBody::CreateItem();
70  FluidPlane::CreateParts();
71  VsRigidBody::SetBody();
72 }
73 
74 void VsFluidPlane::ResizePhysicsGeometry()
75 {
76 }
77 
78 //Planes can never have fluid interactions/dynamics.
79 void VsFluidPlane::Physics_FluidDataChanged()
80 {}
81 
83 {
84  if(m_vxFluidPlane)
85  m_vxFluidPlane->setGravity(VxVector3(0, m_lpSim->Gravity(), 0));
86 }
87 
88 void VsFluidPlane::Velocity(CStdFPoint &oPoint, bool bUseScaling)
89 {
90  FluidPlane::Velocity(oPoint, bUseScaling);
91 
92  if(m_vxFluidPlane)
93  m_vxFluidPlane->setDefaultVelocity(VxVector3(m_vVelocity.x, m_vVelocity.y, m_vVelocity.z));
94 }
95 
96 void VsFluidPlane::Physics_SetDensity(float fltVal)
97 {
98  if(m_vxFluidPlane)
99  m_vxFluidPlane->setDefaultDensity(fltVal);
100 }
101 
102 void VsFluidPlane::UpdateFluidPlaneHeight()
103 {
104  if(m_vxFluidPlane)
105  {
106  CStdFPoint vPos;
107 
108  if(m_lpThisRB->IsRoot())
109  vPos = m_lpThisAB->GetStructure()->Position();
110  else
111  vPos = m_lpThisRB->AbsolutePosition();
112 
113  m_vxFluidPlane->setLevel(vPos.y);
114  }
115 }
116 
117 void VsFluidPlane::Position(CStdFPoint &oPoint, bool bUseScaling, bool bFireChangeEvent, bool bUpdateMatrix)
118 {
119  FluidPlane::Position(oPoint, bUseScaling, bFireChangeEvent, bUpdateMatrix);
120  UpdateFluidPlaneHeight();
121 }
122 
123 void VsFluidPlane::Physics_PositionChanged()
124 {
125  VsRigidBody::Physics_PositionChanged();
126  UpdateFluidPlaneHeight();
127 }
128 
129 void VsFluidPlane::DeletePhysics()
130 {
131  if(!m_vxFluidPlane)
132  return;
133 
134  if(GetVsSimulator() && GetVsSimulator()->Universe())
135  {
136  GetVsSimulator()->Universe()->removeFluidState(m_vxFluidPlane);
137  delete m_vxFluidPlane;
138  }
139 
140  m_vxFluidPlane = NULL;
141 }
142 
143 void VsFluidPlane::SetupPhysics()
144 {
145  if(m_vxFluidPlane)
146  DeletePhysics();
147 
148  m_vxFluidPlane = new VxPlanarFluidState(m_oAbsPosition.y);
149  m_vxFluidPlane->setDefaultDensity(m_fltDensity);
150  m_vxFluidPlane->setDefaultVelocity(VxVector3(m_vVelocity.x, m_vVelocity.y, m_vVelocity.z));
151  m_vxFluidPlane->setGravity(VxVector3(0, m_lpSim->Gravity(), 0));
152  m_vxFluidPlane->setName(m_lpThisAB->ID().c_str());
153  GetVsSimulator()->Universe()->addFluidState(m_vxFluidPlane);
154 }
155 
156  } //Bodies
157  } // Environment
158 } //VortexAnimatSim
virtual void SetGravity()
Sets the gravity of the fluid.
CStdFPoint m_vVelocity
This is the velocity of the fluid.
Definition: FluidPlane.h:34
virtual float GridY()
Gets the length of a segment for the y dimension of the plane.
Definition: Plane.cpp:118
virtual float Gravity()
Gets the gravity value.
Definition: Simulator.cpp:1225
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual CStdFPoint Position()
Gets the local position. (m_oPosition)
Definition: RigidBody.cpp:131
Declares the vortex fluid plane class.
virtual float GridX()
Gets the width of a segment for the x dimension of the plane.
Definition: Plane.cpp:104
float m_fltDensity
Uniform density for the rigid body.
Definition: RigidBody.h:79
virtual CStdFPoint Velocity()
Gets the velocity of the fluid.
Definition: FluidPlane.cpp:73
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.