AnimatLab  2
Test
VsConstraintRelaxation.cpp
1 // VsConstraintRelaxation.cpp: implementation of the VsConstraintRelaxation class.
2 //
4 
5 #include "StdAfx.h"
6 #include "VsConstraintRelaxation.h"
7 #include "VsMovableItem.h"
8 #include "VsBody.h"
9 #include "VsJoint.h"
10 #include "VsMotorizedJoint.h"
11 #include "VsRigidBody.h"
12 #include "VsStructure.h"
13 #include "VsSimulator.h"
14 #include "VsOsgUserData.h"
15 #include "VsOsgUserDataVisitor.h"
16 #include "VsDragger.h"
17 #include "VsSimulator.h"
18 
19 namespace VortexAnimatSim
20 {
21  namespace Environment
22  {
23 
25 // Construction/Destruction
27 
28 VsConstraintRelaxation::VsConstraintRelaxation()
29 {
30  m_fltLoss = 0;
31 }
32 
33 VsConstraintRelaxation::~VsConstraintRelaxation()
34 {
35 }
36 
50 
64 void VsConstraintRelaxation::Loss(float fltVal, bool bUseScaling)
65 {
66  Std_IsAboveMin((float) 0, fltVal, true, "Loss", true);
67 
68  if(bUseScaling)
69  fltVal *= m_lpSim->MassUnits(); //Slip units are s/Kg
70 
71  m_fltLoss = fltVal;
72  SetRelaxationProperties();
73 }
74 
76 {
77  ConstraintRelaxation::Initialize();
78 
79  SetRelaxationProperties();
80 }
81 
90 {
91  ConstraintRelaxation::CreateDefaultUnits();
92 
93  m_fltLoss *= m_lpSim->MassUnits(); //Slip units are s/Kg
94 }
95 
96 bool VsConstraintRelaxation::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
97 {
98  std::string strType = Std_CheckString(strDataType);
99 
100  if(ConstraintRelaxation::SetData(strType, strValue, false))
101  return true;
102 
103  if(strType == "LOSS")
104  {
105  Loss((float) atof(strValue.c_str()));
106  return true;
107  }
108 
109  //If it was not one of those above then we have a problem.
110  if(bThrowError)
111  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
112 
113  return false;
114 }
115 
116 void VsConstraintRelaxation::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
117 {
118  ConstraintRelaxation::QueryProperties(aryProperties);
119 
120  aryProperties.Add(new TypeProperty("Loss", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
121 }
122 
123 void VsConstraintRelaxation::Load(CStdXml &oXml)
124 {
125  ConstraintRelaxation::Load(oXml);
126 
127  oXml.IntoElem(); //Into ConstraintRelaxation Element
128 
129  Loss(oXml.GetChildFloat("Loss", m_fltLoss));
130 
131  oXml.OutOfElem(); //OutOf ConstraintRelaxation Element
132 
133 }
134 
135 void VsConstraintRelaxation::SetRelaxationProperties()
136 {
137  if(m_lpSim && m_lpNode)
138  {
139  VsJoint *lpJoint = dynamic_cast<VsJoint *>(m_lpNode);
140  if(lpJoint)
141  {
142  Vx::VxConstraint *vxConstraint = lpJoint->Constraint();
143 
144  if(vxConstraint)
145  vxConstraint->setRelaxationParameters(m_iCoordinateID, m_fltStiffness, m_fltDamping, m_fltLoss, m_bEnabled);
146  }
147  }
148 }
149 
150  } // Visualization
151 } //VortexAnimatSim
virtual void CreateDefaultUnits()
This takes the default values defined in the constructor and scales them according to the distance an...
virtual float Loss()
Gets the primary linear slip value.
float m_fltLoss
The primary linear slip of the collision between those two materials.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
int m_iCoordinateID
The constraint coordinate ID.
virtual void Initialize()
Initializes this object.
A common class for all joint data specific to vortex.
Definition: VsJoint.h:32
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
float m_fltDamping
The damping of the collision between those two materials.
float m_fltStiffness
The compliance of the collision between those two materials.
virtual void MassUnits(std::string strUnits)
Sets the mass units.
Definition: Simulator.cpp:1772
Node * m_lpNode
The pointer to this items parent Node. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:52
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
Definition: AnimatBase.h:40
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the vortex structure class.