6 #include "VsMovableItem.h"
9 #include "VsMotorizedJoint.h"
10 #include "VsRigidBody.h"
11 #include "VsMeshBase.h"
12 #include "VsTerrain.h"
13 #include "VsSimulator.h"
14 #include "VsDragger.h"
27 VsTerrain::VsTerrain()
30 m_bCullBackfaces =
true;
31 m_osgHeightField = NULL;
32 m_vxHeightField = NULL;
35 VsTerrain::~VsTerrain()
43 {
Std_TraceMsg(0,
"Caught Error in desctructor of VsTerrain/\r\n",
"", -1,
false,
true);}
46 void VsTerrain::CreateGraphicsGeometry()
48 m_osgGeometry = CreatePlaneGeometry(-1, -1, 2, 2, 2, 2,
false);
51 void VsTerrain::SetTexture(std::string strTexture)
53 if(m_osgMeshNode.valid())
57 std::string strFile = AnimatSim::GetFilePath(m_lpThisAB->GetSimulator()->ProjectPath(), strTexture);
58 osg::ref_ptr<osg::Image> image = osgDB::readImageFile(strFile);
60 THROW_PARAM_ERROR(Vs_Err_lTextureLoad, Vs_Err_strTextureLoad,
"Image File", strFile);
62 osg::StateSet* state = m_osgMeshNode->getOrCreateStateSet();
63 m_osgTexture =
new osg::Texture2D(image.get());
64 m_osgTexture->setDataVariance(osg::Object::DYNAMIC);
66 m_osgTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR_MIPMAP_LINEAR);
67 m_osgTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
68 m_osgTexture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
69 m_osgTexture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);
72 matrix.makeScale(osg::Vec3(m_iTextureLengthSegments, m_iTextureWidthSegments, 1.0));
74 osg::ref_ptr<osg::TexMat> matTexture =
new osg::TexMat;
75 matTexture->setMatrix(matrix);
77 state->setTextureAttributeAndModes(0, m_osgTexture.get());
78 state->setTextureAttributeAndModes(0, matTexture.get(), osg::StateAttribute::ON);
80 state->setTextureMode(0, m_eTextureMode, osg::StateAttribute::ON);
81 state->setMode(GL_BLEND,osg::StateAttribute::ON);
85 else if(m_osgTexture.valid())
87 m_osgTexture.release();
88 osg::StateSet* state = m_osgMeshNode->getOrCreateStateSet();
89 state->setTextureAttributeAndModes(0, NULL);
90 state->setTextureMode(0, m_eTextureMode, osg::StateAttribute::OFF);
96 void VsTerrain::Physics_FluidDataChanged()
99 void VsTerrain::LoadMeshNode()
101 std::string strPath = m_lpThisAB->GetSimulator()->ProjectPath();
102 std::string strMeshFile = m_lpThisMesh->MeshFile();
103 std::string strFile = AnimatSim::GetFilePath(strPath, strMeshFile);
106 m_osgBaseMeshNode = CreateHeightField(strFile, m_fltSegmentWidth, m_fltSegmentLength, m_fltMaxHeight, &m_osgHeightField);
107 SetTexture(m_lpThisRB->Texture());
109 osg::Matrix osgScaleMatrix = osg::Matrix::identity();
110 m_osgMeshNode =
new osg::MatrixTransform(osgScaleMatrix);
112 m_osgMeshNode->addChild(m_osgBaseMeshNode.get());
113 m_osgMeshNode->setName(m_lpThisAB->Name() +
"_MeshNode");
116 void VsTerrain::CreatePhysicsGeometry()
121 m_vxHeightField = CreateVxHeightField(m_osgHeightField, m_fltSegmentWidth, m_fltSegmentLength, 0, 0, 0);
122 m_vxGeometry = m_vxHeightField;
125 m_eControlType = VxEntity::kControlNode;
128 THROW_TEXT_ERROR(Vs_Err_lCreatingGeometry, Vs_Err_strCreatingGeometry,
"Body: " + m_lpThisAB->Name() +
" Mesh: " + AnimatSim::GetFilePath(m_lpThisAB->GetSimulator()->ProjectPath(), m_lpThisMesh->MeshFile()));
135 VsMeshBase::CreateItem();
136 Terrain::CreateParts();
137 VsMeshBase::SetBody();
145 Terrain::CreateJoints();
146 VsMeshBase::Initialize();
virtual void CreateJoint()
Creates the joint.
virtual void CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
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.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Joint * m_lpJointToParent