This commit is contained in:
2021-10-14 13:47:35 +02:00
commit 6625a8dfaa
4026 changed files with 844291 additions and 0 deletions
@@ -0,0 +1,126 @@
#include "ovaC3DEntityManipulator.h"
REGISTER_OBJECT_FACTORY(C3DEntityManipulator, "ovaC3DEntityManipulator");
C3DEntityManipulator::C3DEntityManipulator(OMK::Controller& controller, const OMK::ObjectDescriptor& objectDesc) : OMK::SimulatedObject(controller, objectDesc) { }
C3DEntityManipulator::~C3DEntityManipulator() { }
void C3DEntityManipulator::init()
{
registerForSignal(g_sVrpnButtonStateUpdate);
registerForSignal(g_sVrpnAnalogStateUpdate);
m_ballPosition[0] = 1000000;
m_ballPosition[1] = 1000000;
m_ballPosition[2] = 1000000;
m_button[0] = false;
m_button[1] = false;
m_button[2] = false;
}
void C3DEntityManipulator::compute()
{
if (m_button[0] && m_Analogs.size())
{
while (m_Analogs.size())
{
double value = m_Analogs.front() * 0.002;
m_ballSpeed[0] = 0;
m_ballSpeed[1] = 0;
m_ballSpeed[2] = value;
m_ballPosition[0] += m_ballSpeed[0];
m_ballPosition[1] += m_ballSpeed[1];
m_ballPosition[2] += m_ballSpeed[2];
m_Analogs.pop_front();
}
}
else
{
m_ballPosition[0] += m_ballSpeed[0];
m_ballPosition[1] += m_ballSpeed[1];
m_ballPosition[2] += m_ballSpeed[2];
}
const double viscosity = 0.010;
m_ballSpeed[0] *= (1 - viscosity);
m_ballSpeed[1] *= (1 - viscosity);
m_ballSpeed[2] *= (1 - viscosity);
Position far;
far[0] = 1000000;
far[1] = 1000000;
far[2] = 1000000;
sendValuedEvent((m_button[1] || m_button[2]) ? "OpenViBE_ball" : "OpenViBE_passive_ball", g_sManipulate3DEntity_SetPosition, PositionType(m_ballPosition));
sendValuedEvent((m_button[1] || m_button[2]) ? "OpenViBE_passive_ball" : "OpenViBE_ball", g_sManipulate3DEntity_SetPosition, PositionType(far));
Orientation orientation;
orientation[0] = 0;
orientation[1] = (m_ballPosition[2] * 180.0 / M_PI) / 0.5;
orientation[2] = 0;
sendValuedEvent("OpenViBE_passive_ball", g_sManipulate3DEntity_SetOrientation, OrientationType(orientation));
sendValuedEvent("OpenViBE_ball", g_sManipulate3DEntity_SetOrientation, OrientationType(orientation));
if (m_ballPosition[2] < -7 || m_ballPosition[2]>7)
{
sendEvent(getName(), g_s3DEntityManipulator_Reset);
sendEvent("OpenViBE_goal_display", g_sManipulate3DEntity_Goal);
}
}
bool C3DEntityManipulator::processEvent(OMK::Event* pEvent)
{
if (pEvent->eventId == g_s3DEntityManipulator_Reset)
{
m_ballPosition[0] = 0;
m_ballPosition[1] = 0.5;
m_ballPosition[2] = 0;
m_ballSpeed[0] = 0;
m_ballSpeed[1] = 0;
m_ballSpeed[2] = 0;
return true;
}
if (pEvent->eventId == g_sVrpnButtonStateUpdate)
{
VrpnButtonStateEvent* event = dynamic_cast <VrpnButtonStateEvent*>(pEvent);
if (event)
{
const VrpnButtonState& vrpnButtonState = event->value;
if (vrpnButtonState.first<int(sizeof(m_button) / sizeof(m_button[0])))
{
m_button[vrpnButtonState.first] = (vrpnButtonState.second ? true : false);
}
}
return true;
}
if (pEvent->eventId == g_sVrpnAnalogStateUpdate)
{
VrpnAnalogStateEvent* event = dynamic_cast <VrpnAnalogStateEvent*>(pEvent);
if (event)
{
const VrpnAnalogState& vrpnAnalogState = event->value;
m_AnalogsCache.push_back(vrpnAnalogState.front());
if (m_AnalogsCache.size() > 10) { m_AnalogsCache.pop_front(); }
if (m_button[0])
{
double analog = 0;
for (auto it = m_AnalogsCache.begin(); it != m_AnalogsCache.end(); ++it) { analog += *it; }
m_Analogs.push_back(analog / m_AnalogsCache.size());
}
}
return true;
}
return false;
}
@@ -0,0 +1,22 @@
#pragma once
#include "ova_defines.h"
class C3DEntityManipulator : public OMK::SimulatedObject
{
public:
DECLARE_OBJECT_FACTORY(C3DEntityManipulator);
virtual void init();
virtual void compute();
virtual bool processEvent(OMK::Event* pEvent);
bool m_button[3];
std::list<double> m_AnalogsCache;
std::list<double> m_Analogs;
Wm4::Vector3f m_ballPosition;
Wm4::Vector3f m_ballSpeed;
};
@@ -0,0 +1,204 @@
#include "ovaCManipulable3DEntity.h"
REGISTER_OBJECT_FACTORY(CManipulable3DEntity, "ovaCManipulable3DEntity");
CManipulable3DEntity::CManipulable3DEntity(OMK::Controller& controller, const OMK::ObjectDescriptor& objectDesc) : OMK::SimulatedObject(controller, objectDesc) { }
CManipulable3DEntity::~CManipulable3DEntity() { }
/*
,m_rPositionOutput(addOutput < OMK::Translation > ("position", new OMK::Polator < OMK::Translation > ()))
,m_rOrientationOutput(addOutput < OMK::HPRRotation > ("orientation", new OMK::Polator < OMK::HPRRotation > ()))
,m_rScaleOutput(addOutput < OMK::Scale > ("scale", new OMK::Polator < OMK::Scale > ()))
,m_isGoal(false)
{
visualiseOutput < OMK::vTranslationInputHandler >(m_rPositionOutput, "DCS_position") ;
visualiseOutput < OMK::vHPRRotationInputHandler >(m_rOrientationOutput, "DCS_orientation") ;
visualiseOutput < OMK::vScaleInputHandler >(m_rScaleOutput, "DCS_scale") ;
}
*/
void CManipulable3DEntity::init() { }
//void CManipulable3DEntity::init() { m_rTransformOutput.set(m_oTransform); }
#define duration 1250
#define fadein 500
#define fadeout 500
void CManipulable3DEntity::compute()
{
if (m_isGoal)
{
int delta = getSimulatedDate() - m_iGoalDate;
if (delta < duration)
{
if (delta < fadein)
{
double coef = (fadein - delta) / (double)fadein; // 1-0
double rotation = 180 * pow(coef, 3);
m_orientation[0] = 0;
m_orientation[1] = 3 * rotation;
m_orientation[2] = rotation * sin(M_PI * pow(coef, 3) * 1);
m_position[0] = 0;
m_position[1] = 5 + 7 * sin(coef * M_PI / 2);
m_position[2] = 0;
}
if (delta > duration - fadeout)
{
double coef = (delta - duration + fadeout) / double(fadeout); // 0-1
double rotation = 3 * 180 * pow(coef, 4);
m_orientation[0] = rotation;
m_orientation[1] = 3 * rotation * sin(M_PI * pow(coef, 3) * 2);
m_orientation[2] = 0;
m_position[0] = 0;
m_position[1] = 5 + 7 * coef * sin(coef * M_PI / 2);
m_position[2] = 0;
}
if (delta >= fadein && delta <= duration - fadeout)
{
m_orientation[0] = 0;
m_orientation[1] = 0;
m_orientation[2] = 0;
m_position[0] = 0;
m_position[1] = 5;
m_position[2] = 0;
}
}
}
/*
m_rTransformOutput.set(m_oTransform);
*/
}
bool CManipulable3DEntity::processEvent(OMK::Event* pEvent)
{
if (pEvent->eventId == g_sManipulate3DEntity_Goal)
{
m_isGoal = true;
m_iGoalDate = getSimulatedDate();
}
if (pEvent->eventId == g_sManipulate3DEntity_Reset)
{
m_position[0] = 0;
m_position[1] = 0.2;
m_position[2] = 0;
m_orientation[0] = 0;
m_orientation[1] = 0;
m_orientation[2] = 0;
#if defined _DEBUG_
std::cout << "### reseted\n";
#endif
return true;
}
if (pEvent->eventId == g_sManipulate3DEntity_Translate)
{
PositionEvent* event = dynamic_cast <PositionEvent*>(pEvent);
if (event)
{
const Position& value = event->value;
m_position[0] += value[0];
m_position[1] += value[1];
m_position[2] += value[2];
#if defined _DEBUG_
std::cout << "### translated\n";
#endif
return true;
}
}
if (pEvent->eventId == g_sManipulate3DEntity_SetPosition)
{
PositionEvent* event = dynamic_cast <PositionEvent*>(pEvent);
if (event)
{
const Position& value = event->value;
m_position[0] = value[0];
m_position[1] = value[1];
m_position[2] = value[2];
#if defined _DEBUG_
std::cout << "### moved\n";
#endif
return true;
}
}
if (pEvent->eventId == g_sManipulate3DEntity_Scale)
{
ScaleEvent* event = dynamic_cast <ScaleEvent*>(pEvent);
if (event)
{
const Scale& value = event->value;
m_oScale[0] *= value[0];
m_oScale[1] *= value[1];
m_oScale[2] *= value[2];
#if defined _DEBUG_
std::cout << "### scaled\n";
#endif
return true;
}
}
if (pEvent->eventId == g_sManipulate3DEntity_SetScale)
{
ScaleEvent* event = dynamic_cast <ScaleEvent*>(pEvent);
if (event)
{
const Scale& value = event->value;
m_oScale[0] = value[0];
m_oScale[1] = value[1];
m_oScale[2] = value[2];
#if defined _DEBUG_
std::cout << "### scaled fixed\n";
#endif
return true;
}
}
if (pEvent->eventId == g_sManipulate3DEntity_Rotate)
{
OrientationEvent* event = dynamic_cast <OrientationEvent*>(pEvent);
if (event)
{
const Orientation& value = event->value;
m_orientation[0] += value[0];
m_orientation[1] += value[1];
m_orientation[2] += value[2];
#if defined _DEBUG_
std::cout << "### rotated\n";
#endif
return true;
}
}
if (pEvent->eventId == g_sManipulate3DEntity_SetOrientation)
{
OrientationEvent* event = dynamic_cast <OrientationEvent*>(pEvent);
if (event)
{
const Orientation& value = event->value;
m_orientation[0] = value[0];
m_orientation[1] = value[1];
m_orientation[2] = value[2];
#if defined _DEBUG_
std::cout << "### orirentation set\n";
#endif
return true;
}
}
return false;
}
@@ -0,0 +1,27 @@
#pragma once
#include "ova_defines.h"
class CManipulable3DEntity : public OMK::SimulatedObject
{
public:
DECLARE_OBJECT_FACTORY(CManipulable3DEntity);
virtual void init();
virtual void compute();
virtual bool processEvent(OMK::Event* pEvent);
Position m_position;
Orientation m_orientation;
Scale m_oScale;
/*
OMK::Output < OMK::Type::Transform >& m_rTransformOutput;
*/
bool m_isGoal = false;
int m_iGoalDat = 0;
};
@@ -0,0 +1,152 @@
#include "ovaCNeurofeedbackManipulator.h"
#include <OMKMultipleConfigurationParameter.h>
#include <OMKUniqueConfigurationParameter.h>
REGISTER_OBJECT_FACTORY(CNeurofeedbackManipulator, "ovaCNeurofeedbackManipulator");
CNeurofeedbackManipulator::CNeurofeedbackManipulator(OMK::Controller& controller, const OMK::ObjectDescriptor& objectDesc) :OMK::SimulatedObject(controller, objectDesc) { }
CNeurofeedbackManipulator::~CNeurofeedbackManipulator() { }
void CNeurofeedbackManipulator::init()
{
static OMK::Name g_sVrpnAnalogStateUpdate("vrpn_analog state update");
_AnalogRotation_ = 0.25;
_AnalogScale_ = 0.004;
_AnalogSoften_ = 1;
_AnalogFall_ = .99;
m_dLowestAnalogEver = 1E10;
m_dHighestAnalogEver = -1E10;
m_iLastPrint = -1;
registerForSignal(g_sVrpnAnalogStateUpdate);
OMK::ParametersAccessor::get < double >(getConfigurationParameters(), "_AnalogRotation_", _AnalogRotation_);
OMK::ParametersAccessor::get < double >(getConfigurationParameters(), "_AnalogScale_", _AnalogScale_);
OMK::ParametersAccessor::get < double >(getConfigurationParameters(), "_AnalogSoften_", _AnalogSoften_);
OMK::ParametersAccessor::get < double >(getConfigurationParameters(), "_AnalogFall_", _AnalogFall_);
m_bFirstTime = true;
m_position[0] = 4;
m_position[1] = 0;
m_position[2] = -3;
m_orientation[0] = 0;
m_orientation[1] = 0;
m_orientation[2] = 0;
m_dTotal = 0;
m_dCount = 0;
}
void CNeurofeedbackManipulator::compute()
{
auto itAnalog = m_Analogs.begin();
auto itAnalogName = m_vAnalogName.begin();
for (; itAnalog != m_Analogs.end(); ++itAnalog, ++itAnalogName)
{
double analog = (*itAnalog);
m_dTotal += analog;
m_dCount += 1.;
if (analog > m_dHighestAnalogEver) m_dHighestAnalogEver = analog;
if (analog < m_dLowestAnalogEver) m_dLowestAnalogEver = analog;
if (m_iLastPrint != getSimulatedDate() / 1000)
{
m_iLastPrint = getSimulatedDate() / 1000;
#if _DEBUG_
std::cout << "Current session : mean/min/max = "
<< (m_dTotal / m_dCount) << "/"
<< m_dLowestAnalogEver << "/"
<< m_dHighestAnalogEver << "/"
<< "\n";
std::cout << "\n";
#endif
m_dTotal = 0;
m_dCount = 0;
m_dLowestAnalogEver = 1E10;
m_dHighestAnalogEver = -1E10;
}
if (analog <= 0)
{
m_orientation[0] *= _AnalogFall_;
m_orientation[1] *= _AnalogFall_;
m_orientation[2] *= _AnalogFall_;
m_position[1] *= _AnalogFall_;
}
else
{
m_orientation[0] += _AnalogRotation_ * ((rand() & 1) == 0 ? -1 : 1);
m_orientation[1] += _AnalogRotation_ * ((rand() & 1) == 0 ? -1 : 1);
m_orientation[2] += _AnalogRotation_ * ((rand() & 1) == 0 ? -1 : 1);
m_position[1] += analog * _AnalogScale_;
if (m_position[1] > 6) { m_position[1] = 6; }
}
if (m_orientation[0] > 5) m_orientation[0] = 5;
if (m_orientation[1] > 5) m_orientation[1] = 5;
if (m_orientation[2] > 5) m_orientation[2] = 5;
if (m_orientation[0] < -5) m_orientation[0] = -5;
if (m_orientation[1] < -5) m_orientation[1] = -5;
if (m_orientation[2] < -5) m_orientation[2] = -5;
sendValuedEvent(*itAnalogName, g_sManipulate3DEntity_SetOrientation, OrientationType(m_orientation));
sendValuedEvent(*itAnalogName, g_sManipulate3DEntity_SetPosition, PositionType(m_position));
}
}
bool CNeurofeedbackManipulator::processEvent(OMK::Event* pEvent)
{
if (pEvent->eventId == g_sVrpnAnalogStateUpdate)
{
VrpnAnalogStateEvent* event = dynamic_cast <VrpnAnalogStateEvent*>(pEvent);
if (event)
{
VrpnAnalogState analogs = event->value;
if (m_bFirstTime)
{
// create objects
size_t i = 0;
for (auto it1 = analogs.begin(); it1 != analogs.end(); ++it1)
{
const char* name = ("nf object " + std::to_string(i++)).c_str();
m_vAnalogName.push_back(name);
// OpenMASK won't let me delete those configuration parameters,
// However, way to go :o)
OMK::MultipleConfigurationParameter* userParams = new OMK::MultipleConfigurationParameter();
userParams->appendSubDescriptorNamed("geometryFileName", new OMK::UniqueConfigurationParameter("./Data/neurofeedback.wrl"));
getController().createObject(OMK::ObjectDescriptor(name, "ovManipulable3DEntity", getController().computeAdequateFrequency(75), userParams), getFathersDescriptor().getName());
m_Analogs.push_back(0);
}
m_bFirstTime = false;
}
std::cout << "got data\n";
for (auto it1 = analogs.begin(), it2 = m_Analogs.begin(); it1 != analogs.end() && it2 != m_Analogs.end(); ++it1, ++it2)
{
*it2 = *it1 * _AnalogSoften_ + *it2 * (1 - _AnalogSoften_);
}
return true;
}
}
return false;
}
@@ -0,0 +1,32 @@
#pragma once
#include "ova_defines.h"
class CNeurofeedbackManipulator : public OMK::SimulatedObject
{
public:
DECLARE_OBJECT_FACTORY(CNeurofeedbackManipulator);
virtual void init();
virtual void compute();
virtual bool processEvent(OMK::Event* pEvent);
Position m_position;
Orientation m_orientation;
VrpnAnalogState m_Analogs;
std::list < OMK::Name > m_vAnalogName;
bool m_bFirstTime = false;
double m_dLowestAnalogEver = 0;
double m_dHighestAnalogEver = 0;
double m_dTotal = 0;
double m_dCount = 0;
int m_iLastPrint = 0;
double _AnalogRotation_ = 0;
double _AnalogScale_ = 0;
double _AnalogSoften_ = 0;
double _AnalogFall_ = 0;
};
@@ -0,0 +1,109 @@
#include "ovaCNeurofeedbackScoreCounter.h"
REGISTER_OBJECT_FACTORY(CNeurofeedbackScoreCounter, "ovaCNeurofeedbackScoreCounter");
CNeurofeedbackScoreCounter::CNeurofeedbackScoreCounter(OMK::Controller& controller, const OMK::ObjectDescriptor& objectDesc)
:OMK::SimulatedObject(controller, objectDesc)
{
}
CNeurofeedbackScoreCounter::~CNeurofeedbackScoreCounter()
{
}
void CNeurofeedbackScoreCounter::init()
{
registerForSignal(g_sVrpnButtonStateUpdate);
registerForSignal(g_sVrpnAnalogStateUpdate);
m_shouldCare = false;
m_wasZero = false;
m_score = 0;
m_oScale[0] = 1;
m_oScale[1] = 1;
m_oScale[2] = 1;
m_oScaleTarget[0] = 1;
m_oScaleTarget[1] = 1;
m_oScaleTarget[2] = 1;
sendValuedEvent("OpenViBE_score_counter", g_sManipulate3DEntity_SetScale, ScaleType(m_oScale));
}
void CNeurofeedbackScoreCounter::compute()
{
double speed = .01;
m_oScale = (float)speed * m_oScaleTarget + float(1 - speed) * m_oScale;
sendValuedEvent("OpenViBE_score_counter", g_sManipulate3DEntity_SetScale, ScaleType(m_oScale));
}
bool CNeurofeedbackScoreCounter::processEvent(OMK::Event* pEvent)
{
if (pEvent->eventId == g_sVrpnButtonStateUpdate)
{
VrpnButtonStateEvent* event = dynamic_cast <VrpnButtonStateEvent*>(pEvent);
if (event)
{
const VrpnButtonState& vrpnButtonState = event->value;
if (vrpnButtonState.first<int(sizeof(m_button) / sizeof(m_button[0])))
{
m_button[vrpnButtonState.first] = (vrpnButtonState.second ? true : false);
if (vrpnButtonState.first == 3)
{
if (m_button[vrpnButtonState.first])
{
m_shouldCare = true;
#ifdef _DEBUG_
std::cout << "Should care\n";
#endif
}
else
{
m_shouldCare = false;
#ifdef _DEBUG_
std::cout << "Should not care\n";
#endif
}
}
}
}
return true;
}
if (pEvent->eventId == g_sVrpnAnalogStateUpdate)
{
VrpnAnalogStateEvent* event = dynamic_cast <VrpnAnalogStateEvent*>(pEvent);
if (event)
{
const VrpnAnalogState& vrpnAnalogState = event->value;
auto it = vrpnAnalogState.begin();
if (m_wasZero)
{
if (*it >= 1E-3)
{
if (m_shouldCare)
{
m_oScaleTarget[1] += .2;
m_score += 1;
m_shouldCare = false;
std::cout << "NeW SCoRe : " << m_score << "\n";
}
m_wasZero = false;
}
}
else
{
if (*it < 1E-3)
{
m_wasZero = true;
}
}
}
}
return false;
}
@@ -0,0 +1,25 @@
#pragma once
#include "ova_defines.h"
#include <OMKTransform.h>
class CNeurofeedbackScoreCounter : public OMK::SimulatedObject
{
public:
DECLARE_OBJECT_FACTORY(CNeurofeedbackScoreCounter);
virtual void init();
virtual void compute();
virtual bool processEvent(OMK::Event* pEvent);
Scale m_oScale;
Scale m_oScaleTarget;
bool m_button[1024];
bool m_shouldCare = false;
bool m_wasZero = false;
size_t m_score = 0;
};
@@ -0,0 +1,57 @@
#include "ovaCNeurofeedbackSwitch.h"
REGISTER_OBJECT_FACTORY(CNeurofeedbackSwitch, "ovaCNeurofeedbackSwitch");
CNeurofeedbackSwitch::CNeurofeedbackSwitch(OMK::Controller& controller, const OMK::ObjectDescriptor& objectDesc)
:OMK::SimulatedObject(controller, objectDesc)
{
}
CNeurofeedbackSwitch::~CNeurofeedbackSwitch()
{
}
void CNeurofeedbackSwitch::init()
{
_FarAway_[0] = 1000;
_FarAway_[1] = 1000;
_FarAway_[2] = 1000;
_Position_[0] = 0;
_Position_[1] = 0;
_Position_[2] = 0;
sendValuedEvent("OpenViBE_ball", g_sManipulate3DEntity_SetPosition, PositionType(_FarAway_));
sendValuedEvent("OpenViBE_passive_ball", g_sManipulate3DEntity_SetPosition, PositionType(_FarAway_));
registerForSignal(g_sVrpnButtonStateUpdate);
}
void CNeurofeedbackSwitch::compute()
{
}
bool CNeurofeedbackSwitch::processEvent(OMK::Event* pEvent)
{
if (pEvent->eventId == g_sVrpnButtonStateUpdate)
{
VrpnButtonStateEvent* event = dynamic_cast <VrpnButtonStateEvent*>(pEvent);
if (event)
{
const VrpnButtonState& vrpnButtonState = event->value;
if (vrpnButtonState.first<int(sizeof(m_button) / sizeof(m_button[0])))
{
m_button[vrpnButtonState.first] = (vrpnButtonState.second ? true : false);
#if _DEBUG_
std::cout << "got event " << *event << std::endl;
#endif
sendValuedEvent("OpenViBE_ball", g_sManipulate3DEntity_SetPosition, PositionType(m_button[2] ? _Position_ : _FarAway_));
sendValuedEvent("OpenViBE_passive_ball", g_sManipulate3DEntity_SetPosition, PositionType(m_button[3] ? _Position_ : _FarAway_));
}
}
return true;
}
return false;
}
@@ -0,0 +1,23 @@
#pragma once
#include "ova_defines.h"
#include <OMKOutput.h>
#include <OMKTransform.h>
class CNeurofeedbackSwitch : public OMK::SimulatedObject
{
public:
DECLARE_OBJECT_FACTORY(CNeurofeedbackSwitch);
virtual void init();
virtual void compute();
virtual bool processEvent(OMK::Event* pEvent);
bool m_button[1024];
Position _Position_;
Position _FarAway_;
};