AnimatLab  2
Test
VsBoxTest.cpp
1 // VsBoxTest.cpp: implementation of the VsBoxTest class.
2 //
4 
5 #include "StdAfx.h"
6 #include "VsMovableItem.h"
7 #include "VsBody.h"
8 #include "VsJoint.h"
9 #include "VsMotorizedJoint.h"
10 #include "VsRigidBody.h"
11 #include "VsBoxTest.h"
12 #include "VsStructure.h"
13 #include "VsSimulator.h"
14 #include "VsOsgUserData.h"
15 #include "VsOsgUserDataVisitor.h"
16 #include "VsDragger.h"
17 
18 namespace VortexAnimatSim
19 {
20  namespace Environment
21  {
22  namespace Bodies
23  {
24 
26 // Construction/Destruction
28 
29 VsBoxTest::VsBoxTest()
30 {
31  //SetThisPointers();
32 }
33 
34 VsBoxTest::~VsBoxTest()
35 {
36  //try
37  //{
38  // DeleteGraphics();
39  // DeletePhysics();
40  //}
41  //catch(...)
42  //{Std_TraceMsg(0, "Caught Error in desctructor of VsBoxTest\r\n", "", -1, false, true);}
43 }
44 
45 void VsBoxTest::CreateGraphicsGeometry()
46 {
47  //m_osgGeometry = CreateBoxGeometry(Length(), Height(), Width(), LengthSegmentSize(), HeightSegmentSize(), WidthSegmentSize());
48 }
49 
50 void VsBoxTest::CreatePhysicsGeometry()
51 {
52  //if(IsCollisionObject())
53  // m_vxGeometry = new VxBox(m_fltLength, m_fltHeight, m_fltWidth);
54 }
55 
57 {
58  VsSimulator *lpVsSim = dynamic_cast<VsSimulator *>(m_lpSim);
59  osg::Group *m_World = lpVsSim->OSGRoot();
60  VxMaterialTable *m_MT = lpVsSim->Frame()->getMaterialTable();
61 
62  osg::ref_ptr<osg::Node> object;
63  VxGeometry* objectGeom = 0;
64 
65  CStdFPoint vPos = this->Position();
66 
67  osg::ref_ptr<osg::ShapeDrawable> boxDrawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0, 0, 0), m_fltLength, m_fltHeight, m_fltWidth));
68  boxDrawable->setColor(osg::Vec4(1, 0, 0, 0));
69  osg::ref_ptr<osg::Geode> box = new osg::Geode;
70  box->addDrawable(boxDrawable.get());
71  object = box.release();
72  objectGeom = new VxBox(m_fltLength, m_fltHeight, m_fltWidth);
73 
74  // Create the graphical object.
75  // Its root is a transform node (so we could move it around).
76  this->node = new osg::MatrixTransform(osg::Matrix::translate(vPos.x, vPos.y, vPos.z));
77  this->node->setName("Object");
78  this->node->addChild(object.get());
79 
80  // Add it to the scene graph.
81  m_World->addChild(this->node.get());
82 
83  // Create the physics object.
84  // Note that we use a sphere geom to simplify things, but we could have
85  // created a triangle mesh from the same file as the graphical object.
86  this->part = new VxPart; // Create the part.
87  this->part->setName("object"); // Give it a name.
88  this->part->setControl(VxEntity::kControlDynamic); // Set it to dynamic.
89  this->part->setPosition(vPos.x, vPos.y, vPos.z); // Set its initial position.
90 
91  // Add the sphere geometry to the part.
92  this->part->addGeometry(objectGeom, m_MT->getMaterial("DEFAULTMATERIAL"));
93  this->part->setFastMoving(true);
94  this->part->freeze(false);
95 
96  // Add the part to the universe.
97  lpVsSim->Universe()->addEntity(this->part);
98 
99  int iCount = m_aryChildParts.GetSize();
100  for(int iIndex=0; iIndex<iCount; iIndex++)
101  m_aryChildParts[iIndex]->CreateParts();
102 
103 }
104 
106 {
107  //if(m_lpJointToParent)
108  // m_lpJointToParent->CreateJoint();
109 
110  //Box::CreateJoints();
111  //VsRigidBody::Initialize();
112 }
113 
114 void VsBoxTest::ResizePhysicsGeometry()
115 {
116  //if(m_vxGeometry)
117  //{
118  // VxBox *vxBox = dynamic_cast<VxBox *>(m_vxGeometry);
119 
120  // if(!vxBox)
121  // THROW_TEXT_ERROR(Vs_Err_lGeometryMismatch, Vs_Err_strGeometryMismatch, m_lpThisAB->Name());
122  //
123  // vxBox->setDimensions(m_fltLength, m_fltHeight, m_fltWidth);
124  //}
125 }
126 
127 
128  } //Bodies
129  } // Environment
130 } //VortexAnimatSim
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
virtual void CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
Definition: VsBoxTest.cpp:105
float m_fltLength
The length dimension of the box.
Definition: Box.h:46
CStdPtrArray< RigidBody > m_aryChildParts
Definition: RigidBody.h:98
float m_fltWidth
The width dimension of the box.
Definition: Box.h:52
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
float m_fltHeight
The height dimension of the box.
Definition: Box.h:58
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: VsBoxTest.cpp:56
Declares the vortex structure class.