mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
New Geometry View, with new frame and new settings.
This commit is contained in:
99
View.cpp
99
View.cpp
@@ -12,6 +12,7 @@
|
||||
#include "Primitives.h"
|
||||
#include "Resource.h"
|
||||
#include "Mesh.h"
|
||||
#include "Mixer.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "Log.h"
|
||||
|
||||
@@ -31,7 +32,7 @@ void View::update(float dt)
|
||||
MixingView::MixingView() : View()
|
||||
{
|
||||
// default settings
|
||||
scene.root()->scale_ = glm::vec3(1.6, 1.6, 1.0);
|
||||
scene.root()->scale_ = glm::vec3(1.6f, 1.6f, 1.0f);
|
||||
|
||||
// Mixing scene
|
||||
Mesh *disk = new Mesh("mesh/disk.ply");
|
||||
@@ -39,7 +40,6 @@ MixingView::MixingView() : View()
|
||||
backgound_.addChild(disk);
|
||||
|
||||
glm::vec4 pink( 0.8f, 0.f, 0.8f, 1.f );
|
||||
// LineCircle *circle = new LineCircle(pink, 5);
|
||||
Mesh *circle = new Mesh("mesh/circle.ply");
|
||||
circle->shader()->color = pink;
|
||||
backgound_.addChild(circle);
|
||||
@@ -183,10 +183,103 @@ void RenderView::setResolution(uint width, uint height)
|
||||
|
||||
void RenderView::draw()
|
||||
{
|
||||
static glm::mat4 projection = glm::ortho(-SCENE_UNIT, SCENE_UNIT, -SCENE_UNIT, SCENE_UNIT, 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);
|
||||
frame_buffer_->end();
|
||||
}
|
||||
|
||||
|
||||
GeometryView::GeometryView() : View()
|
||||
{
|
||||
// Scene
|
||||
Surface *rect = new Surface;
|
||||
backgound_.addChild(rect);
|
||||
|
||||
// Mesh *shadow = new Mesh("mesh/shadow.ply", "images/shadow.png");
|
||||
Frame *border = new Frame(Frame::SHARP_THIN);
|
||||
border->overlay_ = new Mesh("mesh/border_vertical_overlay.ply");
|
||||
border->color = glm::vec4( 0.8f, 0.f, 0.8f, 1.f );
|
||||
backgound_.addChild(border);
|
||||
|
||||
scene.root()->addChild(&backgound_);
|
||||
|
||||
// default settings
|
||||
scene.root()->scale_ = glm::vec3(1.2f, 1.2f, 1.f);
|
||||
|
||||
}
|
||||
|
||||
GeometryView::~GeometryView()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GeometryView::draw()
|
||||
{
|
||||
// update rendering of render frame
|
||||
FrameBuffer *output = Mixer::manager().frame();
|
||||
if (output){
|
||||
for (NodeSet::iterator node = backgound_.begin(); node != backgound_.end(); node++) {
|
||||
(*node)->scale_.x = output->aspectRatio();
|
||||
}
|
||||
}
|
||||
|
||||
// draw scene of this view
|
||||
scene.root()->draw(glm::identity<glm::mat4>(), Rendering::manager().Projection());
|
||||
}
|
||||
|
||||
void GeometryView::zoom( float factor )
|
||||
{
|
||||
float z = scene.root()->scale_.x;
|
||||
z = CLAMP( z + 0.1f * factor, 0.2f, 10.f);
|
||||
scene.root()->scale_.x = z;
|
||||
scene.root()->scale_.y = z;
|
||||
|
||||
}
|
||||
|
||||
void GeometryView::drag (glm::vec2 from, glm::vec2 to)
|
||||
{
|
||||
static glm::vec3 start_translation = glm::vec3(0.f);
|
||||
static glm::vec2 start_position = glm::vec2(0.f);
|
||||
|
||||
if ( start_position != from ) {
|
||||
start_position = from;
|
||||
start_translation = scene.root()->translation_;
|
||||
}
|
||||
|
||||
// unproject
|
||||
glm::vec3 gl_Position_from = Rendering::manager().unProject(from);
|
||||
glm::vec3 gl_Position_to = Rendering::manager().unProject(to);
|
||||
|
||||
// compute delta translation
|
||||
scene.root()->translation_ = start_translation + gl_Position_to - gl_Position_from;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GeometryView::grab (glm::vec2 from, glm::vec2 to, Source *s)
|
||||
{
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
Group *sourceNode = s->group(View::GEOMETRY);
|
||||
|
||||
static glm::vec3 start_translation = glm::vec3(0.f);
|
||||
static glm::vec2 start_position = glm::vec2(0.f);
|
||||
|
||||
if ( start_position != from ) {
|
||||
start_position = from;
|
||||
start_translation = sourceNode->translation_;
|
||||
}
|
||||
|
||||
// unproject
|
||||
glm::vec3 gl_Position_from = Rendering::manager().unProject(from, sourceNode->parent_->transform_);
|
||||
glm::vec3 gl_Position_to = Rendering::manager().unProject(to, sourceNode->parent_->transform_);
|
||||
|
||||
// compute delta translation
|
||||
sourceNode->translation_ = start_translation + gl_Position_to - gl_Position_from;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user