Skip to content

Commit

Permalink
new trajectory and rework on existing trajectories
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Apr 4, 2019
1 parent 0ec152b commit 4385e4d
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 47 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ add_executable(Frontieres WIN32
sources/visual/CloudVis.cpp
sources/visual/SampleVis.cpp
sources/visual/Trajectory.cpp
sources/visual/Bouncing.cpp
sources/visual/Bouncing.cpp
sources/visual/Circular.cpp
sources/utility/GTime.cpp
libraries/QtFont3D/QtFont3D.cpp
libraries/Stk.cpp
Expand Down
2 changes: 2 additions & 0 deletions Frontieres.pro
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ SOURCES += \
sources/visual/CloudVis.cpp \
sources/visual/Trajectory.cpp \
sources/visual/Bouncing.cpp \
sources/visual/Circular.cpp \
sources/utility/GTime.cpp \
libraries/Stk.cpp \
libraries/RtAudio.cpp \
Expand Down Expand Up @@ -112,6 +113,7 @@ HEADERS += \
sources/visual/CloudVis.h \
sources/visual/Trajectory.h \
sources/visual/Bouncing.h \
sources/visual/Circular.h \
sources/utility/GTime.h \
libraries/RtMidi.h \
libraries/RtAudio.h \
Expand Down
4 changes: 2 additions & 2 deletions sources/Frontieres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@ void mouseDrag(int x, int y)
Scene *scene = ::currentScene;
SceneSample *selectedSample = scene->selectedSample();
SceneCloud *selectedCloud = scene->selectedCloud();

if (selectedCloud) {
if (selectedCloud)
{
selectedCloud->view->updateCloudPosition(mouseX, mouseY);
}
else {
Expand Down
33 changes: 28 additions & 5 deletions sources/interface/MyGLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,23 @@ void MyGLScreen::keyAction_Cloud(int dir)



void MyGLScreen::keyAction_Trajectory()
void MyGLScreen::keyAction_Trajectory(int dir)
{
Scene *scene = ::currentScene;
SceneCloud *selectedCloud = scene->selectedCloud();
Bouncing *tr=new Bouncing(5,1);


Trajectory *tr=nullptr;
paramString = "";
if (selectedCloud) {

selectedCloud->cloud->setTrajectory(tr);
if (dir < 0) {
selectedCloud->view->stopTrajectory();
}
else {
//tr=new Bouncing(100,0.1,selectedCloud->view->getX(),selectedCloud->view->getY());
tr=new Circular(0.5,selectedCloud->view->getX(),selectedCloud->view->getY(),50);
selectedCloud->view->setTrajectory(tr);
}


}
Expand Down Expand Up @@ -741,6 +749,13 @@ void MyGLScreen::mouseMoveEvent(QMouseEvent *event)
int xDiff = 0;
int yDiff = 0;

//origin of trajectory
std::vector<double> origin {0.,0.};
double posCloudX=0.;
double posCloudY=0.;

//std::cout<<"mouse moved"<<std::endl;

Scene *scene = ::currentScene;
SceneSample *selectedSample = scene->selectedSample();
SceneCloud *selectedCloud = scene->selectedCloud();
Expand All @@ -749,7 +764,15 @@ void MyGLScreen::mouseMoveEvent(QMouseEvent *event)
if (selectedCloud->cloud->getLockedState())
if (selectedCloud->cloud->dialogLocked())
return;
posCloudX=selectedCloud->view->getX();
posCloudY=selectedCloud->view->getY();
selectedCloud->view->updateCloudPosition(mouseX, mouseY);
if(selectedCloud->view->getIsMoving())
{
origin=selectedCloud->view->getTrajectory()->getOrigin();
selectedCloud->view->getTrajectory()->updateOrigin(origin[0]-posCloudX+mouseX,origin[1]-posCloudY+mouseY);
}

}
else {

Expand Down Expand Up @@ -1027,7 +1050,7 @@ void MyGLScreen::keyPressEvent(QKeyEvent *event)
break;

case Qt::Key_I: {
keyAction_Trajectory();
keyAction_Trajectory((modkey == Qt::ShiftModifier) ? -1 : +1);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion sources/interface/MyGLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public slots:
void keyAction_LfoFreq(int dir = +1);
void keyAction_LfoAmount(int dir = +1);
void keyAction_Pitch(int dir = +1);
void keyAction_Trajectory(int dir=+1);
void keyAction_Active();
void keyAction_EditEnvelope();
void keyAction_EditCloud();
void keyAction_SampleNames();
void keyAction_Trajectory();

protected:
void initializeGL() override;
Expand Down
16 changes: 1 addition & 15 deletions sources/model/Cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ Cloud::Cloud(VecSceneSample *sampleSet, float theNumGrains)
addFlag = false;
removeFlag = false;

//initialise without moves
isMoving=false;
myTrajectory=nullptr;

// keep pointer to the sample set
theSamples = sampleSet;
Expand Down Expand Up @@ -209,15 +206,7 @@ void Cloud::registerCloudVis(CloudVis *cloudVisToRegister)
myCloudVis->setDuration(duration);
}

Trajectory* Cloud::getTrajectory()
{
return this->myTrajectory;
}

bool Cloud::getIsMoving()
{
return isMoving;
}

// turn on/off
void Cloud::toggleActive()
Expand Down Expand Up @@ -849,10 +838,7 @@ void Cloud::showMessageLocked()
cout << "cloud locked, no change" << endl;
}

void Cloud::setTrajectory(Trajectory *tr){
isMoving=true;
myTrajectory=tr;
}


// print information
void Cloud::describe(std::ostream &out)
Expand Down
3 changes: 0 additions & 3 deletions sources/model/Cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ class Cloud {
QString myName;

bool isActive; // on/off state
bool isMoving;
bool awaitingPlay; // triggered but not ready to play?
bool addFlag, removeFlag; // add/remove requests submitted?
unsigned long local_time; // internal clock
Expand Down Expand Up @@ -312,8 +311,6 @@ class Cloud {
// lock switch
bool locked = false;

// trajectory of the cloud
Trajectory *myTrajectory;

// midi polyphony
CloudMidi *playedCloudMidi[g_maxMidiVoices];
Expand Down
17 changes: 11 additions & 6 deletions sources/visual/Bouncing.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "visual/Bouncing.h"


Bouncing::Bouncing(double bw, double s)
: Trajectory(s)
Bouncing::Bouncing(double bw, double s,double x, double y)
: Trajectory(s,x,y)
{
this->bounceWidth = bw;
}
Expand All @@ -16,12 +16,17 @@ double Bouncing::getBounceWidth()
return this->bounceWidth;
}

std::vector<double> Bouncing::computeTrajectory(double t, double initX, double initY)
std::vector<double> Bouncing::computeTrajectory(double dt)
{
std::vector<double> vecPos{0., 0.};
double sp = this->getSpeed();
vecPos[0] = this->bounceWidth * cos(sp * t) + initX;
vecPos[1] = initY;
double ph=this->getPhase();
const double PI =3.141592653589793238463;
//define the phase modulo the period of the trajectory to avoid having phase going to infinity
setPhase(fmod(getPhase()+dt,1./sp));
std::vector<double> orig=getOrigin();
std::vector<double> vecPos{0., 0.};
vecPos[0] = this->bounceWidth * sin(sp*ph*2*PI) + orig[0];
vecPos[1] = orig[1];
return vecPos;
}

Expand Down
6 changes: 3 additions & 3 deletions sources/visual/Bouncing.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include "theglobals.h"
#include "Trajectory.h"

// abstract class as a base for every kind of trajectory

class Bouncing : public Trajectory {
public:
Bouncing(double bw, double s);
Bouncing(double bw, double s,double xOr,double yOr);
void setBounceWidth(double bw);
double getBounceWidth();
std::vector<double> computeTrajectory(double t, double initX, double initY);
std::vector<double> computeTrajectory(double dt);
~Bouncing();

private:
Expand Down
43 changes: 43 additions & 0 deletions sources/visual/Circular.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "visual/Circular.h"


Circular::Circular(double s,double xOr, double yOr,double xc,double yc)
: Trajectory(s,xOr,yOr)
{
this->centerX = xc;
this->centerY = yc;
std::vector<double> orig=getOrigin();
this->radius=sqrt((orig[0]-centerX)*(orig[0]-centerX)+(orig[1]-centerY)*(orig[1]-centerY));
}

Circular::Circular(double s,double xOr, double yOr,double r)
: Trajectory(s,xOr,yOr)
{
std::vector<double> orig=getOrigin();
this->centerX = orig[0];
this->centerY = orig[1];
this->radius=r;
}




std::vector<double> Circular::computeTrajectory(double dt)
{
double sp = this->getSpeed();
double ph=this->getPhase();
const double PI =3.141592653589793238463;
//define the phase modulo the period of the trajectory to avoid having phase going to infinity
setPhase(fmod(getPhase()+dt,1./sp));
std::vector<double> orig=getOrigin();
std::vector<double> vecPos{0., 0.};

//we compute the euclidean distance between center of the circle and origin of trajectory
vecPos[0] = radius*cos(sp*ph*2*PI)+orig[0];
vecPos[1] = radius*sin(sp*ph*2*PI)+orig[1];
return vecPos;
}

Circular::~Circular()
{
}
26 changes: 26 additions & 0 deletions sources/visual/Circular.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef CIRCULAR_H
#define CIRCULAR_H

#include <vector>
#include <memory>
#include <iostream>
#include "theglobals.h"
#include "Trajectory.h"


class Circular : public Trajectory {
public:
Circular(double s,double xOr, double yOr,double xc,double yc);
Circular(double s,double xOr, double yOr,double r);
double getCenter();
void setCenter(double x,double y);
std::vector<double> computeTrajectory(double dt);
~Circular();

private:
double centerX;
double centerY;
double radius;
};

#endif
46 changes: 40 additions & 6 deletions sources/visual/CloudVis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ CloudVis::~CloudVis()
{
for (GrainVis *vis : myGrainsV)
delete vis;
delete myTrajectory;
}

CloudVis::CloudVis(float x, float y, unsigned int numGrainsVis,
Expand Down Expand Up @@ -95,6 +96,12 @@ CloudVis::CloudVis(float x, float y, unsigned int numGrainsVis,
lambda = 0.997;
selRad = minSelRad;
targetRad = maxSelRad;
lastDrawTime=0;

//initialise without moves
isMoving=false;
myTrajectory=nullptr;

}


Expand Down Expand Up @@ -136,23 +143,50 @@ float CloudVis::getY()
return gcY;
}

Trajectory* CloudVis::getTrajectory()
{
return this->myTrajectory;
}

bool CloudVis::getIsMoving()
{
return isMoving;
}

void CloudVis::setTrajectory(Trajectory *tr)
{
isMoving=true;
myTrajectory=tr;
}

void CloudVis::stopTrajectory()
{
if(myTrajectory !=nullptr)
{
delete myTrajectory;
isMoving=false;
}
}


void CloudVis::draw()
{
double t_sec = GTime::instance().sec - startTime;
double t_sec = 0;
double dt=0;

t_sec = GTime::instance().sec - startTime;
dt=t_sec-lastDrawTime;
lastDrawTime=t_sec;
//std::cout << "time between drawings: " <<dt<<std::endl;
// cout << t_sec << endl;

//computing trajectory
std::vector<double> pos = {0.,0.};
if (this->myCloud->getIsMoving() && !this->isSelected){
pos=this->myCloud->getTrajectory()->computeTrajectory(t_sec,this->gcX,this->gcY);
if (this->getIsMoving() && !this->isSelected){
pos=this->myTrajectory->computeTrajectory(dt);
updateCloudPosition(pos[0],pos[1] );
}




// if ((g_time -last_gtime) > 50){
glPushMatrix();
glTranslatef((GLfloat)gcX, (GLfloat)gcY, 0.0);
Expand Down

0 comments on commit 4385e4d

Please sign in to comment.