diff --git a/examples/rotate-widget/example.cpp b/examples/rotate-widget/example.cpp index e0136a686..4c2afbf46 100644 --- a/examples/rotate-widget/example.cpp +++ b/examples/rotate-widget/example.cpp @@ -328,7 +328,7 @@ void mouse(int glutButton, int glutState, int mouse_x, int mouse_y) is_rotating = false; break; case 0: - bool widget_using = s.widget.down(mouse_x,mouse_y); + bool widget_using = s.widget.down(mouse_x,height-mouse_y); if(widget_using) { push_undo(); @@ -385,7 +385,7 @@ void mouse_drag(int mouse_x, int mouse_y) push_scene(); push_object(); - s.widget.drag(mouse_x,mouse_y); + s.widget.drag(mouse_x,height-mouse_y); pop_object(); pop_scene(); @@ -439,7 +439,7 @@ void init_relative() Vmin = V.colwise().minCoeff(); Vmid = 0.5*(Vmax + Vmin); bbd = (Vmax-Vmin).norm(); - s.widget.pos = Vmid; + s.widget.pos = Vmin+0.3*(Vmax-Vmin); } void undo() @@ -607,7 +607,7 @@ int main(int argc, char * argv[]) // Init antweakbar glutInitDisplayString( "rgba depth double samples>=8 "); glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)/2.0); - glutCreateWindow("upright"); + glutCreateWindow("rotate-widget"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); @@ -629,6 +629,7 @@ int main(int argc, char * argv[]) }; glutTimerFunc(500, timer, 500); + s.camera.dolly_zoom(25-s.camera.m_angle); glutMainLoop(); diff --git a/examples/skeleton/example.cpp b/examples/skeleton/example.cpp index d56d24459..1f9ab6ed5 100644 --- a/examples/skeleton/example.cpp +++ b/examples/skeleton/example.cpp @@ -675,7 +675,7 @@ int main(int argc, char * argv[]) rebar.TwAddVarRW("skeleton_on_top", TW_TYPE_BOOLCPP,&skeleton_on_top,"key=O"); rebar.TwAddVarRW("wireframe", TW_TYPE_BOOLCPP,&wireframe,"key=l"); TwType SkelStyleTypeTW = ReTwDefineEnumFromString("SkelStyleType", - "3d,vector graphics"); + "3d,vector-graphics"); rebar.TwAddVarRW("style",SkelStyleTypeTW,&skel_style,"key=s"); rebar.load(REBAR_NAME); diff --git a/examples/upright/Makefile b/examples/upright/Makefile index d7336a45b..ed0b21f33 100644 --- a/examples/upright/Makefile +++ b/examples/upright/Makefile @@ -21,6 +21,8 @@ ANTTWEAKBAR_LIB=-L$(LIBIGL)/external/AntTweakBar/lib -lAntTweakBar -framework Ap INC=$(LIBIGL_INC) $(ANTTWEAKBAR_INC) $(EIGEN3_INC) LIB=$(OPENGL_LIB) $(GLUT_LIB) $(ANTTWEAKBAR_LIB) $(LIBIGL_LIB) $(CARBON_LIB) +CFLAGS+=-g + upright: upright.o g++ $(OPENMP) $(AFLAGS) $(CFLAGS) -o upright upright.o $(LIB) diff --git a/include/igl/ReAntTweakBar.cpp b/include/igl/ReAntTweakBar.cpp index 54b74d57c..ce113a4bb 100644 --- a/include/igl/ReAntTweakBar.cpp +++ b/include/igl/ReAntTweakBar.cpp @@ -125,12 +125,13 @@ namespace } IGL_INLINE igl::ReTwBar::ReTwBar(): - bar(NULL),rw_items(),cb_items() + bar(NULL),name(),rw_items(),cb_items() { } IGL_INLINE igl::ReTwBar::ReTwBar(const igl::ReTwBar & that): bar(that.bar), + name(that.name), rw_items(that.rw_items), cb_items(that.cb_items) { @@ -150,12 +151,10 @@ IGL_INLINE igl::ReTwBar & igl::ReTwBar::operator=(const igl::ReTwBar & that) // BAR WRAPPERS -IGL_INLINE void igl::ReTwBar::TwNewBar(const char *name) +IGL_INLINE void igl::ReTwBar::TwNewBar(const char * _name) { - // double colon without anything in front of it means look for this in the - // global namespace... I hope... - this->name = name; - this->bar = ::TwNewBar(name); + this->name = _name; + this->bar = ::TwNewBar(_name); } IGL_INLINE int igl::ReTwBar::TwAddVarRW( diff --git a/include/igl/RotateWidget.h b/include/igl/RotateWidget.h index eaf34c3bf..36df96bbf 100644 --- a/include/igl/RotateWidget.h +++ b/include/igl/RotateWidget.h @@ -5,16 +5,17 @@ // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. -#ifndef IGL_HEADER_ONLY -#define IGL_HEADER_ONLY -#include +#ifndef IGL_ROTATE_WIDGET_H +#define IGL_ROTATE_WIDGET_H #include +#include #include #include namespace igl { - // 3D Rotate tool widget + // 3D Rotate tool widget similar to Maya's. Works best if field of view angle + // is less than ~25. class RotateWidget { public: @@ -23,6 +24,7 @@ namespace igl inline static Eigen::Vector3d view_direction(const Eigen::Vector3d & pos); Eigen::Vector3d pos; Eigen::Quaterniond rot,down_rot; + // This line causes trouble if RotateWidget.h is included before bbw.h Eigen::Vector2d down_xy,drag_xy,down_dir; Eigen::Vector3d udown,udrag; double outer_radius_on_screen; @@ -91,10 +93,7 @@ inline Eigen::Vector3d igl::RotateWidget::view_direction(const int x, const int { using namespace Eigen; using namespace igl; - Vector4i vp; - glGetIntegerv(GL_VIEWPORT,vp.data()); - const int height = vp(3); - const Vector3d win_s(x,height-y,0), win_d(x,height-y,1); + const Vector3d win_s(x,y,0), win_d(x,y,1); const Vector3d s = unproject(win_s); const Vector3d d = unproject(win_d); return d-s; @@ -125,10 +124,8 @@ inline bool igl::RotateWidget::intersect(const int x, const int y, Eigen::Vector using namespace Eigen; using namespace igl; Vector3d view = view_direction(x,y); - Vector4i vp; - glGetIntegerv(GL_VIEWPORT,vp.data()); const Vector3d ppos = project(pos); - Vector3d uxy = unproject(Vector3d(x,vp(3)-y,ppos(2))); + Vector3d uxy = unproject(Vector3d(x,y,ppos(2))); double t0,t1; if(!ray_sphere_intersect(uxy,view,pos,unprojected_inner_radius(),t0,t1)) { @@ -150,16 +147,31 @@ inline double igl::RotateWidget::unprojected_inner_radius() return (pos-pos_off).norm(); } -inline Eigen::Vector3d igl::RotateWidget::unproject_onto(const int x, const int y) +inline Eigen::Vector3d igl::RotateWidget::unproject_onto( + const int x, + const int y) { using namespace Eigen; using namespace igl; - Vector4i vp; - glGetIntegerv(GL_VIEWPORT,vp.data()); - const Vector3d ppos = project(pos); - Vector3d uxy = unproject( Vector3d(x,vp(3)-y,ppos(2)))-pos; - uxy /= unprojected_inner_radius()*outer_over_inner*outer_over_inner; - return uxy; + // KNOWN BUG: This projects to same depths as pos. I think what we actually + // want is The intersection with the plane perpendicular to the view + // direction at pos. If the field of view angle is small then this difference + // is negligible. + //const Vector3d ppos = project(pos); + //const Vector3d uxy = unproject( Vector3d(x,y,ppos(2))); + // http://en.wikipedia.org/wiki/Line-plane_intersection + // + // Hrrmmm. There's still something wrong here if the ball's in the corner of + // the screen. Am I somehow not accounting for perspective correctly? + // + // Q: What about just projecting the circle's equation and solving for the + // distance? + const Vector3d l0 = unproject(Vector3d(x,y,0)); + const Vector3d l = unproject(Vector3d(x,y,1))-l0; + const Vector3d n = view_direction(pos); + const double t = (pos-l0).dot(n)/l.dot(n); + const Vector3d uxy = l0+t*l; + return (uxy-pos)/unprojected_inner_radius()*outer_over_inner*outer_over_inner; } inline bool igl::RotateWidget::down(const int x, const int y) @@ -189,7 +201,7 @@ inline bool igl::RotateWidget::down(const int x, const int y) const bool is_hit = intersect(down_xy(0),down_xy(1),hit); if(!is_hit) { - cout<<"~~~!is_hit"<, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&); +template void igl::draw_skeleton_3d, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&); #endif diff --git a/include/igl/draw_skeleton_vector_graphics.cpp b/include/igl/draw_skeleton_vector_graphics.cpp index 92e213778..d55b077fb 100644 --- a/include/igl/draw_skeleton_vector_graphics.cpp +++ b/include/igl/draw_skeleton_vector_graphics.cpp @@ -24,14 +24,18 @@ IGL_INLINE void igl::draw_skeleton_vector_graphics( const float * line_color) { using namespace Eigen; - glLineWidth(10.0); + int old_lighting=0; + double old_line_width=1; + glGetIntegerv(GL_LIGHTING,&old_lighting); + glGetDoublev(GL_LINE_WIDTH,&old_line_width); int cm; glGetIntegerv(GL_COLOR_MATERIAL,&cm); glDisable(GL_LIGHTING); glDisable(GL_LINE_STIPPLE); //glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_COLOR_MATERIAL); + glLineWidth(10.0); glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE); float mat_ambient[4] = {0.1,0.1,0.1,1.0}; float mat_specular[4] = {0.0,0.0,0.0,1.0}; @@ -71,6 +75,8 @@ IGL_INLINE void igl::draw_skeleton_vector_graphics( (cm ? glEnable(GL_COLOR_MATERIAL):glDisable(GL_COLOR_MATERIAL)); //glDisable(GL_POLYGON_OFFSET_FILL); glEnable(GL_LIGHTING); + (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING)); + glLineWidth(old_line_width); } template @@ -78,6 +84,17 @@ IGL_INLINE void igl::draw_skeleton_vector_graphics( const Eigen::PlainObjectBase & C, const Eigen::PlainObjectBase & BE, const Eigen::PlainObjectBase & T) +{ + return draw_skeleton_vector_graphics(C,BE,T,BBW_POINT_COLOR,BBW_LINE_COLOR); +} + +template +IGL_INLINE void igl::draw_skeleton_vector_graphics( + const Eigen::PlainObjectBase & C, + const Eigen::PlainObjectBase & BE, + const Eigen::PlainObjectBase & T, + const float * point_color, + const float * line_color) { Eigen::PlainObjectBase CT; Eigen::PlainObjectBase BET; @@ -96,7 +113,7 @@ IGL_INLINE void igl::draw_skeleton_vector_graphics( CT.row(2*e) = c0 * L + t; CT.row(2*e+1) = c1 * L + t; } - draw_skeleton_vector_graphics(CT,BET); + draw_skeleton_vector_graphics(CT,BET,point_color,line_color); } #ifndef IGL_HEADER_ONLY diff --git a/include/igl/draw_skeleton_vector_graphics.h b/include/igl/draw_skeleton_vector_graphics.h index 853431d5f..432c451d2 100644 --- a/include/igl/draw_skeleton_vector_graphics.h +++ b/include/igl/draw_skeleton_vector_graphics.h @@ -31,6 +31,13 @@ namespace igl const Eigen::MatrixXi & BE); // T #BE*(dim+1) by dim matrix of stacked transposed bone transformations template + IGL_INLINE void draw_skeleton_vector_graphics( + const Eigen::PlainObjectBase & C, + const Eigen::PlainObjectBase & BE, + const Eigen::PlainObjectBase & T, + const float * point_color, + const float * line_color); + template IGL_INLINE void draw_skeleton_vector_graphics( const Eigen::PlainObjectBase & C, const Eigen::PlainObjectBase & BE, diff --git a/include/igl/material_colors.h b/include/igl/material_colors.h index 3c6f87e6d..d14a53d43 100644 --- a/include/igl/material_colors.h +++ b/include/igl/material_colors.h @@ -7,6 +7,7 @@ // obtain one at http://mozilla.org/MPL/2.0/. #ifndef IGL_MATERIAL_COLORS_H #define IGL_MATERIAL_COLORS_H +#include // Define constant material colors for use with opengl glMaterialfv // Most of these colors come from IGL publications namespace igl diff --git a/include/igl/project.cpp b/include/igl/project.cpp index c0aed2955..5418f8088 100644 --- a/include/igl/project.cpp +++ b/include/igl/project.cpp @@ -116,6 +116,7 @@ template int igl::project, Eigen::Matrix > igl::project >(Eigen::PlainObjectBase > const&); template int igl::project, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); template Eigen::PlainObjectBase > igl::project >(Eigen::PlainObjectBase > const&); +template Eigen::PlainObjectBase > igl::project >(Eigen::PlainObjectBase > const&); #endif #endif