AnimatLab  2
Test
Terrrain.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "AnimatBase.h"
11 
12 #include "Node.h"
13 #include "IPhysicsMovableItem.h"
14 #include "IPhysicsBody.h"
15 #include "BoundingBox.h"
16 #include "MovableItem.h"
17 #include "BodyPart.h"
18 #include "Joint.h"
19 #include "ReceptiveField.h"
20 #include "ContactSensor.h"
21 #include "RigidBody.h"
22 #include "Mesh.h"
23 #include "Terrain.h"
24 #include "Structure.h"
25 #include "Organism.h"
26 #include "ActivatedItem.h"
27 #include "ActivatedItemMgr.h"
28 #include "DataChartMgr.h"
29 #include "ExternalStimuliMgr.h"
30 #include "KeyFrame.h"
31 #include "SimulationRecorder.h"
32 #include "OdorType.h"
33 #include "Odor.h"
34 #include "Light.h"
35 #include "LightManager.h"
36 #include "Simulator.h"
37 
38 namespace AnimatSim
39 {
40  namespace Environment
41  {
42  namespace Bodies
43  {
53 {
54  m_fltDensity = 0;
55  m_bFreeze = true;
56  m_strCollisionMeshType = "TERRAIN";
57  m_fltSegmentWidth = 1;
58  m_fltSegmentLength = 1;
59  m_fltMaxHeight = 5;
60  m_iTextureLengthSegments = 10;
61  m_iTextureWidthSegments = 10;
62 }
63 
71 {
72 
73 }
74 
75 float Terrain::SegmentWidth() {return m_fltSegmentWidth;}
76 
77 void Terrain::SegmentWidth(float fltVal, bool bUseScaling)
78 {
79  Std_IsAboveMin((float) 0, fltVal, true, "Terrain.SegmentWidth");
80  if(bUseScaling)
81  m_fltSegmentWidth = fltVal * m_lpSim->InverseDistanceUnits();
82  else
83  m_fltSegmentWidth = fltVal;
84 
85  Resize();
86 }
87 
88 float Terrain::SegmentLength() {return m_fltSegmentLength;}
89 
90 void Terrain::SegmentLength(float fltVal, bool bUseScaling)
91 {
92  Std_IsAboveMin((float) 0, fltVal, true, "Terrain.SegmentLength");
93  if(bUseScaling)
94  m_fltSegmentLength = fltVal * m_lpSim->InverseDistanceUnits();
95  else
96  m_fltSegmentLength = fltVal;
97 
98  Resize();
99 }
100 
101 float Terrain::MaxHeight() {return m_fltMaxHeight;}
102 
103 void Terrain::MaxHeight(float fltVal, bool bUseScaling)
104 {
105  Std_IsAboveMin((float) 0, fltVal, true, "Terrain.MaxHeight");
106  if(bUseScaling)
107  m_fltMaxHeight = fltVal * m_lpSim->InverseDistanceUnits();
108  else
109  m_fltMaxHeight = fltVal;
110 
111  Resize();
112 }
113 
114 int Terrain::TextureLengthSegments()
115 {return m_iTextureLengthSegments;}
116 
117 void Terrain::TextureLengthSegments(int iVal)
118 {
119  Std_IsAboveMin((int) 0, iVal, true, "Terrain.TextureLengthSegments");
120  m_iTextureLengthSegments = iVal;
121 
122  //Reset the texture
124 }
125 
126 int Terrain::TextureWidthSegments()
127 {return m_iTextureWidthSegments;}
128 
129 void Terrain::TextureWidthSegments(int iVal)
130 {
131  Std_IsAboveMin((int) 0, iVal, true, "Terrain.TextureWidthSegments");
132  m_iTextureWidthSegments = iVal;
133 
134  //Reset the texture
136 }
137 
138 bool Terrain::AllowRotateDragX() {return false;}
139 
140 bool Terrain::AllowRotateDragY() {return false;}
141 
142 bool Terrain::AllowRotateDragZ() {return false;}
143 
144 bool Terrain::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
145 {
146  std::string strType = Std_CheckString(strDataType);
147 
148  if(Mesh::SetData(strType, strValue, false))
149  return true;
150 
151  if(strType == "SEGMENTWIDTH")
152  {
153  SegmentWidth((float) atof(strValue.c_str()));
154  return true;
155  }
156 
157  if(strType == "SEGMENTLENGTH")
158  {
159  SegmentLength((float) atof(strValue.c_str()));
160  return true;
161  }
162 
163  if(strType == "MAXHEIGHT")
164  {
165  MaxHeight((float) atof(strValue.c_str()));
166  return true;
167  }
168 
169  if(strType == "TEXTURELENGTHSEGMENTS")
170  {
171  TextureLengthSegments(atoi(strValue.c_str()));
172  return true;
173  }
174 
175  if(strType == "TEXTUREWIDTHSEGMENTS")
176  {
177  TextureWidthSegments(atoi(strValue.c_str()));
178  return true;
179  }
180 
181  //If it was not one of those above then we have a problem.
182  if(bThrowError)
183  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
184 
185  return false;
186 }
187 
188 void Terrain::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
189 {
190  Mesh::QueryProperties(aryProperties);
191 
192  aryProperties.Add(new TypeProperty("SegmentWidth", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
193  aryProperties.Add(new TypeProperty("SegmentLength", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
194  aryProperties.Add(new TypeProperty("MaxHeight", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
195  aryProperties.Add(new TypeProperty("TextureLengthSegments", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
196  aryProperties.Add(new TypeProperty("TextureWidthSegments", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
197 }
198 
199 void Terrain::Load(CStdXml &oXml)
200 {
201  Mesh::Load(oXml);
202 
203  oXml.IntoElem(); //Into RigidBody Element
204 
205  SegmentWidth(oXml.GetChildFloat("SegmentWidth", m_fltSegmentWidth));
206  SegmentLength(oXml.GetChildFloat("SegmentLength", m_fltSegmentLength));
207  MaxHeight(oXml.GetChildFloat("MaxHeight", m_fltMaxHeight));
208  TextureLengthSegments(oXml.GetChildInt("TextureLengthSegments", m_iTextureLengthSegments));
209  TextureWidthSegments(oXml.GetChildInt("TextureWidthSegments", m_iTextureWidthSegments));
210 
211  oXml.OutOfElem(); //OutOf RigidBody Element
212 
213  //Density is always zero
214  m_fltDensity = 0;
215 
216  //This part type is always frozen
217  m_bFreeze = true;
218 }
219 
220 
221  } //Bodies
222  } //Environment
223 } //AnimatSim
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
Root namespace for the base simulation library for AnimatLab.
Declares the body part class.
std::string m_strCollisionMeshType
Type of the collision mesh. Can be Convex or Triangular.
Definition: Mesh.h:18
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
Declares the key frame class.
Declares the joint class.
Declares the organism class.
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
Definition: StdXml.cpp:456
virtual std::string Texture()
Gets the texture filename.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
Declares a light object.
virtual void Resize()
Called when this object has been resized.
Definition: BodyPart.cpp:141
Declares the activated item class.
Declares a light manager object.
float m_fltDensity
Uniform density for the rigid body.
Definition: RigidBody.h:79
Declares the bounding box class.
A standard xml manipulation class.
Definition: StdXml.h:19
virtual bool AllowRotateDragX()
Gets whether this body part can be rotated along the x-axis by the user with the drag handlers...
Definition: Terrrain.cpp:138
Declares the node class.
virtual bool AllowRotateDragZ()
Gets whether this body part can be rotated along the z-axis by the user with the drag handlers...
Definition: Terrrain.cpp:142
virtual bool AllowRotateDragY()
Gets whether this body part can be rotated along the y-axis by the user with the drag handlers...
Definition: Terrrain.cpp:140
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Terrain()
Default constructor.
Definition: Terrrain.cpp:52
Declares the data chart manager class.
Declares the rigid body class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the terrain class.
Declares the structure class.
Declares the odor type class.
virtual float InverseDistanceUnits()
Gets the inverse distance units.
Definition: Simulator.cpp:1742
Declares the odor class.
Declares the simulator class.
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
Declares the receptive field class.
std::string m_strTexture
An optional texture to apply to the rigid body.
Definition: MovableItem.h:91
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617