diff options
Diffstat (limited to 'indra/newview/llagentpilot.cpp')
-rwxr-xr-x[-rw-r--r--] | indra/newview/llagentpilot.cpp | 195 |
1 files changed, 162 insertions, 33 deletions
diff --git a/indra/newview/llagentpilot.cpp b/indra/newview/llagentpilot.cpp index 13e1023185..734c502fcf 100644..100755 --- a/indra/newview/llagentpilot.cpp +++ b/indra/newview/llagentpilot.cpp @@ -34,12 +34,12 @@ #include "llagent.h" #include "llappviewer.h" #include "llviewercontrol.h" +#include "llviewercamera.h" +#include "llsdserialize.h" +#include "llsdutil_math.h" LLAgentPilot gAgentPilot; -BOOL LLAgentPilot::sLoop = TRUE; -BOOL LLAgentPilot::sReplaySession = FALSE; - LLAgentPilot::LLAgentPilot() : mNumRuns(-1), mQuitAfterRuns(FALSE), @@ -47,7 +47,10 @@ LLAgentPilot::LLAgentPilot() : mLastRecordTime(0.f), mStarted(FALSE), mPlaying(FALSE), - mCurrentAction(0) + mCurrentAction(0), + mOverrideCamera(FALSE), + mLoop(TRUE), + mReplaySession(FALSE) { } @@ -55,7 +58,26 @@ LLAgentPilot::~LLAgentPilot() { } -void LLAgentPilot::load(const std::string& filename) +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 + { + lldebugs << "no autopilot file found" << llendl; + return; + } +} + +void LLAgentPilot::loadTxt(const std::string& filename) { if(filename.empty()) { @@ -75,6 +97,7 @@ void LLAgentPilot::load(const std::string& filename) llinfos << "Opening pilot file " << filename << llendl; } + mActions.reset(); S32 num_actions; file >> num_actions; @@ -89,10 +112,59 @@ void LLAgentPilot::load(const std::string& filename) mActions.put(new_action); } + mOverrideCamera = false; + + file.close(); +} + +void LLAgentPilot::loadXML(const std::string& filename) +{ + if(filename.empty()) + { + return; + } + + llifstream file(filename); + + if (!file) + { + lldebugs << "Couldn't open " << filename + << ", aborting agentpilot load!" << llendl; + return; + } + else + { + llinfos << "Opening pilot file " << filename << llendl; + } + + mActions.reset(); + LLSD record; + while (!file.eof() && 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.put(action); + } + mOverrideCamera = true; file.close(); } -void LLAgentPilot::save(const std::string& filename) +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); @@ -108,12 +180,41 @@ void LLAgentPilot::save(const std::string& filename) for (i = 0; i < mActions.count(); 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] << '\n'; + 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); + + if (!file) + { + llinfos << "Couldn't open " << filename << ", aborting agentpilot save!" << llendl; + } + + S32 i; + for (i = 0; i < mActions.count(); 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.reset(); @@ -125,7 +226,7 @@ void LLAgentPilot::startRecord() void LLAgentPilot::stopRecord() { gAgentPilot.addAction(STRAIGHT); - gAgentPilot.save(gSavedSettings.getString("StatsPilotFile")); + gAgentPilot.save(); mRecording = FALSE; } @@ -136,6 +237,12 @@ void LLAgentPilot::addAction(enum EActionType action_type) 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.put(action); } @@ -152,6 +259,7 @@ void LLAgentPilot::startPlayback() { llinfos << "Starting playback, moving to waypoint 0" << llendl; gAgent.startAutoPilotGlobal(mActions[0].mTarget); + moveCamera(); mStarted = FALSE; } else @@ -172,12 +280,53 @@ void LLAgentPilot::stopPlayback() gAgent.stopAutoPilot(); } - if (sReplaySession) + if (mReplaySession) { LLAppViewer::instance()->forceQuit(); } } +void LLAgentPilot::moveCamera() +{ + if (!getOverrideCamera()) + return; + + if (mCurrentAction<mActions.count()) + { + 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)) + { + llwarns << "mCurrentAction is invalid, t = " << t << llendl; + 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) @@ -209,12 +358,13 @@ void LLAgentPilot::updateTarget() if (mCurrentAction < mActions.count()) { gAgent.startAutoPilotGlobal(mActions[mCurrentAction].mTarget); + moveCamera(); } else { stopPlayback(); mNumRuns--; - if (sLoop) + if (mLoop) { if ((mNumRuns < 0) || (mNumRuns > 0)) { @@ -249,29 +399,8 @@ void LLAgentPilot::updateTarget() } } -// static -void LLAgentPilot::startRecord(void *) -{ - gAgentPilot.startRecord(); -} - -void LLAgentPilot::saveRecord(void *) +void LLAgentPilot::addWaypoint() { - gAgentPilot.stopRecord(); -} - -void LLAgentPilot::addWaypoint(void *) -{ - gAgentPilot.addAction(STRAIGHT); -} - -void LLAgentPilot::startPlayback(void *) -{ - gAgentPilot.mNumRuns = -1; - gAgentPilot.startPlayback(); + addAction(STRAIGHT); } -void LLAgentPilot::stopPlayback(void *) -{ - gAgentPilot.stopPlayback(); -} |