|
@@ -16,20 +16,21 @@
|
|
#include <GLFW/glfw3.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
-#include <windows.h>
|
|
|
|
-#include <GL/glew.h>
|
|
|
|
|
|
+# include <windows.h>
|
|
|
|
+# undef max
|
|
|
|
+# undef min
|
|
|
|
+# include <GL/glew.h>
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#include <cmath>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <cstdio>
|
|
-#include <string>
|
|
|
|
#include <sstream>
|
|
#include <sstream>
|
|
#include <iomanip>
|
|
#include <iomanip>
|
|
|
|
+#include <iostream>
|
|
|
|
+#include <fstream>
|
|
|
|
|
|
#include <algorithm>
|
|
#include <algorithm>
|
|
|
|
|
|
-using namespace std;
|
|
|
|
-
|
|
|
|
//OK NV
|
|
//OK NV
|
|
Eigen::Vector3f project(const Eigen::Vector3f& obj,
|
|
Eigen::Vector3f project(const Eigen::Vector3f& obj,
|
|
const Eigen::Matrix4f& model,
|
|
const Eigen::Matrix4f& model,
|
|
@@ -154,15 +155,9 @@ Eigen::Matrix4f translate(
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-// Undef Visual Studio macros...
|
|
|
|
-#undef max
|
|
|
|
-#undef min
|
|
|
|
-
|
|
|
|
#include <limits>
|
|
#include <limits>
|
|
#include <cassert>
|
|
#include <cassert>
|
|
|
|
|
|
-#define IGL_HEADER_ONLY
|
|
|
|
-
|
|
|
|
#ifdef ENABLE_XML_SERIALIZATION
|
|
#ifdef ENABLE_XML_SERIALIZATION
|
|
#include "igl/xml/XMLSerializer.h"
|
|
#include "igl/xml/XMLSerializer.h"
|
|
#endif
|
|
#endif
|
|
@@ -320,20 +315,26 @@ static TextRenderer __font_renderer;
|
|
|
|
|
|
static void glfw_mouse_press(GLFWwindow* window, int button, int action, int modifier)
|
|
static void glfw_mouse_press(GLFWwindow* window, int button, int action, int modifier)
|
|
{
|
|
{
|
|
- if (!TwEventMouseButtonGLFW(button, action))
|
|
|
|
- {
|
|
|
|
- igl::Viewer::MouseButton mb;
|
|
|
|
- if (button == GLFW_MOUSE_BUTTON_1)
|
|
|
|
- mb = igl::Viewer::IGL_LEFT;
|
|
|
|
- else if (button == GLFW_MOUSE_BUTTON_2)
|
|
|
|
- mb = igl::Viewer::IGL_RIGHT;
|
|
|
|
- else //if (button == GLFW_MOUSE_BUTTON_3)
|
|
|
|
- mb = igl::Viewer::IGL_MIDDLE;
|
|
|
|
|
|
+ bool tw_used = TwEventMouseButtonGLFW(button, action);
|
|
|
|
+ igl::Viewer::MouseButton mb;
|
|
|
|
|
|
- if (action == GLFW_PRESS)
|
|
|
|
|
|
+ if (button == GLFW_MOUSE_BUTTON_1)
|
|
|
|
+ mb = igl::Viewer::IGL_LEFT;
|
|
|
|
+ else if (button == GLFW_MOUSE_BUTTON_2)
|
|
|
|
+ mb = igl::Viewer::IGL_RIGHT;
|
|
|
|
+ else //if (button == GLFW_MOUSE_BUTTON_3)
|
|
|
|
+ mb = igl::Viewer::IGL_MIDDLE;
|
|
|
|
+
|
|
|
|
+ if (action == GLFW_PRESS)
|
|
|
|
+ {
|
|
|
|
+ if(!tw_used)
|
|
|
|
+ {
|
|
__viewer->mouse_down(mb,modifier);
|
|
__viewer->mouse_down(mb,modifier);
|
|
- else
|
|
|
|
- __viewer->mouse_up(mb,modifier);
|
|
|
|
|
|
+ }
|
|
|
|
+ } else
|
|
|
|
+ {
|
|
|
|
+ // Always call mouse_up on up
|
|
|
|
+ __viewer->mouse_up(mb,modifier);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -509,16 +510,34 @@ static void glfw_window_size(GLFWwindow* window, int width, int height)
|
|
__viewer->resize(w, h);
|
|
__viewer->resize(w, h);
|
|
|
|
|
|
TwWindowSize(w, h);
|
|
TwWindowSize(w, h);
|
|
|
|
+ const auto & bar = __viewer->bar;
|
|
|
|
+ // Keep AntTweakBar on right side of screen and height == opengl height
|
|
|
|
+ // get the current position of a bar
|
|
|
|
+ int size[2];
|
|
|
|
+ TwGetParam(bar, NULL, "size", TW_PARAM_INT32, 2, size);
|
|
|
|
+ int pos[2];
|
|
|
|
+ // Place bar on left side of opengl rect (padded by 10 pixels)
|
|
|
|
+ pos[0] = 10;//max(10,(int)width - size[0] - 10);
|
|
|
|
+ // place bar at top (padded by 10 pixels)
|
|
|
|
+ pos[1] = 10;
|
|
|
|
+ // Set height to new height of window (padded by 10 pixels on bottom)
|
|
|
|
+ size[1] = height-pos[1]-10;
|
|
|
|
+ TwSetParam(bar, NULL, "position", TW_PARAM_INT32, 2, pos);
|
|
|
|
+ TwSetParam(bar, NULL, "size", TW_PARAM_INT32, 2,size);
|
|
}
|
|
}
|
|
|
|
|
|
static void glfw_mouse_move(GLFWwindow* window, double x, double y)
|
|
static void glfw_mouse_move(GLFWwindow* window, double x, double y)
|
|
{
|
|
{
|
|
- if (!TwEventMousePosGLFW(x*highdpi,y*highdpi))
|
|
|
|
|
|
+ if(!TwEventMousePosGLFW(x*highdpi,y*highdpi) || __viewer->down)
|
|
|
|
+ {
|
|
|
|
+ // Call if TwBar hasn't used or if down
|
|
__viewer->mouse_move(x*highdpi, y*highdpi);
|
|
__viewer->mouse_move(x*highdpi, y*highdpi);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
static void glfw_mouse_scroll(GLFWwindow* window, double x, double y)
|
|
static void glfw_mouse_scroll(GLFWwindow* window, double x, double y)
|
|
{
|
|
{
|
|
|
|
+ using namespace std;
|
|
scroll_x += x;
|
|
scroll_x += x;
|
|
scroll_y += y;
|
|
scroll_y += y;
|
|
|
|
|
|
@@ -636,7 +655,7 @@ namespace igl
|
|
options.line_color << 0.0f, 0.0f, 0.0f;
|
|
options.line_color << 0.0f, 0.0f, 0.0f;
|
|
|
|
|
|
// Default lights settings
|
|
// Default lights settings
|
|
- options.light_position << 0.0f, 0.30f, 5.0f;
|
|
|
|
|
|
+ options.light_position << 0.0f, -0.30f, -5.0f;
|
|
|
|
|
|
// Default trackball
|
|
// Default trackball
|
|
options.trackball_angle << 0.0f, 0.0f, 0.0f, 1.0f;
|
|
options.trackball_angle << 0.0f, 0.0f, 0.0f, 1.0f;
|
|
@@ -814,8 +833,8 @@ namespace igl
|
|
data.dirty |= DIRTY_TEXTURE;
|
|
data.dirty |= DIRTY_TEXTURE;
|
|
}
|
|
}
|
|
|
|
|
|
- int size = 128;
|
|
|
|
- int size2 = size/2;
|
|
|
|
|
|
+ unsigned size = 128;
|
|
|
|
+ unsigned size2 = size/2;
|
|
data.texture_R.resize(size, size);
|
|
data.texture_R.resize(size, size);
|
|
for (unsigned i=0; i<size; ++i)
|
|
for (unsigned i=0; i<size; ++i)
|
|
{
|
|
{
|
|
@@ -1039,7 +1058,7 @@ namespace igl
|
|
mouse_x,
|
|
mouse_x,
|
|
mouse_y,
|
|
mouse_y,
|
|
options.trackball_angle.data());
|
|
options.trackball_angle.data());
|
|
- Eigen::Vector4f snapq = options.trackball_angle;
|
|
|
|
|
|
+ //Eigen::Vector4f snapq = options.trackball_angle;
|
|
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -1057,6 +1076,7 @@ namespace igl
|
|
}
|
|
}
|
|
case ZOOM:
|
|
case ZOOM:
|
|
{
|
|
{
|
|
|
|
+ //float delta = 0.001f * (mouse_x - down_mouse_x + mouse_y - down_mouse_y);
|
|
float delta = 0.001f * (mouse_x - down_mouse_x + mouse_y - down_mouse_y);
|
|
float delta = 0.001f * (mouse_x - down_mouse_x + mouse_y - down_mouse_y);
|
|
options.camera_zoom *= 1 + delta;
|
|
options.camera_zoom *= 1 + delta;
|
|
down_mouse_x = mouse_x;
|
|
down_mouse_x = mouse_x;
|
|
@@ -1084,13 +1104,19 @@ namespace igl
|
|
if (plugin_manager->plugin_list[i]->mouse_scroll(delta_y))
|
|
if (plugin_manager->plugin_list[i]->mouse_scroll(delta_y))
|
|
return true;
|
|
return true;
|
|
|
|
|
|
- float mult = (delta_y>0)?1.1:0.9;
|
|
|
|
- options.camera_zoom = (options.camera_zoom * mult > 0.1f ? options.camera_zoom * mult : 0.1f);
|
|
|
|
|
|
+ // Only zoom if there's actually a change
|
|
|
|
+ if(delta_y != 0)
|
|
|
|
+ {
|
|
|
|
+ float mult = (1.0+((delta_y>0)?1.:-1.)*0.05);
|
|
|
|
+ const float min_zoom = 0.1f;
|
|
|
|
+ options.camera_zoom = (options.camera_zoom * mult > min_zoom ? options.camera_zoom * mult : min_zoom);
|
|
|
|
+ }
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
static GLuint create_shader_helper(GLint type, const std::string &shader_string)
|
|
static GLuint create_shader_helper(GLint type, const std::string &shader_string)
|
|
{
|
|
{
|
|
|
|
+ using namespace std;
|
|
if (shader_string.empty())
|
|
if (shader_string.empty())
|
|
return (GLuint) 0;
|
|
return (GLuint) 0;
|
|
|
|
|
|
@@ -1150,6 +1176,7 @@ namespace igl
|
|
const std::string &geometry_shader_string,
|
|
const std::string &geometry_shader_string,
|
|
int geometry_shader_max_vertices)
|
|
int geometry_shader_max_vertices)
|
|
{
|
|
{
|
|
|
|
+ using namespace std;
|
|
vertex_shader = create_shader_helper(GL_VERTEX_SHADER, vertex_shader_string);
|
|
vertex_shader = create_shader_helper(GL_VERTEX_SHADER, vertex_shader_string);
|
|
geometry_shader = create_shader_helper(GL_GEOMETRY_SHADER, geometry_shader_string);
|
|
geometry_shader = create_shader_helper(GL_GEOMETRY_SHADER, geometry_shader_string);
|
|
fragment_shader = create_shader_helper(GL_FRAGMENT_SHADER, fragment_shader_string);
|
|
fragment_shader = create_shader_helper(GL_FRAGMENT_SHADER, fragment_shader_string);
|
|
@@ -1722,6 +1749,8 @@ namespace igl
|
|
|
|
|
|
void Viewer::draw()
|
|
void Viewer::draw()
|
|
{
|
|
{
|
|
|
|
+ using namespace std;
|
|
|
|
+ using namespace Eigen;
|
|
glClearColor(options.background_color[0],
|
|
glClearColor(options.background_color[0],
|
|
options.background_color[1],
|
|
options.background_color[1],
|
|
options.background_color[2],
|
|
options.background_color[2],
|
|
@@ -1802,7 +1831,8 @@ namespace igl
|
|
GLint texture_factori = opengl.shader_mesh.uniform("texture_factor");
|
|
GLint texture_factori = opengl.shader_mesh.uniform("texture_factor");
|
|
|
|
|
|
glUniform1f(specular_exponenti, options.shininess);
|
|
glUniform1f(specular_exponenti, options.shininess);
|
|
- glUniform3fv(light_position_worldi, 1, options.light_position.data());
|
|
|
|
|
|
+ Vector3f rev_light = -1.*options.light_position;
|
|
|
|
+ glUniform3fv(light_position_worldi, 1, rev_light.data());
|
|
glUniform1f(lighting_factori, 1.0f); // enables lighting
|
|
glUniform1f(lighting_factori, 1.0f); // enables lighting
|
|
glUniform4f(fixed_colori, 0.0, 0.0, 0.0, 0.0);
|
|
glUniform4f(fixed_colori, 0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
@@ -2107,6 +2137,7 @@ namespace igl
|
|
// Helpers that draws the most common meshes
|
|
// Helpers that draws the most common meshes
|
|
void Viewer::draw_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F)
|
|
void Viewer::draw_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F)
|
|
{
|
|
{
|
|
|
|
+ using namespace std;
|
|
if (data.V.rows() == 0 && data.F.rows() == 0)
|
|
if (data.V.rows() == 0 && data.F.rows() == 0)
|
|
{
|
|
{
|
|
clear_mesh();
|
|
clear_mesh();
|
|
@@ -2137,6 +2168,7 @@ namespace igl
|
|
|
|
|
|
void Viewer::draw_normals(const Eigen::MatrixXd& N)
|
|
void Viewer::draw_normals(const Eigen::MatrixXd& N)
|
|
{
|
|
{
|
|
|
|
+ using namespace std;
|
|
if (N.rows() == data.V.rows())
|
|
if (N.rows() == data.V.rows())
|
|
{
|
|
{
|
|
options.face_based = false;
|
|
options.face_based = false;
|
|
@@ -2154,6 +2186,7 @@ namespace igl
|
|
|
|
|
|
void Viewer::draw_colors(Eigen::MatrixXd C)
|
|
void Viewer::draw_colors(Eigen::MatrixXd C)
|
|
{
|
|
{
|
|
|
|
+ using namespace std;
|
|
if (C.rows() == 1)
|
|
if (C.rows() == 1)
|
|
{
|
|
{
|
|
for (unsigned i=0;i<data.V_material_diffuse.rows();++i)
|
|
for (unsigned i=0;i<data.V_material_diffuse.rows();++i)
|
|
@@ -2179,6 +2212,7 @@ namespace igl
|
|
|
|
|
|
void Viewer::draw_UV(const Eigen::MatrixXd& UV)
|
|
void Viewer::draw_UV(const Eigen::MatrixXd& UV)
|
|
{
|
|
{
|
|
|
|
+ using namespace std;
|
|
if (UV.rows() == data.V.rows())
|
|
if (UV.rows() == data.V.rows())
|
|
{
|
|
{
|
|
options.face_based = false;
|
|
options.face_based = false;
|
|
@@ -2233,7 +2267,7 @@ namespace igl
|
|
data.labels_strings.push_back(str);
|
|
data.labels_strings.push_back(str);
|
|
}
|
|
}
|
|
|
|
|
|
- void Viewer::launch(string filename)
|
|
|
|
|
|
+ void Viewer::launch(std::string filename)
|
|
{
|
|
{
|
|
GLFWwindow* window;
|
|
GLFWwindow* window;
|
|
|
|
|
|
@@ -2255,12 +2289,11 @@ namespace igl
|
|
}
|
|
}
|
|
glfwMakeContextCurrent(window);
|
|
glfwMakeContextCurrent(window);
|
|
|
|
|
|
- int major, minor, rev;
|
|
|
|
- major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
|
|
|
|
- minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
|
|
|
|
- rev = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
|
|
|
|
-
|
|
|
|
#ifdef DEBUG
|
|
#ifdef DEBUG
|
|
|
|
+ int major, minor, rev;
|
|
|
|
+ major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
|
|
|
|
+ minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
|
|
|
|
+ rev = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
|
|
printf("OpenGL version recieved: %d.%d.%d\n", major, minor, rev);
|
|
printf("OpenGL version recieved: %d.%d.%d\n", major, minor, rev);
|
|
printf("Supported OpenGL is %s\n", (const char*)glGetString(GL_VERSION));
|
|
printf("Supported OpenGL is %s\n", (const char*)glGetString(GL_VERSION));
|
|
printf("Supported GLSL is %s\n", (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
|
|
printf("Supported GLSL is %s\n", (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
|