Skip to content
Permalink
Browse files
some improvements I can't remembe
  • Loading branch information
Daniel Bisig committed Apr 24, 2022
1 parent c06562c commit b465c61eb3237b3a27c9b14afe5379662fc1f2fa
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 6 deletions.
@@ -239,6 +239,8 @@ OscControl::notify(std::shared_ptr<OscMessage> pMessage)
std::vector< std::shared_ptr<_OscArg> > groupedOscArgs;
groupOscArgs(pMessage, groupedOscArgs);

//std::cout << "oscCommand " << oscCommand << "\n";

if(oscCommand == "/ClearSimulation") clearSimulation();
else if(oscCommand == "/RestoreSimulation") restoreSimulation(groupedOscArgs);
else if(oscCommand == "/SaveSimulation") saveSimulation(groupedOscArgs);
@@ -248,10 +250,15 @@ OscControl::notify(std::shared_ptr<OscMessage> pMessage)
else if(oscCommand == "/AddAgents") addAgents(groupedOscArgs);
else if(oscCommand == "/RemoveAgents") removeAgents(groupedOscArgs);
else if(oscCommand == "/SetParameter") setParameter(groupedOscArgs);
else if (oscCommand == "/AssignNeighbors") assignNeighbors(groupedOscArgs);
else if(oscCommand == "/ShowSwarm") showSwarm(groupedOscArgs);
else if(oscCommand == "/HideSwarm") hideSwarm(groupedOscArgs);
else if(oscCommand == "/ShowSpace") showSpace(groupedOscArgs);
else if(oscCommand == "/HideSpace") hideSpace(groupedOscArgs);
else if (oscCommand == "/DisplayPosition") setDisplayPosition(groupedOscArgs);
else if (oscCommand == "/DisplayOrientation") setDisplayOrientation(groupedOscArgs);
else if (oscCommand == "/DisplayOrientationChange") changeDisplayOrientation(groupedOscArgs);
else if (oscCommand == "/DisplayZoom") setDisplayZoom(groupedOscArgs);
else if(oscCommand == "/AgentColor") setAgentColor(groupedOscArgs);
else if(oscCommand == "/AgentScale") setAgentScale(groupedOscArgs);
else if(oscCommand == "/AgentLineWidth") setAgentLineWidth(groupedOscArgs);
@@ -646,6 +653,34 @@ OscControl::setParameter(const std::vector< std::shared_ptr<_OscArg> >& pParamet
}
}

void
OscControl::assignNeighbors(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception)
{
// TODO: create an assign neighbor event for this
// TODO: this is marginal implementatiom only for changing the visibility of one parameter in one space only

try
{
if (pParameters.size() == 5 && pParameters[0]->oscType() == OSC_TYPE_STRING && pParameters[1]->oscType() == OSC_TYPE_INT32 && pParameters[2]->oscType() == OSC_TYPE_STRING && pParameters[3]->oscType() == OSC_TYPE_STRING && pParameters[4]->oscType() == OSC_TYPE_INT32)
{
// swarm name / agent_index / parameter name / space name/ visible
std::string swarmName = pParameters[0]->operator const std::string&();
int agentIndex = *(pParameters[1]);
std::string parameterName = pParameters[2]->operator const std::string&();
std::string spaceName = pParameters[3]->operator const std::string&();
int visible = *(pParameters[4]);

// TODO: create an assign neighbor event for this
Simulation::get().swarm(swarmName)->agent(agentIndex)->assignNeighbors(parameterName, spaceName, static_cast<bool>(visible));
}
else throw Exception("FLOCK ERROR: Wrong Parameters for /AssignNeighbors", __FILE__, __FUNCTION__, __LINE__);
}
catch (Exception& e)
{
throw;
}
}

void
OscControl::showSwarm(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception)
{
@@ -767,6 +802,94 @@ OscControl::hideSpace(const std::vector< std::shared_ptr<_OscArg> >& pParameters
}
}

void
OscControl::setDisplayPosition(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception)
{
try
{
if (pParameters.size() == 1 && pParameters[0]->oscType() == EXT_TYPE_ARG_FLOAT_ARRAY)
{
int posDim = pParameters[0]->valueCount();
float* posValues = *(pParameters[0]);
if (posDim != 3) throw Exception("FLOCK ERROR: Wrong Parameters for /DisplayPosition", __FILE__, __FUNCTION__, __LINE__);

ofVec3f pos(posValues[0], posValues[1], posValues[2]);

FlockVisuals::get().setDisplayPosition(pos);
}
else throw Exception("FLOCK ERROR: Wrong Parameters for /DisplayPosition", __FILE__, __FUNCTION__, __LINE__);
}
catch (Exception& e)
{
throw;
}
}

void
OscControl::setDisplayOrientation(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception)
{
try
{
if (pParameters.size() == 1 && pParameters[0]->oscType() == EXT_TYPE_ARG_FLOAT_ARRAY)
{
int orientDim = pParameters[0]->valueCount();
float* orientValues = *(pParameters[0]);
if (orientDim != 4) throw Exception("FLOCK ERROR: Wrong Parameters for /DisplayOrientation", __FILE__, __FUNCTION__, __LINE__);

ofQuaternion orient(orientValues[0], orientValues[1], orientValues[2], orientValues[3]);

FlockVisuals::get().setDisplayOrientation(orient);
}
else throw Exception("FLOCK ERROR: Wrong Parameters for /DisplayOrientation", __FILE__, __FUNCTION__, __LINE__);
}
catch (Exception& e)
{
throw;
}
}

void
OscControl::changeDisplayOrientation(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception)
{
try
{
if (pParameters.size() == 1 && pParameters[0]->oscType() == EXT_TYPE_ARG_FLOAT_ARRAY)
{
int orientDim = pParameters[0]->valueCount();
float* orientValues = *(pParameters[0]);
if (orientDim != 4) throw Exception("FLOCK ERROR: Wrong Parameters for /DisplayOrientationChange", __FILE__, __FUNCTION__, __LINE__);

ofQuaternion orient(orientValues[0], orientValues[1], orientValues[2], orientValues[3]);

FlockVisuals::get().setDisplayOrientationChange(orient);
}
else throw Exception("FLOCK ERROR: Wrong Parameters for /DisplayOrientationChange", __FILE__, __FUNCTION__, __LINE__);
}
catch (Exception& e)
{
throw;
}
}

void
OscControl::setDisplayZoom(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception)
{
try
{
if (pParameters.size() == 1 && pParameters[0]->oscType() == OSC_TYPE_FLOAT)
{
float zoom = *(pParameters[0]);

FlockVisuals::get().setDisplayZoom(zoom);
}
else throw Exception("FLOCK ERROR: Wrong Parameters for /DisplayZoom", __FILE__, __FUNCTION__, __LINE__);
}
catch (Exception& e)
{
throw;
}
}

void
OscControl::setAgentColor(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception)
{
@@ -78,7 +78,7 @@ protected:
void setParameter(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
// void randomizeParameter(std::vector<_OscArg*>& pParameters()) throw (Exception);
// void removeParameter(std::vector<_OscArg*>& pParameters()) throw (Exception);
// void assignNeighbors(std::vector<_OscArg*>& pParameters()) throw (Exception);
void assignNeighbors(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
// void removeNeigbors(std::vector<_OscArg*>& pParameters()) throw (Exception);
// void registerParameter(std::vector<_OscArg*>& pParameters()) throw (Exception);
// void deregisterParameter(std::vector<_OscArg*>& pParameters()) throw (Exception);
@@ -90,10 +90,10 @@ protected:
void showSpace(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
void hideSpace(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
// void setDisplayColor(std::vector<_OscArg*>& pParameters()) throw (Exception);
// void setDisplayPosition(std::vector<_OscArg*>& pParameters()) throw (Exception);
// void setDisplayOrientation(std::vector<_OscArg*>& pParameters()) throw (Exception);
// void changeDisplayOrientation(std::vector<_OscArg*>& pParameters()) throw (Exception);
// void setDisplayZoom(std::vector<_OscArg*>& pParameters()) throw (Exception);
void setDisplayPosition(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
void setDisplayOrientation(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
void changeDisplayOrientation(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
void setDisplayZoom(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
// void setWindowSettings(std::vector<_OscArg*>& pParameters()) throw (Exception);
// virtual void toggleFullScreen( ) throw (Exception);
void setAgentColor(const std::vector< std::shared_ptr<_OscArg> >& pParameters) throw (Exception);
@@ -140,6 +140,14 @@ Swarm::agentCount() const
return mAgents.size();
}

Agent*
Swarm::agent(unsigned int pAgentIndex) throw (Exception)
{
if (pAgentIndex >= mAgents.size()) throw Exception("FLOCK ERROR: agent index " + std::to_string(pAgentIndex) + " exceeds numbers of agents " + std::to_string(mAgents.size()), __FILE__, __FUNCTION__, __LINE__);

return mAgents[pAgentIndex];
}

std::vector<Agent*>&
Swarm::agents()
{
@@ -76,6 +76,14 @@ public:
\return number of agents
*/
unsigned int agentCount() const;

/**
\brief return agent
\param pAgentCount number of agents to add
\return agent
\exception Exception failed to return agent
*/
Agent* agent(unsigned int pAgentIndex) throw (Exception);

/**
\brief return agents
@@ -159,12 +159,16 @@ void
FlockVisuals::setDisplayPosition(const ofVec3f& pPosition)
{
mViewPos = pPosition;

//std::cout << "setDisplayPosition " << mViewPos[0] << " " << mViewPos[1] << " " << mViewPos[2] << "\n";
}

void
FlockVisuals::setDisplayOrientation(const ofQuaternion& pOrientation)
{
mRotQuat = pOrientation;

//std::cout << "setDisplayOrientation " << mRotQuat[0] << " " << mRotQuat[1] << " " << mRotQuat[2] << " " << mRotQuat[3] << "\n";
}

void
@@ -177,6 +181,8 @@ void
FlockVisuals::setDisplayZoom(float pZoom)
{
mZoomVal = pZoom;

//std::cout << "setDisplayZoom " << mZoomVal << "\n";
}

void
@@ -310,6 +310,8 @@ VisSwarm::update()
void
VisSwarm::displayAgents(const ofShader &pShader)
{
//std::cout << "displayAgents swarm " << mSwarmName << " pos " << mPosParName << " vel " << mVelParName << "\n";

// display agent shapes
glLineWidth(mAgentShape->lineWidth());
int agentCount = mAgentPositions.size();
@@ -322,7 +324,7 @@ VisSwarm::displayAgents(const ofShader &pShader)
mAgentShape->setOrientation(agentVel);
mAgentShape->display(pShader);

//std::cout << "display Agent " << aI << " pos " << agentPos << "\n";
//if(mSwarmName == "mocap_swarm" && aI == 35) std::cout << "display Agent " << aI << " pos " << agentPos << "\n";
}
}

0 comments on commit b465c61

Please sign in to comment.