summaryrefslogtreecommitdiff
path: root/06_performance/src/oni.cpp
diff options
context:
space:
mode:
Diffstat (limited to '06_performance/src/oni.cpp')
-rw-r--r--06_performance/src/oni.cpp90
1 files changed, 62 insertions, 28 deletions
diff --git a/06_performance/src/oni.cpp b/06_performance/src/oni.cpp
index 346adec..20b67bb 100644
--- a/06_performance/src/oni.cpp
+++ b/06_performance/src/oni.cpp
@@ -31,6 +31,8 @@ void syncOniPlayer::play(){
};
//sleep(2);
drawable=true;
+ startTime=ofGetElapsedTimef();
+ playerActive=true;
}
}
void syncOniPlayer::update(){
@@ -48,6 +50,10 @@ int syncOniPlayer::getCurrentFrame(){
if (players.size()) return players[0]->getCurrentFrame();
else return -1;
}
+float syncOniPlayer::getPosition(){
+ if (players.size()) return players[0]->getPosition();
+ else return -1.0f;
+}
void syncOniPlayer::drawWindows(){
if (!drawable) return;
for (int i=0;i<players.size();i++) {
@@ -96,8 +102,9 @@ void syncOniPlayer::drawCloud(int step){
return;
}
-void syncOniPlayer::drawPoints(float birth,float life,float dx,float dy, float dz,float size){
+void syncOniPlayer::drawPoints(float _birth,float life,float dx,float dy, float dz,float size){
if (!drawable) return;
+
//glEnable(GL_PROGRAM_POINT_SIZE);
//glEnable(GL_POINT_SMOOTH);
//glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
@@ -105,33 +112,55 @@ void syncOniPlayer::drawPoints(float birth,float life,float dx,float dy, float d
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
//glPointSize( size);
//glBegin(GL_POINTS);
- const XnDepthPixel* depthmap=players[0]->getDepthGenerator().GetDepthMap();
- const ofPixels& pixels=players[0]->getImagePixels();
- int range=1700;
- int dmw=players[0]->getWidth();
- int dmh=players[0]->getHeight();
- if (dmw&&dmh){
- int step=pixels.getWidth()/dmw;
- for (int o=0;o<birth;o++) {
- int i=ofRandom(dmw);
- int j=ofRandom(dmh);
- ofPoint p= players[0]->projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
- if (p.z <100 || p.z>range) continue;
- //points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2));
- //fpoint f=fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2);
- //f.draw(life,dx,dy,dz);
- if (pointPool.size()) {//take 1st dead particle
- points[(*pointPool.begin())].setup(p.x, p.y, p.z,
- LUT[pixels[((j*step*dmw)+(i*step))*3]],
- LUT[pixels[((j*step*dmw)+(i*step))*3]+1],
- LUT[pixels[((j*step*dmw)+(i*step))*3]+2]
- );
- pointPool.erase(pointPool.begin());
- }
- else {//make a new one
- points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2));
- }
- }
+
+ if (playerActive){
+ //apply envelope
+ float attackSeconds=2.0f;
+ float playOutFraction=0.9f;
+ float birth;
+ float clipTime=ofGetElapsedTimef()-startTime;
+ if (clipTime<attackSeconds) {
+ //ramp in
+ birth=_birth*(clipTime/attackSeconds);
+ }
+ else if (players[0]->getPosition()>playOutFraction) {
+ //cerr<<"playing out!"<<endl;
+ birth=_birth*(1.0f-((players[0]->getPosition()-playOutFraction)/(1.0f-playOutFraction)));
+ //if it reaches the end stop creating points but allow old points to play out
+ if (players[0]->getPosition()>0.99) playerActive=false;
+ }
+ else birth=_birth;
+
+ //cerr<<birth<<" "<<clipTime<<" "<<players[0]->getPosition()<<endl;
+
+ const XnDepthPixel* depthmap=players[0]->getDepthGenerator().GetDepthMap();
+ const ofPixels& pixels=players[0]->getImagePixels();
+ int range=1700;
+ int dmw=players[0]->getWidth();
+ int dmh=players[0]->getHeight();
+ if (dmw&&dmh){
+ int step=pixels.getWidth()/dmw;
+ for (int o=0;o<birth;o++) {
+ int i=ofRandom(dmw);
+ int j=ofRandom(dmh);
+ ofPoint p= players[0]->projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
+ if (p.z <100 || p.z>range) continue;
+ //points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2));
+ //fpoint f=fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2);
+ //f.draw(life,dx,dy,dz);
+ if (pointPool.size()) {//take 1st dead particle
+ points[(*pointPool.begin())].setup(p.x, p.y, p.z,
+ LUT[pixels[((j*step*dmw)+(i*step))*3]],
+ LUT[pixels[((j*step*dmw)+(i*step))*3]+1],
+ LUT[pixels[((j*step*dmw)+(i*step))*3]+2]
+ );
+ pointPool.erase(pointPool.begin());
+ }
+ else {//make a new one
+ points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2));
+ }
+ }
+ }
}
for (int i=0;i<points.size();i++){
if (!points[i].draw(life,dx,dy,dz,size)) {
@@ -155,6 +184,7 @@ void syncOniPlayer::stop(){
}
}
drawable=false;
+ playerActive=false;
}
//=================
void oniManager::init(const char* filename){
@@ -217,4 +247,8 @@ void oniManager::drawPoints(float size,float birth,float life,float dx,float dy,
players[playing].drawPoints(birth,life,dx,dy,dz,size);
}
}
+syncOniPlayer* oniManager::getCurrentPlayer(){
+ if (players.size()>playing&&playing>-1) return &players[playing];
+ else return NULL;
+}