Added foreground to scene.

This commit is contained in:
brunoherbelin
2020-05-22 10:31:08 +02:00
parent 16fa3300b8
commit 9f4cb4dce3
7 changed files with 42 additions and 28 deletions

View File

@@ -230,9 +230,9 @@ void Mixer::insertSource(Source *s)
setCurrentSource( session_->addSource(s) );
// add sources Nodes to all views
mixing_.scene.fg()->attach(s->group(View::MIXING));
geometry_.scene.fg()->attach(s->group(View::GEOMETRY));
layer_.scene.fg()->attach(s->group(View::LAYER));
mixing_.scene.ws()->attach(s->group(View::MIXING));
geometry_.scene.ws()->attach(s->group(View::GEOMETRY));
layer_.scene.ws()->attach(s->group(View::LAYER));
layer_.setDepth(s);
}
@@ -251,9 +251,9 @@ void Mixer::deleteSource(Source *s)
std::string name = s->name();
// remove source Nodes from all views
mixing_.scene.fg()->detatch( s->group(View::MIXING) );
geometry_.scene.fg()->detatch( s->group(View::GEOMETRY) );
layer_.scene.fg()->detatch( s->group(View::LAYER) );
mixing_.scene.ws()->detatch( s->group(View::MIXING) );
geometry_.scene.ws()->detatch( s->group(View::GEOMETRY) );
layer_.scene.ws()->detatch( s->group(View::LAYER) );
// delete source
session_->deleteSource(s);
@@ -422,9 +422,9 @@ void Mixer::swap()
// detatch current session's nodes from views
for (auto source_iter = session_->begin(); source_iter != session_->end(); source_iter++)
{
mixing_.scene.fg()->detatch( (*source_iter)->group(View::MIXING) );
geometry_.scene.fg()->detatch( (*source_iter)->group(View::GEOMETRY) );
layer_.scene.fg()->detatch( (*source_iter)->group(View::LAYER) );
mixing_.scene.ws()->detatch( (*source_iter)->group(View::MIXING) );
geometry_.scene.ws()->detatch( (*source_iter)->group(View::GEOMETRY) );
layer_.scene.ws()->detatch( (*source_iter)->group(View::LAYER) );
}
}
@@ -436,9 +436,9 @@ void Mixer::swap()
// attach new session's nodes to views
for (auto source_iter = session_->begin(); source_iter != session_->end(); source_iter++)
{
mixing_.scene.fg()->attach( (*source_iter)->group(View::MIXING) );
geometry_.scene.fg()->attach( (*source_iter)->group(View::GEOMETRY) );
layer_.scene.fg()->attach( (*source_iter)->group(View::LAYER) );
mixing_.scene.ws()->attach( (*source_iter)->group(View::MIXING) );
geometry_.scene.ws()->attach( (*source_iter)->group(View::GEOMETRY) );
layer_.scene.ws()->attach( (*source_iter)->group(View::LAYER) );
}
// optional copy of views config

View File

@@ -349,7 +349,7 @@ RenderingAttrib Rendering::currentAttrib()
glm::mat4 Rendering::Projection()
{
static glm::mat4 projection = glm::ortho(-SCENE_UNIT, SCENE_UNIT, -SCENE_UNIT, SCENE_UNIT, SCENE_DEPTH, 1.f);
static glm::mat4 projection = glm::ortho(-SCENE_UNIT, SCENE_UNIT, -SCENE_UNIT, SCENE_UNIT, -SCENE_DEPTH, 1.f);
glm::mat4 scale = glm::scale(glm::identity<glm::mat4>(), glm::vec3(1.f, AspectRatio(), 1.f));
return projection * scale;

View File

@@ -414,12 +414,14 @@ Scene::Scene(): root_(nullptr), foreground_(nullptr), background_(nullptr)
root_ = new Group;
background_ = new Group;
background_->translation_.z = 0;
background_->translation_.z = 0.f;
workspace_ = new Group;
workspace_->translation_.z = 1.f;
foreground_ = new Group;
// TODO Verify depth for foreground
foreground_->translation_.z = 1;
foreground_->translation_.z = SCENE_DEPTH -0.1f;
root_->attach(background_);
root_->attach(workspace_);
root_->attach(foreground_);
}
@@ -433,6 +435,7 @@ Scene::~Scene()
void Scene::clear()
{
clearForeground();
clearWorkspace();
clearBackground();
}
@@ -441,6 +444,11 @@ void Scene::clearForeground()
foreground_->clear();
}
void Scene::clearWorkspace()
{
foreground_->clear();
}
void Scene::clearBackground()
{
background_->clear();

View File

@@ -238,16 +238,16 @@ protected:
/**
* @brief A Scene holds a root node with two children; a background and a foreground
* @brief A Scene holds a root node with 3 children; a background, a workspace and a foreground
*
* Nodes should be added to foreground and background only (not root)
* The update() is called on the root (both background and foreground)
* The update() is called on the root
*
*/
class Scene {
Group *root_;
Group *background_;
Group *workspace_;
Group *foreground_;
public:
@@ -259,10 +259,12 @@ public:
void clear();
void clearBackground();
void clearWorkspace();
void clearForeground();
Group *root() { return root_; }
Group *bg() { return background_; }
Group *ws() { return workspace_; }
Group *fg() { return foreground_; }
};

View File

@@ -59,7 +59,7 @@ void Session::update(float dt)
SourceList::iterator Session::addSource(Source *s)
{
// insert the source in the rendering
render_.scene.fg()->attach(s->group(View::RENDERING));
render_.scene.ws()->attach(s->group(View::RENDERING));
// insert the source to the beginning of the list
sources_.push_front(s);
// return the iterator to the source created at the beginning
@@ -74,7 +74,7 @@ SourceList::iterator Session::deleteSource(Source *s)
if (its != sources_.end()) {
// remove Node from the rendering scene
render_.scene.fg()->detatch( s->group(View::RENDERING) );
render_.scene.ws()->detatch( s->group(View::RENDERING) );
// erase the source from the update list & get next element
its = sources_.erase(its);

View File

@@ -54,7 +54,7 @@ void View::update(float dt)
// a more complete update is requested
if (View::need_deep_update_) {
// reorder sources
scene.fg()->sort();
scene.ws()->sort();
}
}
@@ -151,6 +151,7 @@ uint MixingView::textureMixingQuadratic()
for (int j=0; j < CIRCLE_PIXELS / 2; ++j) {
// distance to the center
distance = (GLfloat) ((c * c) + (l * l)) / CIRCLE_PIXEL_RADIUS;
// distance = (GLfloat) sqrt( (GLfloat) ((c * c) + (l * l))) / (GLfloat) sqrt(CIRCLE_PIXEL_RADIUS); // linear
// luminance
luminance = 255.f * CLAMP( 0.95f - 0.8f * distance, 0.f, 1.f);
color[0] = color[1] = color[2] = static_cast<GLubyte>(luminance);
@@ -206,7 +207,7 @@ void RenderView::setResolution(glm::vec3 resolution)
void RenderView::draw()
{
static glm::mat4 projection = glm::ortho(-1.f, 1.f, -1.f, 1.f, SCENE_DEPTH, 0.f);
static glm::mat4 projection = glm::ortho(-1.f, 1.f, -1.f, 1.f, -SCENE_DEPTH, 0.f);
glm::mat4 P = glm::scale( projection, glm::vec3(1.f / frame_buffer_->aspectRatio(), 1.f, 1.f));
frame_buffer_->begin();
scene.root()->draw(glm::identity<glm::mat4>(), P);
@@ -230,7 +231,7 @@ GeometryView::GeometryView() : View(GEOMETRY)
Frame *border = new Frame(Frame::SHARP_THIN);
border->color = glm::vec4( 0.8f, 0.f, 0.8f, 1.f );
scene.bg()->attach(border);
scene.fg()->attach(border);
}
@@ -247,6 +248,9 @@ void GeometryView::update(float dt)
for (NodeSet::iterator node = scene.bg()->begin(); node != scene.bg()->end(); node++) {
(*node)->scale_.x = output->aspectRatio();
}
for (NodeSet::iterator node = scene.fg()->begin(); node != scene.fg()->end(); node++) {
(*node)->scale_.x = output->aspectRatio();
}
}
}
}
@@ -376,7 +380,7 @@ void LayerView::update(float dt)
for (NodeSet::iterator node = scene.bg()->begin(); node != scene.bg()->end(); node++) {
(*node)->scale_.x = aspect_ratio;
}
for (NodeSet::iterator node = scene.fg()->begin(); node != scene.fg()->end(); node++) {
for (NodeSet::iterator node = scene.ws()->begin(); node != scene.ws()->end(); node++) {
(*node)->translation_.y = (*node)->translation_.x / aspect_ratio;
}
}
@@ -401,7 +405,7 @@ void LayerView::setDepth (Source *s, float d)
// negative depth given; find the front most depth
if ( depth < 0.f ) {
Node *front = scene.fg()->front();
Node *front = scene.ws()->front();
if (front)
depth = front->translation_.z + 0.5f;
else
@@ -412,7 +416,7 @@ void LayerView::setDepth (Source *s, float d)
Group *sourceNode = s->group(mode_);
// diagonal movement only
sourceNode->translation_.x = CLAMP( -depth, SCENE_DEPTH + 2.f, 0.f);
sourceNode->translation_.x = CLAMP( -depth, -(SCENE_DEPTH - 2.f), 0.f);
sourceNode->translation_.y = sourceNode->translation_.x / aspect_ratio;
// change depth

View File

@@ -23,7 +23,7 @@
#define EUCLIDEAN(P1, P2) sqrt((P1.x() - P2.x()) * (P1.x() - P2.x()) + (P1.y() - P2.y()) * (P1.y() - P2.y()))
#define SCENE_UNIT 5.f
#define SCENE_DEPTH -12.f
#define SCENE_DEPTH 12.f
#define CIRCLE_SQUARE_DIST(x,y) ( (x*x + y*y) / (SCENE_UNIT * SCENE_UNIT * SCENE_UNIT * SCENE_UNIT) )
#define IMGUI_TITLE_MAINWINDOW ICON_FA_CIRCLE_NOTCH " vimix"