Merge pull request #10438 from druiz17/input-recorder-fix

fix issue when loading recording file into the input recorder
This commit is contained in:
anshuman64 2017-05-10 17:34:46 -07:00 committed by GitHub
commit 1be404ef87

View file

@ -22,20 +22,20 @@
#include <BuildInfo.h> #include <BuildInfo.h>
#include <GLMHelpers.h> #include <GLMHelpers.h>
QString SAVE_DIRECTORY = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + BuildInfo::MODIFIED_ORGANIZATION + "/" + BuildInfo::INTERFACE_NAME + "/hifi-input-recordings/"; QString SAVE_DIRECTORY = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + BuildInfo::MODIFIED_ORGANIZATION + "/" + BuildInfo::INTERFACE_NAME + "/hifi-input-recordings/";
QString FILE_PREFIX_NAME = "input-recording-"; QString FILE_PREFIX_NAME = "input-recording-";
QString COMPRESS_EXTENSION = ".tar.gz"; QString COMPRESS_EXTENSION = ".tar.gz";
namespace controller { namespace controller {
QJsonObject poseToJsonObject(const Pose pose) { QJsonObject poseToJsonObject(const Pose pose) {
QJsonObject newPose; QJsonObject newPose;
QJsonArray translation; QJsonArray translation;
translation.append(pose.translation.x); translation.append(pose.translation.x);
translation.append(pose.translation.y); translation.append(pose.translation.y);
translation.append(pose.translation.z); translation.append(pose.translation.z);
QJsonArray rotation; QJsonArray rotation;
rotation.append(pose.rotation.x); rotation.append(pose.rotation.x);
rotation.append(pose.rotation.y); rotation.append(pose.rotation.y);
@ -69,7 +69,7 @@ namespace controller {
QJsonArray angularVelocity = object["angularVelocity"].toArray(); QJsonArray angularVelocity = object["angularVelocity"].toArray();
pose.valid = object["valid"].toBool(); pose.valid = object["valid"].toBool();
pose.translation.x = translation[0].toDouble(); pose.translation.x = translation[0].toDouble();
pose.translation.y = translation[1].toDouble(); pose.translation.y = translation[1].toDouble();
pose.translation.z = translation[2].toDouble(); pose.translation.z = translation[2].toDouble();
@ -89,13 +89,13 @@ namespace controller {
return pose; return pose;
} }
void exportToFile(QJsonObject& object) { void exportToFile(QJsonObject& object) {
if (!QDir(SAVE_DIRECTORY).exists()) { if (!QDir(SAVE_DIRECTORY).exists()) {
QDir().mkdir(SAVE_DIRECTORY); QDir().mkdir(SAVE_DIRECTORY);
} }
QString timeStamp = QDateTime::currentDateTime().toString(Qt::ISODate); QString timeStamp = QDateTime::currentDateTime().toString(Qt::ISODate);
timeStamp.replace(":", "-"); timeStamp.replace(":", "-");
QString fileName = SAVE_DIRECTORY + FILE_PREFIX_NAME + timeStamp + COMPRESS_EXTENSION; QString fileName = SAVE_DIRECTORY + FILE_PREFIX_NAME + timeStamp + COMPRESS_EXTENSION;
@ -124,7 +124,7 @@ namespace controller {
status = true; status = true;
return object; return object;
} }
InputRecorder::InputRecorder() {} InputRecorder::InputRecorder() {}
InputRecorder::~InputRecorder() {} InputRecorder::~InputRecorder() {}
@ -195,16 +195,16 @@ namespace controller {
_framesRecorded = data["frameCount"].toInt(); _framesRecorded = data["frameCount"].toInt();
QJsonArray actionArrayList = data["actionList"].toArray(); QJsonArray actionArrayList = data["actionList"].toArray();
QJsonArray poseArrayList = data["poseList"].toArray(); QJsonArray poseArrayList = data["poseList"].toArray();
for (int actionIndex = 0; actionIndex < actionArrayList.size(); actionIndex++) { for (int actionIndex = 0; actionIndex < actionArrayList.size(); actionIndex++) {
QJsonArray actionState = actionArrayList[actionIndex].toArray(); QJsonArray actionState = actionArrayList[actionIndex].toArray();
for (int index = 0; index < actionState.size(); index++) { for (int index = 0; index < actionState.size(); index++) {
_currentFrameActions[index] = actionState[index].toInt(); _currentFrameActions[index] = actionState[index].toDouble();
} }
_actionStateList.push_back(_currentFrameActions); _actionStateList.push_back(_currentFrameActions);
_currentFrameActions = ActionStates(toInt(Action::NUM_ACTIONS)); _currentFrameActions = ActionStates(toInt(Action::NUM_ACTIONS));
} }
for (int poseIndex = 0; poseIndex < poseArrayList.size(); poseIndex++) { for (int poseIndex = 0; poseIndex < poseArrayList.size(); poseIndex++) {
QJsonArray poseState = poseArrayList[poseIndex].toArray(); QJsonArray poseState = poseArrayList[poseIndex].toArray();
for (int index = 0; index < poseState.size(); index++) { for (int index = 0; index < poseState.size(); index++) {
@ -250,13 +250,13 @@ namespace controller {
for(auto& channel : _currentFramePoses) { for(auto& channel : _currentFramePoses) {
channel = Pose(); channel = Pose();
} }
for(auto& channel : _currentFrameActions) { for(auto& channel : _currentFrameActions) {
channel = 0.0f; channel = 0.0f;
} }
} }
} }
float InputRecorder::getActionState(controller::Action action) { float InputRecorder::getActionState(controller::Action action) {
if (_actionStateList.size() > 0 ) { if (_actionStateList.size() > 0 ) {
return _actionStateList[_playCount][toInt(action)]; return _actionStateList[_playCount][toInt(action)];