2 #include "OsgCameraManipulator.h"
3 #include "OsgMovableItem.h"
5 #include "OsgRigidBody.h"
9 #include "OsgUserData.h"
10 #include "OsgSimulationWindow.h"
11 #include "OsgScriptedSimulationWindow.h"
12 #include "OsgMouseSpring.h"
13 #include "OsgDraggerHandler.h"
14 #include "OsgDragger.h"
15 #include "OsgSimulator.h"
19 namespace Visualization
22 OsgScriptedSimulationWindow::OsgScriptedSimulationWindow()
24 m_lpCurrentPath = NULL;
27 m_lpDefaultTrackBody = NULL;
31 OsgScriptedSimulationWindow::~OsgScriptedSimulationWindow(
void)
56 CStdFPoint oNewPoint, oReportPosition;
62 m_vDefaultPosition = oNewPoint;
66 CStdFPoint vTargetPos = m_lpTrackBody->AbsolutePosition();
85 CStdFPoint vPos(fltX, fltY, fltZ);
103 oXml.Deserialize(strXml);
104 oXml.FindElement(
"Root");
105 oXml.FindChildElement(
"Position");
112 std::string OsgScriptedSimulationWindow::DefaultPartID() {
return m_strDefaultPartID;}
114 void OsgScriptedSimulationWindow::DefaultPartID(std::string strID)
116 m_strDefaultPartID = strID;
121 m_lpDefaultTrackBody = NULL;
123 m_lpDefaultTrackBody =
dynamic_cast<BodyPart *
>(
m_lpSim->
FindByID(m_strDefaultPartID));
134 if(strType ==
"POSITION")
140 if(strType ==
"DEFAULTPARTID")
142 DefaultPartID(strValue);
148 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
166 oXml.Deserialize(strXml);
167 oXml.FindElement(
"Root");
168 oXml.FindChildElement(
"CameraPath");
191 int iIdx = FindCameraPath(strID);
192 m_aryCameraPaths.RemoveAt(iIdx);
196 int OsgScriptedSimulationWindow::FindCameraPath(std::string strID,
bool bThrowError)
198 int iCount = m_aryCameraPaths.GetSize();
199 for(
int iIdx=0; iIdx<iCount; iIdx++)
200 if(m_aryCameraPaths[iIdx]->
ID() == strID)
204 THROW_TEXT_ERROR(Al_Err_lItemNotFound, Al_Err_strItemNotFound, (
"ID: " + strID));
209 void OsgScriptedSimulationWindow::SortPaths()
211 m_arySortedCameraPaths.RemoveAll();
213 int iCount = m_aryCameraPaths.GetSize();
214 for(
int iIdx=0; iIdx<iCount; iIdx++)
216 m_arySortedCameraPaths.Add(m_aryCameraPaths[iIdx]->StartTime(), m_aryCameraPaths[iIdx]);
224 if(strType ==
"CAMERAPATH")
232 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
241 if(strType ==
"CAMERAPATH")
249 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Item Type", strItemType);
259 DefaultPartID(m_strDefaultPartID);
261 int iCount = m_aryCameraPaths.GetSize();
262 for(
int iIdx=0; iIdx<iCount; iIdx++)
269 m_lpTrackBody = m_lpDefaultTrackBody;
271 m_iCurrentPathIter = m_arySortedCameraPaths.begin();
273 if(m_arySortedCameraPaths.GetSize() > 0)
274 m_lpCurrentPath = m_iCurrentPathIter->second;
276 m_lpCurrentPath = NULL;
283 m_lpTrackBody = m_lpDefaultTrackBody;
286 m_lpCurrentPath = NULL;
288 int iCount = m_aryCameraPaths.GetSize();
289 for(
int iIndex=0; iIndex<iCount; iIndex++)
293 void OsgScriptedSimulationWindow::FindNextCameraPath()
295 if(m_iCurrentPathIter != m_arySortedCameraPaths.end())
297 m_iCurrentPathIter++;
298 if(m_iCurrentPathIter != m_arySortedCameraPaths.end())
299 m_lpCurrentPath = m_iCurrentPathIter->second;
307 if(m_lpCurrentPath && m_lpCurrentPath->AfterPathTime(
m_lpSim->
Time()))
308 FindNextCameraPath();
310 if(m_lpCurrentPath && m_lpCurrentPath->WithinPathTime(
m_lpSim->
Time()))
314 CStdFPoint oPos = m_lpCurrentPath->TrackBody()->AbsolutePosition();
315 osg::Vec3d vTargetPos(oPos.x, oPos.y, oPos.z);
317 osg::Vec3d vPos = m_lpCurrentPath->GetInterpPosition();
335 m_osgViewer->frame();
339 void OsgScriptedSimulationWindow::Load(CStdXml &oXml)
341 OsgSimulationWindow::Load(oXml);
345 std::string m_strDefaultStructureID;
346 std::string m_strDefaultPartID;
348 DefaultPartID(oXml.GetChildString(
"LookAtBodyID", m_strDefaultPartID));
354 if(oXml.FindChildElement(
"CameraPaths",
false))
358 int iCount = oXml.NumberOfChildren();
359 for(
int iIndex=0; iIndex<iCount; iIndex++)
361 oXml.FindChildByIndex(iIndex);
392 lpSpline->ParentWindow(
this);
394 lpSpline->
Load(oXml);
395 m_aryCameraPaths.Add(lpSpline);
399 catch(CStdErrorInfo oError)
401 if(lpSpline)
delete lpSpline;
408 if(lpSpline)
delete lpSpline;
410 THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
virtual void Initialize()
Initializes this object.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
virtual bool AddItem(const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
Adds a new object to this parent.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Declares the vortex Light class.
Simulator * m_lpSim
The pointer to a Simulation.
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 std::string ID()
Gets the unique GUID ID of this object.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual void RemoveCameraPath(std::string strID, bool bThrowError=true)
Removes the camera path based on ID.
virtual bool SimRunning()
Gets whether the simulation is running.
virtual void SimStarting()
Called just before the simulation starts.
virtual void TrackCamera()
Implements code to do the camera tracking.
virtual CStdFPoint DefaultPosition()
Gets the local position. (m_oPosition)
virtual void SetCameraPositionAndLookAt(CStdFPoint oCameraPos, CStdFPoint oTarget)
Manually sets a camera position and look at position.
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 SetCameraPostion(CStdFPoint vCameraPos)
Manually sets a camera position.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
virtual void Initialize()
Initializes this object.
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
BodyPart * m_lpOriginalTrackBody
Used to keep track of the body part that was being tracked before sim started.
virtual void Initialize()
Initializes this object.
virtual bool Interpolate(const double t)
Interpolate spline at time t.
virtual void TrackCamera()
Implements code to do the camera tracking.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
bool Std_LoadPoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint, bool bThrowError)
Standard load point.
virtual float InverseDistanceUnits()
Gets the inverse distance units.
virtual void Update()
Updates this window.
Declares the vortex structure class.
virtual float Time()
Gets the current simulation time in seconds.
virtual OsgLinearPath * LoadCameraPath(CStdXml &oXml)
Loads the a camera path.
virtual void AddCameraPath(std::string strXml)
Creates and adds a camera path.
virtual bool RemoveItem(const std::string &strItemType, const std::string &strID, bool bThrowError=true)
Removes a child item from this parent.