Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions core/include/core_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ class CoreApp : public ofBaseApp {
static void draw_green_frame();
void draw_fps_counter() const;

ofxAzureKinect::Device kinect_device;
ofxAzureKinect::Device _kinect_device;

IntroScene intro_scene;
TrackingScene tracking_scene;
IntroScene _intro_scene;
TrackingScene _tracking_scene;

Scene *current_scene;
Scene *inactive_scene;
Scene *keyboard_triggered_scene;
Scene *_current_scene;
Scene *_inactive_scene;
Scene *_keyboard_triggered_scene;

ofFbo current_app_fbo;
ofFbo inactive_app_fbo;
ofShader transition_shader;
ofFbo _current_app_fbo;
ofFbo _inactive_app_fbo;
ofShader _transition_shader;

const std::chrono::milliseconds transition_duration = 500ms;
std::chrono::steady_clock::time_point transition_start_time;
const std::chrono::milliseconds _transition_duration = 500ms;
std::chrono::steady_clock::time_point _transition_start_time;

ofSoundPlayer ambient_sound;
ofSoundPlayer transition_to_intro_sound;
ofSoundPlayer transition_to_tracking_sound;
ofSoundPlayer _ambient_sound;
ofSoundPlayer _transition_to_intro_sound;
ofSoundPlayer _transition_to_tracking_sound;

bool show_debug_info = false;
bool _show_debug_info;
};
143 changes: 62 additions & 81 deletions core/src/core_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
#include <utility>

CoreApp::CoreApp() :
tracking_scene({&kinect_device}), current_scene(&intro_scene), inactive_scene(&tracking_scene),
keyboard_triggered_scene(nullptr) {}
_tracking_scene({&_kinect_device}), _current_scene(&_intro_scene), _inactive_scene(&_tracking_scene),
_keyboard_triggered_scene(nullptr), _show_debug_info(false) {}

//--------------------------------------------------------------
void CoreApp::setup() {
ofSetFrameRate(60);
ofSetVerticalSync(true);

ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices.";

if (kinect_device.open()) {
if (_kinect_device.open()) {
auto device_settings = ofxAzureKinect::DeviceSettings();
device_settings.syncImages = true;
device_settings.depthMode = K4A_DEPTH_MODE_NFOV_UNBINNED;
Expand All @@ -22,87 +21,78 @@ void CoreApp::setup() {
device_settings.colorResolution = K4A_COLOR_RESOLUTION_1080P;
device_settings.updateWorld = true;
device_settings.updateVbo = false;
kinect_device.startCameras(device_settings);
_kinect_device.startCameras(device_settings);

auto body_tracker_settings = ofxAzureKinect::BodyTrackerSettings();
body_tracker_settings.sensorOrientation = K4ABT_SENSOR_ORIENTATION_DEFAULT;
body_tracker_settings.processingMode = K4ABT_TRACKER_PROCESSING_MODE_GPU;
body_tracker_settings.updateBodiesImage = true;
kinect_device.startBodyTracker(body_tracker_settings);
_kinect_device.startBodyTracker(body_tracker_settings);
}

current_app_fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
inactive_app_fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
transition_shader.load("shaders/transition");
_current_app_fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
_inactive_app_fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
_transition_shader.load("shaders/transition");

ambient_sound.load("resources/audio/gruen_ambient.wav");
ambient_sound.play();
ambient_sound.setLoop(true);
_ambient_sound.load("resources/audio/gruen_ambient.wav");
_ambient_sound.play();
_ambient_sound.setLoop(true);

transition_to_intro_sound.load("resources/audio/transition_to_intro.wav");
transition_to_intro_sound.setVolume(0.25f);
_transition_to_intro_sound.load("resources/audio/transition_to_intro.wav");
_transition_to_intro_sound.setVolume(0.25f);

transition_to_tracking_sound.load("resources/audio/transition_to_tracking.wav");
transition_to_tracking_sound.setVolume(0.25f);
_transition_to_tracking_sound.load("resources/audio/transition_to_tracking.wav");
_transition_to_tracking_sound.setVolume(0.25f);
}

//--------------------------------------------------------------
void CoreApp::exit() {
kinect_device.close();
_kinect_device.close();
ofSoundStopAll();
}

//--------------------------------------------------------------
void CoreApp::update() {
if (keyboard_triggered_scene) {
keyboard_triggered_scene->update();
if (_keyboard_triggered_scene) {
_keyboard_triggered_scene->update();
return;
}

const auto &body_skeletons = kinect_device.getBodySkeletons();
const auto &body_skeletons = _kinect_device.getBodySkeletons();

if (current_scene == &intro_scene && !body_skeletons.empty()) {
transition_to_tracking_sound.play();
transition_start_time = std::chrono::steady_clock::now();
current_scene = &tracking_scene;
} else if (current_scene == &tracking_scene && body_skeletons.empty()) {
intro_scene.reset_particles();
if (_current_scene == &_intro_scene && !body_skeletons.empty()) {
_transition_to_tracking_sound.play();
_transition_start_time = std::chrono::steady_clock::now();
_current_scene = &_tracking_scene;
} else if (_current_scene == &_tracking_scene && body_skeletons.empty()) {
_intro_scene.reset_particles();

transition_to_intro_sound.play();
transition_start_time = std::chrono::steady_clock::now();
current_scene = &intro_scene;
_transition_to_intro_sound.play();
_transition_start_time = std::chrono::steady_clock::now();
_current_scene = &_intro_scene;
}

current_scene->update();
_current_scene->update();
}

//--------------------------------------------------------------
void CoreApp::draw() {
if (keyboard_triggered_scene) {
keyboard_triggered_scene->draw();
draw_fps_counter();
return;
}

auto current_time = std::chrono::steady_clock::now();
auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(current_time - transition_start_time);
auto progress = static_cast<float>(elapsed_time.count()) / static_cast<float>(transition_duration.count());

if (progress < 1.0f) {
current_scene->render();
inactive_scene->render();

transition_shader.begin();
{
transition_shader.setUniformTexture("transition_tex", inactive_scene->get_frame_buffer().getTexture(), 1);
transition_shader.setUniform1f("progress", progress);
transition_shader.setUniform1f("random_offset_one", ofRandomHeight());
transition_shader.setUniform1f("random_offset_two", ofRandomHeight());
current_scene->get_frame_buffer().draw(0, 0);
}
transition_shader.end();
const auto time = std::chrono::steady_clock::now();
const auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time - _transition_start_time);
const auto progress = static_cast<float>(elapsed_time.count()) / static_cast<float>(_transition_duration.count());

if (_keyboard_triggered_scene) {
_keyboard_triggered_scene->draw();
} else if (progress < 1.0f) {
_current_scene->render();
_inactive_scene->render();

_transition_shader.begin();
_transition_shader.setUniformTexture("transition_tex", _inactive_scene->get_frame_buffer().getTexture(), 1);
_transition_shader.setUniform1f("progress", progress);
_transition_shader.setUniform1f("random_offset_one", ofRandomHeight());
_transition_shader.setUniform1f("random_offset_two", ofRandomHeight());
_current_scene->get_frame_buffer().draw(0, 0);
_transition_shader.end();
} else {
current_scene->draw();
_current_scene->draw();
}

draw_fps_counter();
Expand All @@ -121,80 +111,71 @@ void CoreApp::draw_green_frame() {
}

void CoreApp::draw_fps_counter() const {
if (!show_debug_info) {
if (!_show_debug_info) {
return;
}

std::ostringstream oss;
auto oss = std::ostringstream();
oss << ofToString(ofGetFrameRate(), 2) + " FPS" << std::endl;
ofDrawBitmapStringHighlight(oss.str(), 10, 20);
}

//--------------------------------------------------------------
void CoreApp::keyPressed(int key) {
switch (key) {
case 'e':
tracking_scene.toggle_skeletons();
_tracking_scene.toggle_skeletons();
break;
case 'q':
tracking_scene.trigger_global_effect({ofGetWidth(), 0});
_tracking_scene.trigger_global_effect({ofGetWidth(), 0});
break;
case 'w':
tracking_scene.trigger_global_effect({0, 0});
_tracking_scene.trigger_global_effect({0, 0});
break;
case 'a':
tracking_scene.trigger_global_effect({ofGetWidth(), ofGetHeight()});
_tracking_scene.trigger_global_effect({ofGetWidth(), ofGetHeight()});
break;
case 's':
tracking_scene.trigger_global_effect({0, ofGetHeight()});
_tracking_scene.trigger_global_effect({0, ofGetHeight()});
break;
case 'r':
tracking_scene.reset_camera();
_tracking_scene.reset_camera();
break;
case 'f':
show_debug_info = !show_debug_info;
_show_debug_info = !_show_debug_info;
break;
case '1':
keyboard_triggered_scene = &intro_scene;
_keyboard_triggered_scene = &_intro_scene;
break;
case '2':
keyboard_triggered_scene = &tracking_scene;
_keyboard_triggered_scene = &_tracking_scene;
break;
case '3':
keyboard_triggered_scene = nullptr;
_keyboard_triggered_scene = nullptr;
break;
case 'p':
intro_scene.reset_particles();
_intro_scene.reset_particles();
break;
default:
break;
}
}

//--------------------------------------------------------------
void CoreApp::keyReleased(int key) {}

//--------------------------------------------------------------
void CoreApp::mouseMoved(int x, int y) {}

//--------------------------------------------------------------
void CoreApp::mouseDragged(int x, int y, int button) {}

//--------------------------------------------------------------
void CoreApp::mousePressed(int x, int y, int button) {}

//--------------------------------------------------------------
void CoreApp::mouseReleased(int x, int y, int button) {}

//--------------------------------------------------------------
void CoreApp::mouseEntered(int x, int y) {}

//--------------------------------------------------------------
void CoreApp::mouseExited(int x, int y) {}

//--------------------------------------------------------------
void CoreApp::windowResized(int w, int h) {}

//--------------------------------------------------------------
void CoreApp::gotMessage(ofMessage msg) {}

//--------------------------------------------------------------
void CoreApp::dragEvent(ofDragInfo dragInfo) {}
2 changes: 1 addition & 1 deletion core/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main() {
auto settings = ofGLWindowSettings();
settings.setSize(1920, 1080);
settings.setGLVersion(4, 6);
settings.windowMode = OF_FULLSCREEN;
settings.windowMode = OF_WINDOW;

const auto window = ofCreateWindow(settings);
ofRunApp(window, make_shared<CoreApp>());
Expand Down
29 changes: 12 additions & 17 deletions intro/include/intro_scene.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <string>
#include <utility>
#include <vector>

#include <ofMain.h>
#include <ofFbo.h>
#include <ofShader.h>
#include <ofVec2f.h>
#include <ofxSvg.h>

#include <scene.h>
Expand All @@ -21,15 +22,15 @@ class IntroScene : public Scene {
void reset_particles();

private:
const int screen_width = ofGetWidth();
const int screen_height = ofGetHeight();
void create_logo_vectors();
void create_logo_in_outs_vectors();

// flow field
std::vector<ofVec2f> flow_field;
int flow_field_resolution;
int flow_field_cols;
int flow_field_rows;
float flow_field_offset;
const int flow_field_resolution = 20;
const int flow_field_cols = ofGetWidth() / flow_field_resolution;
const int flow_field_rows = ofGetHeight() / flow_field_resolution;

// particles
std::array<Particle, 2048> particles;
Expand All @@ -44,29 +45,23 @@ class IntroScene : public Scene {
// logo
ofxSVG logo_svg;
ofxSVG logo_in_outs_svg;
const float logo_scale = 1.0;
std::vector<pair<ofVec2f, ofVec2f>> logo_vectors;
std::vector<pair<ofVec2f, ofVec2f>> logo_in_outs_vectors;

std::vector<std::pair<ofVec2f, ofVec2f>> logo_vectors;
std::vector<std::pair<ofVec2f, ofVec2f>> logo_in_outs_vectors;
std::vector<std::pair<ofVec2f, ofVec2f>> all_logo_vectors;

ofxSVG logo_picture;
ofFbo logo_fbo;

ofVec2f logo_position;
float logo_width;
float logo_height;
int logo_left, logo_right, logo_top, logo_bottom;
ofVec2f logo_center;
float logo_radius;
int logo_margin = 30;
int logo_margin;

ofFbo particle_draw_fbo;

ofShader particle_trail_shader;
ofShader particle_pixel_shader;

int line_position = 0;

void create_logo_vectors();
void create_logo_in_outs_vectors();
};
Loading
Loading