AnimatLab  2
Test
VsSimulator.h
1 
2 #pragma once
3 
4 #include "VsMeshMgr.h"
5 #include "VsMaterialType.h"
6 #include "VsHud.h"
7 #include "VsIntersectionEvent.h"
8 #include "VsMouseSpring.h"
9 #include "VsCameraManipulator.h"
10 #include "VsSimulationWindowMgr.h"
11 
17 namespace VortexAnimatSim
18 {
19 
20  class VORTEX_PORT VsSimulator : public AnimatSim::Simulator
21  {
22  protected:
23  VsSimulationWindowMgr *m_vsWinMgr;
24 
25  //osg group node for the main scene
26  osg::ref_ptr<osg::Group> m_grpScene;
27 
28  //Command manager for gripper manipulators in the scene.
29  osg::ref_ptr<osgManipulator::CommandManager> m_osgCmdMgr;
30 
31  //Vortex Universe
32  VxUniverse *m_uUniverse;
33 
34  //Vortex Frame
35  VxFrame *m_vxFrame;
36 
37  osg::AlphaFunc *m_osgAlphafunc;
38 
39  VsIntersectionEvent m_vsIntersect;
40 
41  double m_dblTotalVortexStepTime;
42  long m_lStepVortexTimeCount;
43 
44  double m_dblTotalStepTime;
45  long m_lStepTimeCount;
46 
47  VsMeshMgr *m_lpMeshMgr;
48 
49  virtual AnimatSim::Recording::SimulationRecorder *CreateSimulationRecorder();
50  virtual void SnapshotStopFrame();
51 
52  //helper functions
53  void InitializeVortex(int argc, const char **argv);
54  void InitializeVortexViewer(int argc, const char **argv);
55  void SetSimulationStabilityParams();
56 
57  virtual void StepSimulation();
58  virtual void SimulateEnd();
59 
60  virtual void UpdateSimulationWindows();
61 
62  osg::NotifySeverity ConvertTraceLevelToOSG();
63 
64  osg::ref_ptr<osg::Node> m_Spline;
65 
66  public:
67  VsSimulator();
68  virtual ~VsSimulator();
69 
70  Vx::VxUniverse* Universe();
71  Vx::VxFrame* Frame();
72  VsRigidBody *TrackBody();
73  osg::Group *OSGRoot() {return m_grpScene.get();};
74  osgManipulator::CommandManager *OsgCmdMgr() {return m_osgCmdMgr.get();};
75  VsMeshMgr *MeshMgr()
76  {
77  if(!m_lpMeshMgr)
78  m_lpMeshMgr = new VsMeshMgr();
79 
80  return m_lpMeshMgr;
81  };
82 
83 #pragma region CreateMethods
84 
85  virtual Vx::VxTriangleMesh *CreatTriangleMeshFromOsg(osg::Node *osgNode);
86  virtual Vx::VxConvexMesh *CreateConvexMeshFromOsg(osg::Node *osgNode);
87  virtual void GenerateCollisionMeshFile(std::string strOriginalMeshFile, std::string strCollisionMeshFile, float fltScaleX, float fltScaleY, float fltScaleZ);
88  virtual void ConvertV1MeshFile(std::string strOriginalMeshFile, std::string strNewMeshFile, std::string strTexture);
89 
90 #pragma endregion
91 
92 #pragma region MutatorOverrides
93 
94  virtual void StabilityScale(float fltVal);
95  virtual void LinearCompliance(float fltVal, bool bUseScaling = true);
96  virtual void AngularCompliance(float fltVal, bool bUseScaling = true);
97  virtual void LinearDamping(float fltVal, bool bUseScaling = true);
98  virtual void AngularDamping(float fltVal, bool bUseScaling = true);
99  virtual void LinearKineticLoss(float fltVal, bool bUseScaling = true);
100  virtual void AngularKineticLoss(float fltVal, bool bUseScaling = true);
101 
102  virtual void PhysicsTimeStep(float fltVal);
103  virtual void Gravity(float fltVal, bool bUseScaling = true);
104  virtual int GetMaterialID(std::string strID);
105 
106 #pragma endregion
107 
108 #pragma region HelperMethods
109 
110  virtual void GetPositionAndRotationFromD3DMatrix(float (&aryTransform)[4][4], CStdFPoint &vPos, CStdFPoint &vRot);
111 
112  //Timer Methods
113  virtual unsigned long long GetTimerTick();
114  virtual double TimerDiff_n(unsigned long long lStart, unsigned long long lEnd);
115  virtual double TimerDiff_u(unsigned long long lStart, unsigned long long lEnd);
116  virtual double TimerDiff_m(unsigned long long lStart, unsigned long long lEnd);
117  virtual double TimerDiff_s(unsigned long long lStart, unsigned long long lEnd);
118  virtual void MicroSleep(unsigned int iMicroTime);
119  virtual void WriteToConsole(std::string strMessage);
120 
121 #pragma endregion
122 
123  virtual void AlphaThreshold(float fltValue);
124 
125  virtual float *GetDataPointer(const std::string &strDataType);
126 
127  virtual void Reset(); //Resets the entire application back to the default state
128  virtual void ResetSimulation(); //Resets the current simulation back to time 0.0
129 
130  virtual void Initialize(int argc, const char **argv);
131  virtual void ShutdownSimulation();
132  virtual void ToggleSimulation();
133  virtual void StopSimulation();
134  virtual bool StartSimulation();
135  virtual bool PauseSimulation();
136  virtual void Save(std::string strFile);
137 
138  static VsSimulator *ConvertSimulator(Simulator *lpSim);
139  };
140 
141 } //VortexAnimatSim
Vortex physical structure implementation.
Definition: VsMeshMgr.h:18
Simulates the entire environment.
Definition: Simulator.h:31
Declares the vortex heads-up display class.
Records the simulation keyframes and videos.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
Declares the vortex MeshMgr class.