summaryrefslogtreecommitdiff
path: root/indra/newview/llagentpilot.cpp
diff options
context:
space:
mode:
authorAnsariel <ansariel.hiller@phoenixviewer.com>2024-05-22 19:04:52 +0200
committerAnsariel <ansariel.hiller@phoenixviewer.com>2024-05-22 19:04:52 +0200
commit1b67dd855c41f5a0cda7ec2a68d98071986ca703 (patch)
treeab243607f74f78200787bba5b9b88f07ef1b966f /indra/newview/llagentpilot.cpp
parent6d6eabca44d08d5b97bfe3e941d2b9687c2246ea (diff)
parente1623bb276f83a43ce7a197e388720c05bdefe61 (diff)
Merge remote-tracking branch 'origin/main' into DRTVWR-600-maint-A
# Conflicts: # autobuild.xml # indra/cmake/CMakeLists.txt # indra/cmake/GoogleMock.cmake # indra/llaudio/llaudioengine_fmodstudio.cpp # indra/llaudio/llaudioengine_fmodstudio.h # indra/llaudio/lllistener_fmodstudio.cpp # indra/llaudio/lllistener_fmodstudio.h # indra/llaudio/llstreamingaudio_fmodstudio.cpp # indra/llaudio/llstreamingaudio_fmodstudio.h # indra/llcharacter/llmultigesture.cpp # indra/llcharacter/llmultigesture.h # indra/llimage/llimage.cpp # indra/llimage/llimagepng.cpp # indra/llimage/llimageworker.cpp # indra/llimage/tests/llimageworker_test.cpp # indra/llmessage/tests/llmockhttpclient.h # indra/llprimitive/llgltfmaterial.h # indra/llrender/llfontfreetype.cpp # indra/llui/llcombobox.cpp # indra/llui/llfolderview.cpp # indra/llui/llfolderviewmodel.h # indra/llui/lllineeditor.cpp # indra/llui/lllineeditor.h # indra/llui/lltextbase.cpp # indra/llui/lltextbase.h # indra/llui/lltexteditor.cpp # indra/llui/lltextvalidate.cpp # indra/llui/lltextvalidate.h # indra/llui/lluictrl.h # indra/llui/llview.cpp # indra/llwindow/llwindowmacosx.cpp # indra/newview/app_settings/settings.xml # indra/newview/llappearancemgr.cpp # indra/newview/llappearancemgr.h # indra/newview/llavatarpropertiesprocessor.cpp # indra/newview/llavatarpropertiesprocessor.h # indra/newview/llbreadcrumbview.cpp # indra/newview/llbreadcrumbview.h # indra/newview/llbreastmotion.cpp # indra/newview/llbreastmotion.h # indra/newview/llconversationmodel.h # indra/newview/lldensityctrl.cpp # indra/newview/lldensityctrl.h # indra/newview/llface.inl # indra/newview/llfloatereditsky.cpp # indra/newview/llfloatereditwater.cpp # indra/newview/llfloateremojipicker.h # indra/newview/llfloaterimsessiontab.cpp # indra/newview/llfloaterprofiletexture.cpp # indra/newview/llfloaterprofiletexture.h # indra/newview/llgesturemgr.cpp # indra/newview/llgesturemgr.h # indra/newview/llimpanel.cpp # indra/newview/llimpanel.h # indra/newview/llinventorybridge.cpp # indra/newview/llinventorybridge.h # indra/newview/llinventoryclipboard.cpp # indra/newview/llinventoryclipboard.h # indra/newview/llinventoryfunctions.cpp # indra/newview/llinventoryfunctions.h # indra/newview/llinventorygallery.cpp # indra/newview/lllistbrowser.cpp # indra/newview/lllistbrowser.h # indra/newview/llpanelobjectinventory.cpp # indra/newview/llpanelprofile.cpp # indra/newview/llpanelprofile.h # indra/newview/llpreviewgesture.cpp # indra/newview/llsavedsettingsglue.cpp # indra/newview/llsavedsettingsglue.h # indra/newview/lltooldraganddrop.cpp # indra/newview/llurllineeditorctrl.cpp # indra/newview/llvectorperfoptions.cpp # indra/newview/llvectorperfoptions.h # indra/newview/llviewerparceloverlay.cpp # indra/newview/llviewertexlayer.cpp # indra/newview/llviewertexturelist.cpp # indra/newview/macmain.h # indra/test/test.cpp
Diffstat (limited to 'indra/newview/llagentpilot.cpp')
-rw-r--r--indra/newview/llagentpilot.cpp814
1 files changed, 407 insertions, 407 deletions
diff --git a/indra/newview/llagentpilot.cpp b/indra/newview/llagentpilot.cpp
index c62431db91..0aaa93b6d2 100644
--- a/indra/newview/llagentpilot.cpp
+++ b/indra/newview/llagentpilot.cpp
@@ -1,407 +1,407 @@
-/**
- * @file llagentpilot.cpp
- * @brief LLAgentPilot class implementation
- *
- * $LicenseInfo:firstyear=2002&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include "llviewerprecompiledheaders.h"
-
-#include <iostream>
-#include <fstream>
-#include <iomanip>
-
-#include "llagentpilot.h"
-#include "llagent.h"
-#include "llappviewer.h"
-#include "llviewercontrol.h"
-#include "llviewercamera.h"
-#include "llsdserialize.h"
-#include "llsdutil_math.h"
-
-LLAgentPilot gAgentPilot;
-
-LLAgentPilot::LLAgentPilot() :
- mNumRuns(-1),
- mQuitAfterRuns(false),
- mRecording(false),
- mLastRecordTime(0.f),
- mStarted(false),
- mPlaying(false),
- mCurrentAction(0),
- mOverrideCamera(false),
- mLoop(true),
- mReplaySession(false)
-{
-}
-
-LLAgentPilot::~LLAgentPilot()
-{
-}
-
-void LLAgentPilot::load()
-{
- std::string txt_filename = gSavedSettings.getString("StatsPilotFile");
- std::string xml_filename = gSavedSettings.getString("StatsPilotXMLFile");
- if (LLFile::isfile(xml_filename))
- {
- loadXML(xml_filename);
- }
- else if (LLFile::isfile(txt_filename))
- {
- loadTxt(txt_filename);
- }
- else
- {
- LL_DEBUGS() << "no autopilot file found" << LL_ENDL;
- return;
- }
-}
-
-void LLAgentPilot::loadTxt(const std::string& filename)
-{
- if(filename.empty())
- {
- return;
- }
-
- llifstream file(filename.c_str());
-
- if (!file)
- {
- LL_DEBUGS() << "Couldn't open " << filename
- << ", aborting agentpilot load!" << LL_ENDL;
- return;
- }
- else
- {
- LL_INFOS() << "Opening pilot file " << filename << LL_ENDL;
- }
-
- mActions.clear();
- S32 num_actions;
-
- file >> num_actions;
-
- mActions.reserve(num_actions);
- for (S32 i = 0; i < num_actions; i++)
- {
- S32 action_type;
- Action new_action;
- file >> new_action.mTime >> action_type;
- file >> new_action.mTarget.mdV[VX] >> new_action.mTarget.mdV[VY] >> new_action.mTarget.mdV[VZ];
- new_action.mType = (EActionType)action_type;
- mActions.push_back(new_action);
- }
-
- mOverrideCamera = false;
-
- file.close();
-}
-
-void LLAgentPilot::loadXML(const std::string& filename)
-{
- if(filename.empty())
- {
- return;
- }
-
- llifstream file(filename.c_str());
-
- if (!file)
- {
- LL_DEBUGS() << "Couldn't open " << filename
- << ", aborting agentpilot load!" << LL_ENDL;
- return;
- }
- else
- {
- LL_INFOS() << "Opening pilot file " << filename << LL_ENDL;
- }
-
- mActions.clear();
- LLSD record;
- while (!file.eof() && LLSDParser::PARSE_FAILURE != LLSDSerialize::fromXML(record, file))
- {
- Action action;
- action.mTime = record["time"].asReal();
- action.mType = (EActionType)record["type"].asInteger();
- action.mCameraView = record["camera_view"].asReal();
- action.mTarget = ll_vector3d_from_sd(record["target"]);
- action.mCameraOrigin = ll_vector3_from_sd(record["camera_origin"]);
- action.mCameraXAxis = ll_vector3_from_sd(record["camera_xaxis"]);
- action.mCameraYAxis = ll_vector3_from_sd(record["camera_yaxis"]);
- action.mCameraZAxis = ll_vector3_from_sd(record["camera_zaxis"]);
- mActions.push_back(action);
- }
- mOverrideCamera = true;
- file.close();
-}
-
-void LLAgentPilot::save()
-{
- std::string txt_filename = gSavedSettings.getString("StatsPilotFile");
- std::string xml_filename = gSavedSettings.getString("StatsPilotXMLFile");
- saveTxt(txt_filename);
- saveXML(xml_filename);
-}
-
-void LLAgentPilot::saveTxt(const std::string& filename)
-{
- llofstream file;
- file.open(filename.c_str());
-
- if (!file)
- {
- LL_INFOS() << "Couldn't open " << filename << ", aborting agentpilot save!" << LL_ENDL;
- }
-
- file << mActions.size() << '\n';
-
- S32 i;
- for (i = 0; i < mActions.size(); i++)
- {
- file << mActions[i].mTime << "\t" << mActions[i].mType << "\t";
- file << std::setprecision(32) << mActions[i].mTarget.mdV[VX] << "\t" << mActions[i].mTarget.mdV[VY] << "\t" << mActions[i].mTarget.mdV[VZ];
- file << '\n';
- }
-
- file.close();
-}
-
-void LLAgentPilot::saveXML(const std::string& filename)
-{
- llofstream file;
- file.open(filename.c_str());
-
- if (!file)
- {
- LL_INFOS() << "Couldn't open " << filename << ", aborting agentpilot save!" << LL_ENDL;
- }
-
- S32 i;
- for (i = 0; i < mActions.size(); i++)
- {
- Action& action = mActions[i];
- LLSD record;
- record["time"] = (LLSD::Real)action.mTime;
- record["type"] = (LLSD::Integer)action.mType;
- record["camera_view"] = (LLSD::Real)action.mCameraView;
- record["target"] = ll_sd_from_vector3d(action.mTarget);
- record["camera_origin"] = ll_sd_from_vector3(action.mCameraOrigin);
- record["camera_xaxis"] = ll_sd_from_vector3(action.mCameraXAxis);
- record["camera_yaxis"] = ll_sd_from_vector3(action.mCameraYAxis);
- record["camera_zaxis"] = ll_sd_from_vector3(action.mCameraZAxis);
- LLSDSerialize::toXML(record, file);
- }
- file.close();
-}
-
-void LLAgentPilot::startRecord()
-{
- mActions.clear();
- mTimer.reset();
- addAction(STRAIGHT);
- mRecording = true;
-}
-
-void LLAgentPilot::stopRecord()
-{
- gAgentPilot.addAction(STRAIGHT);
- gAgentPilot.save();
- mRecording = false;
-}
-
-void LLAgentPilot::addAction(enum EActionType action_type)
-{
- LL_INFOS() << "Adding waypoint: " << gAgent.getPositionGlobal() << LL_ENDL;
- Action action;
- action.mType = action_type;
- action.mTarget = gAgent.getPositionGlobal();
- action.mTime = mTimer.getElapsedTimeF32();
- LLViewerCamera *cam = LLViewerCamera::getInstance();
- action.mCameraView = cam->getView();
- action.mCameraOrigin = cam->getOrigin();
- action.mCameraXAxis = cam->getXAxis();
- action.mCameraYAxis = cam->getYAxis();
- action.mCameraZAxis = cam->getZAxis();
- mLastRecordTime = (F32)action.mTime;
- mActions.push_back(action);
-}
-
-void LLAgentPilot::startPlayback()
-{
- if (!mPlaying)
- {
- mPlaying = true;
- mCurrentAction = 0;
- mTimer.reset();
-
- if (mActions.size())
- {
- LL_INFOS() << "Starting playback, moving to waypoint 0" << LL_ENDL;
- gAgent.startAutoPilotGlobal(mActions[0].mTarget);
- moveCamera();
- mStarted = false;
- }
- else
- {
- LL_INFOS() << "No autopilot data, cancelling!" << LL_ENDL;
- mPlaying = false;
- }
- }
-}
-
-void LLAgentPilot::stopPlayback()
-{
- if (mPlaying)
- {
- mPlaying = false;
- mCurrentAction = 0;
- mTimer.reset();
- gAgent.stopAutoPilot();
- }
-
- if (mReplaySession)
- {
- LLAppViewer::instance()->forceQuit();
- }
-}
-
-void LLAgentPilot::moveCamera()
-{
- if (!getOverrideCamera())
- return;
-
- if (mCurrentAction<mActions.size())
- {
- S32 start_index = llmax(mCurrentAction-1,0);
- S32 end_index = mCurrentAction;
- F32 t = 0.0;
- F32 timedelta = mActions[end_index].mTime - mActions[start_index].mTime;
- F32 tickelapsed = mTimer.getElapsedTimeF32()-mActions[start_index].mTime;
- if (timedelta > 0.0)
- {
- t = tickelapsed/timedelta;
- }
-
- if ((t<0.0)||(t>1.0))
- {
- LL_WARNS() << "mCurrentAction is invalid, t = " << t << LL_ENDL;
- return;
- }
-
- Action& start = mActions[start_index];
- Action& end = mActions[end_index];
-
- F32 view = lerp(start.mCameraView, end.mCameraView, t);
- LLVector3 origin = lerp(start.mCameraOrigin, end.mCameraOrigin, t);
- LLQuaternion start_quat(start.mCameraXAxis, start.mCameraYAxis, start.mCameraZAxis);
- LLQuaternion end_quat(end.mCameraXAxis, end.mCameraYAxis, end.mCameraZAxis);
- LLQuaternion quat = nlerp(t, start_quat, end_quat);
- LLMatrix3 mat(quat);
-
- LLViewerCamera::getInstance()->setView(view);
- LLViewerCamera::getInstance()->setOrigin(origin);
- LLViewerCamera::getInstance()->mXAxis = LLVector3(mat.mMatrix[0]);
- LLViewerCamera::getInstance()->mYAxis = LLVector3(mat.mMatrix[1]);
- LLViewerCamera::getInstance()->mZAxis = LLVector3(mat.mMatrix[2]);
- }
-}
-
-void LLAgentPilot::updateTarget()
-{
- if (mPlaying)
- {
- if (mCurrentAction < mActions.size())
- {
- if (0 == mCurrentAction)
- {
- if (gAgent.getAutoPilot())
- {
- // Wait until we get to the first location before starting.
- return;
- }
- else
- {
- if (!mStarted)
- {
- LL_INFOS() << "At start, beginning playback" << LL_ENDL;
- mTimer.reset();
- mStarted = true;
- }
- }
- }
- if (mTimer.getElapsedTimeF32() > mActions[mCurrentAction].mTime)
- {
- //gAgent.stopAutoPilot();
- mCurrentAction++;
-
- if (mCurrentAction < mActions.size())
- {
- gAgent.startAutoPilotGlobal(mActions[mCurrentAction].mTarget);
- moveCamera();
- }
- else
- {
- stopPlayback();
- mNumRuns--;
- if (mLoop)
- {
- if ((mNumRuns < 0) || (mNumRuns > 0))
- {
- LL_INFOS() << "Looping, restarting playback" << LL_ENDL;
- startPlayback();
- }
- else if (mQuitAfterRuns)
- {
- LL_INFOS() << "Done with all runs, quitting viewer!" << LL_ENDL;
- LLAppViewer::instance()->forceQuit();
- }
- else
- {
- LL_INFOS() << "Done with all runs, disabling pilot" << LL_ENDL;
- stopPlayback();
- }
- }
- }
- }
- }
- else
- {
- stopPlayback();
- }
- }
- else if (mRecording)
- {
- if (mTimer.getElapsedTimeF32() - mLastRecordTime > 1.f)
- {
- addAction(STRAIGHT);
- }
- }
-}
-
-void LLAgentPilot::addWaypoint()
-{
- addAction(STRAIGHT);
-}
-
+/**
+ * @file llagentpilot.cpp
+ * @brief LLAgentPilot class implementation
+ *
+ * $LicenseInfo:firstyear=2002&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+
+#include "llagentpilot.h"
+#include "llagent.h"
+#include "llappviewer.h"
+#include "llviewercontrol.h"
+#include "llviewercamera.h"
+#include "llsdserialize.h"
+#include "llsdutil_math.h"
+
+LLAgentPilot gAgentPilot;
+
+LLAgentPilot::LLAgentPilot() :
+ mNumRuns(-1),
+ mQuitAfterRuns(false),
+ mRecording(false),
+ mLastRecordTime(0.f),
+ mStarted(false),
+ mPlaying(false),
+ mCurrentAction(0),
+ mOverrideCamera(false),
+ mLoop(true),
+ mReplaySession(false)
+{
+}
+
+LLAgentPilot::~LLAgentPilot()
+{
+}
+
+void LLAgentPilot::load()
+{
+ std::string txt_filename = gSavedSettings.getString("StatsPilotFile");
+ std::string xml_filename = gSavedSettings.getString("StatsPilotXMLFile");
+ if (LLFile::isfile(xml_filename))
+ {
+ loadXML(xml_filename);
+ }
+ else if (LLFile::isfile(txt_filename))
+ {
+ loadTxt(txt_filename);
+ }
+ else
+ {
+ LL_DEBUGS() << "no autopilot file found" << LL_ENDL;
+ return;
+ }
+}
+
+void LLAgentPilot::loadTxt(const std::string& filename)
+{
+ if(filename.empty())
+ {
+ return;
+ }
+
+ llifstream file(filename.c_str());
+
+ if (!file)
+ {
+ LL_DEBUGS() << "Couldn't open " << filename
+ << ", aborting agentpilot load!" << LL_ENDL;
+ return;
+ }
+ else
+ {
+ LL_INFOS() << "Opening pilot file " << filename << LL_ENDL;
+ }
+
+ mActions.clear();
+ S32 num_actions;
+
+ file >> num_actions;
+
+ mActions.reserve(num_actions);
+ for (S32 i = 0; i < num_actions; i++)
+ {
+ S32 action_type;
+ Action new_action;
+ file >> new_action.mTime >> action_type;
+ file >> new_action.mTarget.mdV[VX] >> new_action.mTarget.mdV[VY] >> new_action.mTarget.mdV[VZ];
+ new_action.mType = (EActionType)action_type;
+ mActions.push_back(new_action);
+ }
+
+ mOverrideCamera = false;
+
+ file.close();
+}
+
+void LLAgentPilot::loadXML(const std::string& filename)
+{
+ if(filename.empty())
+ {
+ return;
+ }
+
+ llifstream file(filename.c_str());
+
+ if (!file)
+ {
+ LL_DEBUGS() << "Couldn't open " << filename
+ << ", aborting agentpilot load!" << LL_ENDL;
+ return;
+ }
+ else
+ {
+ LL_INFOS() << "Opening pilot file " << filename << LL_ENDL;
+ }
+
+ mActions.clear();
+ LLSD record;
+ while (!file.eof() && LLSDParser::PARSE_FAILURE != LLSDSerialize::fromXML(record, file))
+ {
+ Action action;
+ action.mTime = record["time"].asReal();
+ action.mType = (EActionType)record["type"].asInteger();
+ action.mCameraView = record["camera_view"].asReal();
+ action.mTarget = ll_vector3d_from_sd(record["target"]);
+ action.mCameraOrigin = ll_vector3_from_sd(record["camera_origin"]);
+ action.mCameraXAxis = ll_vector3_from_sd(record["camera_xaxis"]);
+ action.mCameraYAxis = ll_vector3_from_sd(record["camera_yaxis"]);
+ action.mCameraZAxis = ll_vector3_from_sd(record["camera_zaxis"]);
+ mActions.push_back(action);
+ }
+ mOverrideCamera = true;
+ file.close();
+}
+
+void LLAgentPilot::save()
+{
+ std::string txt_filename = gSavedSettings.getString("StatsPilotFile");
+ std::string xml_filename = gSavedSettings.getString("StatsPilotXMLFile");
+ saveTxt(txt_filename);
+ saveXML(xml_filename);
+}
+
+void LLAgentPilot::saveTxt(const std::string& filename)
+{
+ llofstream file;
+ file.open(filename.c_str());
+
+ if (!file)
+ {
+ LL_INFOS() << "Couldn't open " << filename << ", aborting agentpilot save!" << LL_ENDL;
+ }
+
+ file << mActions.size() << '\n';
+
+ S32 i;
+ for (i = 0; i < mActions.size(); i++)
+ {
+ file << mActions[i].mTime << "\t" << mActions[i].mType << "\t";
+ file << std::setprecision(32) << mActions[i].mTarget.mdV[VX] << "\t" << mActions[i].mTarget.mdV[VY] << "\t" << mActions[i].mTarget.mdV[VZ];
+ file << '\n';
+ }
+
+ file.close();
+}
+
+void LLAgentPilot::saveXML(const std::string& filename)
+{
+ llofstream file;
+ file.open(filename.c_str());
+
+ if (!file)
+ {
+ LL_INFOS() << "Couldn't open " << filename << ", aborting agentpilot save!" << LL_ENDL;
+ }
+
+ S32 i;
+ for (i = 0; i < mActions.size(); i++)
+ {
+ Action& action = mActions[i];
+ LLSD record;
+ record["time"] = (LLSD::Real)action.mTime;
+ record["type"] = (LLSD::Integer)action.mType;
+ record["camera_view"] = (LLSD::Real)action.mCameraView;
+ record["target"] = ll_sd_from_vector3d(action.mTarget);
+ record["camera_origin"] = ll_sd_from_vector3(action.mCameraOrigin);
+ record["camera_xaxis"] = ll_sd_from_vector3(action.mCameraXAxis);
+ record["camera_yaxis"] = ll_sd_from_vector3(action.mCameraYAxis);
+ record["camera_zaxis"] = ll_sd_from_vector3(action.mCameraZAxis);
+ LLSDSerialize::toXML(record, file);
+ }
+ file.close();
+}
+
+void LLAgentPilot::startRecord()
+{
+ mActions.clear();
+ mTimer.reset();
+ addAction(STRAIGHT);
+ mRecording = true;
+}
+
+void LLAgentPilot::stopRecord()
+{
+ gAgentPilot.addAction(STRAIGHT);
+ gAgentPilot.save();
+ mRecording = false;
+}
+
+void LLAgentPilot::addAction(enum EActionType action_type)
+{
+ LL_INFOS() << "Adding waypoint: " << gAgent.getPositionGlobal() << LL_ENDL;
+ Action action;
+ action.mType = action_type;
+ action.mTarget = gAgent.getPositionGlobal();
+ action.mTime = mTimer.getElapsedTimeF32();
+ LLViewerCamera *cam = LLViewerCamera::getInstance();
+ action.mCameraView = cam->getView();
+ action.mCameraOrigin = cam->getOrigin();
+ action.mCameraXAxis = cam->getXAxis();
+ action.mCameraYAxis = cam->getYAxis();
+ action.mCameraZAxis = cam->getZAxis();
+ mLastRecordTime = (F32)action.mTime;
+ mActions.push_back(action);
+}
+
+void LLAgentPilot::startPlayback()
+{
+ if (!mPlaying)
+ {
+ mPlaying = true;
+ mCurrentAction = 0;
+ mTimer.reset();
+
+ if (mActions.size())
+ {
+ LL_INFOS() << "Starting playback, moving to waypoint 0" << LL_ENDL;
+ gAgent.startAutoPilotGlobal(mActions[0].mTarget);
+ moveCamera();
+ mStarted = false;
+ }
+ else
+ {
+ LL_INFOS() << "No autopilot data, cancelling!" << LL_ENDL;
+ mPlaying = false;
+ }
+ }
+}
+
+void LLAgentPilot::stopPlayback()
+{
+ if (mPlaying)
+ {
+ mPlaying = false;
+ mCurrentAction = 0;
+ mTimer.reset();
+ gAgent.stopAutoPilot();
+ }
+
+ if (mReplaySession)
+ {
+ LLAppViewer::instance()->forceQuit();
+ }
+}
+
+void LLAgentPilot::moveCamera()
+{
+ if (!getOverrideCamera())
+ return;
+
+ if (mCurrentAction<mActions.size())
+ {
+ S32 start_index = llmax(mCurrentAction-1,0);
+ S32 end_index = mCurrentAction;
+ F32 t = 0.0;
+ F32 timedelta = mActions[end_index].mTime - mActions[start_index].mTime;
+ F32 tickelapsed = mTimer.getElapsedTimeF32()-mActions[start_index].mTime;
+ if (timedelta > 0.0)
+ {
+ t = tickelapsed/timedelta;
+ }
+
+ if ((t<0.0)||(t>1.0))
+ {
+ LL_WARNS() << "mCurrentAction is invalid, t = " << t << LL_ENDL;
+ return;
+ }
+
+ Action& start = mActions[start_index];
+ Action& end = mActions[end_index];
+
+ F32 view = lerp(start.mCameraView, end.mCameraView, t);
+ LLVector3 origin = lerp(start.mCameraOrigin, end.mCameraOrigin, t);
+ LLQuaternion start_quat(start.mCameraXAxis, start.mCameraYAxis, start.mCameraZAxis);
+ LLQuaternion end_quat(end.mCameraXAxis, end.mCameraYAxis, end.mCameraZAxis);
+ LLQuaternion quat = nlerp(t, start_quat, end_quat);
+ LLMatrix3 mat(quat);
+
+ LLViewerCamera::getInstance()->setView(view);
+ LLViewerCamera::getInstance()->setOrigin(origin);
+ LLViewerCamera::getInstance()->mXAxis = LLVector3(mat.mMatrix[0]);
+ LLViewerCamera::getInstance()->mYAxis = LLVector3(mat.mMatrix[1]);
+ LLViewerCamera::getInstance()->mZAxis = LLVector3(mat.mMatrix[2]);
+ }
+}
+
+void LLAgentPilot::updateTarget()
+{
+ if (mPlaying)
+ {
+ if (mCurrentAction < mActions.size())
+ {
+ if (0 == mCurrentAction)
+ {
+ if (gAgent.getAutoPilot())
+ {
+ // Wait until we get to the first location before starting.
+ return;
+ }
+ else
+ {
+ if (!mStarted)
+ {
+ LL_INFOS() << "At start, beginning playback" << LL_ENDL;
+ mTimer.reset();
+ mStarted = true;
+ }
+ }
+ }
+ if (mTimer.getElapsedTimeF32() > mActions[mCurrentAction].mTime)
+ {
+ //gAgent.stopAutoPilot();
+ mCurrentAction++;
+
+ if (mCurrentAction < mActions.size())
+ {
+ gAgent.startAutoPilotGlobal(mActions[mCurrentAction].mTarget);
+ moveCamera();
+ }
+ else
+ {
+ stopPlayback();
+ mNumRuns--;
+ if (mLoop)
+ {
+ if ((mNumRuns < 0) || (mNumRuns > 0))
+ {
+ LL_INFOS() << "Looping, restarting playback" << LL_ENDL;
+ startPlayback();
+ }
+ else if (mQuitAfterRuns)
+ {
+ LL_INFOS() << "Done with all runs, quitting viewer!" << LL_ENDL;
+ LLAppViewer::instance()->forceQuit();
+ }
+ else
+ {
+ LL_INFOS() << "Done with all runs, disabling pilot" << LL_ENDL;
+ stopPlayback();
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ stopPlayback();
+ }
+ }
+ else if (mRecording)
+ {
+ if (mTimer.getElapsedTimeF32() - mLastRecordTime > 1.f)
+ {
+ addAction(STRAIGHT);
+ }
+ }
+}
+
+void LLAgentPilot::addWaypoint()
+{
+ addAction(STRAIGHT);
+}
+