summaryrefslogtreecommitdiff
path: root/06_performance
diff options
context:
space:
mode:
Diffstat (limited to '06_performance')
-rw-r--r--06_performance/src/main.cpp2
-rw-r--r--06_performance/src/oni.cpp90
-rw-r--r--06_performance/src/oni.h5
-rw-r--r--06_performance/src/testApp.cpp12
-rw-r--r--06_performance/src/testApp.h2
5 files changed, 79 insertions, 32 deletions
diff --git a/06_performance/src/main.cpp b/06_performance/src/main.cpp
index 9343609..733d488 100644
--- a/06_performance/src/main.cpp
+++ b/06_performance/src/main.cpp
@@ -5,7 +5,7 @@
int main( ){
//ofSetupOpenGL(4080,768, OF_WINDOW); // <-------- setup the GL context
- ofSetupOpenGL(1550,296, OF_WINDOW); // <-------- setup the GL context
+ ofSetupOpenGL(1400,262, OF_WINDOW); // <-------- setup the GL context
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;
+}
diff --git a/06_performance/src/oni.h b/06_performance/src/oni.h
index c858995..73edeee 100644
--- a/06_performance/src/oni.h
+++ b/06_performance/src/oni.h
@@ -42,6 +42,7 @@ class syncOniPlayer{
gamma=3.0f;
LUT=NULL;
makeLUT();
+ playerActive=false;
}
~syncOniPlayer(){
stop();
@@ -60,6 +61,7 @@ class syncOniPlayer{
void update();
void pause();
int getCurrentFrame();
+ float getPosition();
int getNumParticles();
void drawWindows();
void drawCloud(int step);
@@ -76,6 +78,8 @@ class syncOniPlayer{
set<int> pointPool;
float gamma;
uint8_t *LUT;
+ float startTime;
+ bool playerActive;
};
//========================================
class oniManager{
@@ -84,6 +88,7 @@ class oniManager{
void startPlayer(int num);
int getNumClips();
int getNumParticles();
+ syncOniPlayer* getCurrentPlayer();
void update();
void drawWindows();
void drawCloud(int step);
diff --git a/06_performance/src/testApp.cpp b/06_performance/src/testApp.cpp
index db45680..4cc47a3 100644
--- a/06_performance/src/testApp.cpp
+++ b/06_performance/src/testApp.cpp
@@ -562,6 +562,8 @@ void testApp::draw(){
msg+="\n"+ofToString(F_yseg, 4);
msg+="\n"+ofToString(narrator.getNumParticles())+" size "+ofToString(F_lineWidth);
msg+="\n"+ofToString(xModel)+","+ofToString(yModel)+","+ofToString(zModel)+" * "+ofToString(sModel);
+ syncOniPlayer *player=narrator.getCurrentPlayer();
+ if (player) msg+="\n"+ofToString(player->getCurrentFrame())+","+ofToString(player->getPosition(),2);
ofDrawBitmapString(msg,20,20);
}
}
@@ -612,12 +614,18 @@ void testApp::keyPressed (int key){
if(key == 'c'){
zModel-=25;
}
- if(key == 'y'){
+ if(key == 'w'){
sModel*=1.02;
}
- if(key == 'h'){
+ if(key == 's'){
sModel/=1.02;
}
+ if(key == 'q'){
+ I_fade1=min(I_fade1+1,255);
+ }
+ if(key == 'a'){
+ I_fade1=max(I_fade1-1,0);
+ }
if(key == 'h'){
F_particleX-=1;
}
diff --git a/06_performance/src/testApp.h b/06_performance/src/testApp.h
index 4ecc24d..87a0b07 100644
--- a/06_performance/src/testApp.h
+++ b/06_performance/src/testApp.h
@@ -10,7 +10,7 @@
#include "oni.h"
-#define BUFFER_SIZE 1024
+#define BUFFER_SIZE 1024 //was 1024
#define BUFFER_FRAMES 512
/*