AnimatLab  2
Test
VsPlaneTest.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 "VsPlaneTest.h"
14 #include "VsStructure.h"
15 #include "VsSimulator.h"
16 #include "VsOsgUserData.h"
17 #include "VsOsgUserDataVisitor.h"
18 #include "VsDragger.h"
19 
20 namespace VortexAnimatSim
21 {
22  namespace Environment
23  {
24  namespace Bodies
25  {
26 
34 {
35  //SetThisPointers();
36  //m_bCullBackfaces = true; //we want back face culling on by default for planes.
37 }
38 
46 {
47  //try
48  //{
49  // DeleteGraphics();
50  // DeletePhysics();
51  //}
52  //catch(...)
53  //{Std_TraceMsg(0, "Caught Error in desctructor of VsPlaneTest/\r\n", "", -1, false, true);}
54 }
55 
56 void VsPlaneTest::CreateGraphicsGeometry()
57 {
58  //m_osgGeometry = CreatePlaneGeometry(CornerX(), CornerY(), m_ptSize.x, m_ptSize.y, GridX(), GridY(), false);
59 }
60 
61 void VsPlaneTest::CreatePhysicsGeometry()
62 {
63  //if(IsCollisionObject())
64  // m_vxGeometry = new VxPlane();
65 }
66 
68 {
69  VsSimulator *lpVsSim = dynamic_cast<VsSimulator *>(m_lpSim);
70  osg::Group *m_World = lpVsSim->OSGRoot();
71  VxMaterialTable *m_MT = lpVsSim->Frame()->getMaterialTable();
72 
73  //****** Terrain ******//
74  osg::ref_ptr<osg::Node> terrain;
75  VxGeometry* terrainGeom = 0;
76 
77  // Create a plane geometry using an OSG helper function. Note that
78  // graphically, a plane cannot be infinite, so we create it to be
79  // 2x2, centered around the world origin.
80  osg::ref_ptr<osg::Geometry> terrainDrawable = osg::createTexturedQuadGeometry(
81  osg::Vec3(-50, 0, -50), osg::Vec3(100, 0, 0), osg::Vec3(0, 0, 100), 0, 0, 1, 1);
82 
83  // Create the node necessary to hold the geometry.
84  osg::ref_ptr<osg::Geode> terrainGeode = new osg::Geode;
85  terrainGeode->addDrawable(terrainDrawable.get());
86  terrain = terrainGeode.release();
87 
88  // Load the geometry from the same node as the graphical object.
89  terrainGeom = new VxPlane;
90 
91  // Create the graphical object.
92  // Its root is a transform node (so we could move it around).
93  this->node = new osg::MatrixTransform;
94  this->node->setName("TerrainNode");
95 
96  // Read the file and add it as a child of the transform.
97  this->node->addChild(terrain.get());
98 
99  // Add it to the scene graph.
100  m_World->addChild(this->node.get());
101 
102  // Create the physics object.
103  this->part = new VxPart; // Create the part.
104  this->part->setName("TerrainPart"); // Give it a name.
105  this->part->setControl(VxEntity::kControlNode); // Set it to kinetic.
106  this->part->freeze(true); // Freeze it.
107 
108  // Add the geometry to the part.
109  this->part->addGeometry(terrainGeom, m_MT->getMaterial("DEFAULTMATERIAL"));
110 
111  // Add it to the universe.
112  lpVsSim->Universe()->addEntity(this->part);
113 }
114 
115 void VsPlaneTest::ResizePhysicsGeometry()
116 {
117  //if(m_vxGeometry)
118  // m_vxGeometry = new VxPlane();
119 }
120 //Planes can never have fluid interactions/dynamics.
121 void VsPlaneTest::Physics_FluidDataChanged()
122 {}
123 
124  } //Bodies
125  } // Environment
126 } //VortexAnimatSim
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: VsPlaneTest.cpp:67
Declares the vortex plane class.
Declares the vortex structure class.