2 #include "VsMouseSpring.h"
3 #include "VsCameraManipulator.h"
4 #include "VsMovableItem.h"
7 #include "VsRigidBody.h"
10 #include "VsSimulator.h"
11 #include "VsOsgUserData.h"
12 #include "VsSimulationWindow.h"
13 #include "VsScriptedSimulationWindow.h"
14 #include "VsMouseSpring.h"
15 #include "VsDraggerHandler.h"
16 #include "VsDragger.h"
20 namespace Visualization
23 VsScriptedSimulationWindow::VsScriptedSimulationWindow()
25 m_lpCurrentPath = NULL;
28 m_lpDefaultTrackBody = NULL;
32 VsScriptedSimulationWindow::~VsScriptedSimulationWindow(
void)
57 CStdFPoint oNewPoint, oReportPosition;
63 m_vDefaultPosition = oNewPoint;
67 CStdFPoint vTargetPos = m_lpTrackBody->AbsolutePosition();
86 CStdFPoint vPos(fltX, fltY, fltZ);
104 oXml.Deserialize(strXml);
105 oXml.FindElement(
"Root");
106 oXml.FindChildElement(
"Position");
113 std::string VsScriptedSimulationWindow::DefaultPartID() {
return m_strDefaultPartID;}
115 void VsScriptedSimulationWindow::DefaultPartID(std::string strID)
117 m_strDefaultPartID = strID;
122 m_lpDefaultTrackBody = NULL;
124 m_lpDefaultTrackBody =
dynamic_cast<BodyPart *
>(
m_lpSim->
FindByID(m_strDefaultPartID));
135 if(strType ==
"POSITION")
141 if(strType ==
"DEFAULTPARTID")
143 DefaultPartID(strValue);
149 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
167 oXml.Deserialize(strXml);
168 oXml.FindElement(
"Root");
169 oXml.FindChildElement(
"CameraPath");
192 int iIdx = FindCameraPath(strID);
193 m_aryCameraPaths.RemoveAt(iIdx);
197 int VsScriptedSimulationWindow::FindCameraPath(std::string strID,
bool bThrowError)
199 int iCount = m_aryCameraPaths.GetSize();
200 for(
int iIdx=0; iIdx<iCount; iIdx++)
201 if(m_aryCameraPaths[iIdx]->
ID() == strID)
205 THROW_TEXT_ERROR(Al_Err_lItemNotFound, Al_Err_strItemNotFound, (
"ID: " + strID));
210 void VsScriptedSimulationWindow::SortPaths()
212 m_arySortedCameraPaths.RemoveAll();
214 int iCount = m_aryCameraPaths.GetSize();
215 for(
int iIdx=0; iIdx<iCount; iIdx++)
217 m_arySortedCameraPaths.Add(m_aryCameraPaths[iIdx]->StartTime(), m_aryCameraPaths[iIdx]);
225 if(strType ==
"CAMERAPATH")
233 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
242 if(strType ==
"CAMERAPATH")
250 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
260 DefaultPartID(m_strDefaultPartID);
262 int iCount = m_aryCameraPaths.GetSize();
263 for(
int iIdx=0; iIdx<iCount; iIdx++)
270 m_lpTrackBody = m_lpDefaultTrackBody;
272 m_iCurrentPathIter = m_arySortedCameraPaths.begin();
274 if(m_arySortedCameraPaths.GetSize() > 0)
275 m_lpCurrentPath = m_iCurrentPathIter->second;
277 m_lpCurrentPath = NULL;
284 m_lpTrackBody = m_lpDefaultTrackBody;
287 m_lpCurrentPath = NULL;
289 int iCount = m_aryCameraPaths.GetSize();
290 for(
int iIndex=0; iIndex<iCount; iIndex++)
294 void VsScriptedSimulationWindow::FindNextCameraPath()
296 if(m_iCurrentPathIter != m_arySortedCameraPaths.end())
298 m_iCurrentPathIter++;
299 if(m_iCurrentPathIter != m_arySortedCameraPaths.end())
300 m_lpCurrentPath = m_iCurrentPathIter->second;
308 if(m_lpCurrentPath && m_lpCurrentPath->AfterPathTime(
m_lpSim->
Time()))
309 FindNextCameraPath();
311 if(m_lpCurrentPath && m_lpCurrentPath->WithinPathTime(
m_lpSim->
Time()))
315 CStdFPoint oPos = m_lpCurrentPath->TrackBody()->AbsolutePosition();
316 osg::Vec3d vTargetPos(oPos.x, oPos.y, oPos.z);
318 osg::Vec3d vPos = m_lpCurrentPath->GetInterpPosition();
320 std::string strMesage =
"Time: " + STR(
m_lpSim->
Time()) +
", Pos: [" + STR(vPos.x()) +
", " + STR(vPos.y()) +
", " + STR(vPos.z()) +
"]\n";
321 OutputDebugString(strMesage.c_str());
336 m_osgViewer->frame();
340 void VsScriptedSimulationWindow::Load(CStdXml &oXml)
342 VsSimulationWindow::Load(oXml);
346 std::string m_strDefaultStructureID;
347 std::string m_strDefaultPartID;
349 DefaultPartID(oXml.GetChildString(
"LookAtBodyID", m_strDefaultPartID));
355 if(oXml.FindChildElement(
"CameraPaths",
false))
359 int iCount = oXml.NumberOfChildren();
360 for(
int iIndex=0; iIndex<iCount; iIndex++)
362 oXml.FindChildByIndex(iIndex);
393 lpSpline->ParentWindow(
this);
395 lpSpline->
Load(oXml);
396 m_aryCameraPaths.Add(lpSpline);
400 catch(CStdErrorInfo oError)
402 if(lpSpline)
delete lpSpline;
409 if(lpSpline)
delete lpSpline;
411 THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
virtual void RemoveCameraPath(std::string strID, bool bThrowError=true)
Removes the camera path based on ID.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
virtual void Initialize()
Initializes this object.
virtual OsgLinearPath * LoadCameraPath(CStdXml &oXml)
Loads the a camera path.
virtual void Initialize()
Initializes this object.
Simulator * m_lpSim
The pointer to a Simulation.
BodyPart * m_lpOriginalTrackBody
Used to keep track of the body part that was being tracked before sim started.
virtual void AddCameraPath(std::string strXml)
Creates and adds a camera path.
virtual std::string ID()
Gets the unique GUID ID of this object.
virtual void Initialize()
Initializes this object.
virtual void SimStarting()
Called just before the simulation starts.
virtual bool RemoveItem(const std::string &strItemType, const std::string &strID, bool bThrowError=true)
Removes a child item from this parent.
virtual bool SimRunning()
Gets whether the simulation is running.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
virtual bool AddItem(const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
Adds a new object to this parent.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual void Update()
Updates this window.
virtual CStdFPoint DefaultPosition()
Gets the local position. (m_oPosition)
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
virtual void SetCameraPostion(CStdFPoint vCameraPos)
Manually sets a camera position.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the vortex Light class.
bool Std_LoadPoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint, bool bThrowError)
Standard load point.
virtual void TrackCamera()
Implements code to do the camera tracking.
virtual bool Interpolate(const double t)
Interpolate spline at time t.
virtual void SetCameraPositionAndLookAt(CStdFPoint oCameraPos, CStdFPoint oTarget)
Manually sets a camera position and look at position.
virtual float InverseDistanceUnits()
Gets the inverse distance units.
virtual float Time()
Gets the current simulation time in seconds.
virtual void TrackCamera()
Implements code to do the camera tracking.
Declares the vortex structure class.