mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 10:19:59 +01:00
Initial implementation of handles on sources to manipulate in geometry
view (only resize implemented so far)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Log.h"
|
||||
#include "Primitives.h"
|
||||
#include "GlmToolkit.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
@@ -17,8 +18,9 @@ PickingVisitor::PickingVisitor(glm::vec2 coordinates) : Visitor(), point_(coordi
|
||||
|
||||
void PickingVisitor::visit(Node &n)
|
||||
{
|
||||
// use the transform modified during update
|
||||
modelview_ *= n.transform_;
|
||||
|
||||
modelview_ *= n.transform_;
|
||||
// modelview_ *= transform(n.translation_, n.rotation_, n.scale_);
|
||||
// Log::Info("Node %d", n.id());
|
||||
// Log::Info("%s", glm::to_string(modelview_).c_str());
|
||||
@@ -27,9 +29,9 @@ void PickingVisitor::visit(Node &n)
|
||||
void PickingVisitor::visit(Group &n)
|
||||
{
|
||||
glm::mat4 mv = modelview_;
|
||||
//Log::Info("Group %d", n.id());
|
||||
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
|
||||
(*node)->accept(*this);
|
||||
if ( (*node)->visible_ )
|
||||
(*node)->accept(*this);
|
||||
modelview_ = mv;
|
||||
}
|
||||
}
|
||||
@@ -41,33 +43,71 @@ void PickingVisitor::visit(Switch &n)
|
||||
modelview_ = mv;
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Animation &n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Primitive &n)
|
||||
{
|
||||
// TODO: generic visitor for primitive with random shape
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Surface &n)
|
||||
{
|
||||
// Log::Info("Surface %d", n.id());
|
||||
if (!n.visible_)
|
||||
return;
|
||||
|
||||
// apply inverse transform to the point of interest
|
||||
glm::vec4 P = glm::inverse(modelview_) * glm::vec4( point_, 0.f, 1.f );
|
||||
|
||||
// lower left corner
|
||||
glm::vec3 LL = glm::vec3( -1.f, -1.f, 0.f );
|
||||
// up right corner
|
||||
glm::vec3 UR = glm::vec3( 1.f, 1.f, 0.f );
|
||||
|
||||
// if P is inside [LL UR] rectangle:
|
||||
if ( P.x > LL.x && P.x < UR.x && P.y > LL.y && P.y < UR.y )
|
||||
// test bounding box: it is an exact fit for a resctangular surface
|
||||
if ( n.bbox().contains( glm::vec3(P)) )
|
||||
// add this surface to the nodes picked
|
||||
nodes_.push_back( std::pair(&n, glm::vec2(P)) );
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Frame &n)
|
||||
{
|
||||
n.border()->accept(*this);
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(Handles &n)
|
||||
{
|
||||
if (!n.visible_)
|
||||
return;
|
||||
|
||||
// apply inverse transform to the point of interest
|
||||
glm::vec4 P = glm::inverse(modelview_) * glm::vec4( point_, 0.f, 1.f );
|
||||
|
||||
// get the bounding box of a handle
|
||||
GlmToolkit::AxisAlignedBoundingBox bb = n.handle()->bbox();
|
||||
|
||||
// test picking depending on type of handle
|
||||
bool picked = false;
|
||||
if ( n.type() == Handles::RESIZE ) {
|
||||
// 4 corners
|
||||
picked = ( bb.translated(glm::vec3(+1.f, +1.f, 0.f)).contains( glm::vec3(P) ) ||
|
||||
bb.translated(glm::vec3(+1.f, -1.f, 0.f)).contains( glm::vec3(P) ) ||
|
||||
bb.translated(glm::vec3(-1.f, +1.f, 0.f)).contains( glm::vec3(P) ) ||
|
||||
bb.translated(glm::vec3(-1.f, -1.f, 0.f)).contains( glm::vec3(P) ) );
|
||||
}
|
||||
else if ( n.type() == Handles::RESIZE_H ){
|
||||
// left & right
|
||||
picked = ( bb.translated(glm::vec3(+1.f, 0.f, 0.f)).contains( glm::vec3(P) ) ||
|
||||
bb.translated(glm::vec3(-1.f, 0.f, 0.f)).contains( glm::vec3(P) ) );
|
||||
}
|
||||
else if ( n.type() == Handles::RESIZE_V ){
|
||||
// top & bottom
|
||||
picked = ( bb.translated(glm::vec3(0.f, +1.f, 0.f)).contains( glm::vec3(P) ) ||
|
||||
bb.translated(glm::vec3(0.f, -1.f, 0.f)).contains( glm::vec3(P) ) );
|
||||
}
|
||||
else if ( n.type() == Handles::ROTATE ){
|
||||
// TODO Picking Rotation
|
||||
}
|
||||
|
||||
if ( picked )
|
||||
// add this surface to the nodes picked
|
||||
nodes_.push_back( std::pair(&n, glm::vec2(P)) );
|
||||
|
||||
}
|
||||
|
||||
void PickingVisitor::visit(LineSquare &)
|
||||
{
|
||||
// apply inverse transform to the point of interest
|
||||
|
||||
Reference in New Issue
Block a user