|
@@ -6,7 +6,7 @@
|
|
|
#include <igl/writeOFF.h>
|
|
|
#include <igl/readWRL.h>
|
|
|
#include <igl/report_gl_error.h>
|
|
|
-#include <igl/triangulate.h>
|
|
|
+#include <igl/polygon_mesh_to_triangle_mesh.h>
|
|
|
#include <igl/readOFF.h>
|
|
|
#include <igl/readMESH.h>
|
|
|
#include <igl/draw_mesh.h>
|
|
@@ -19,7 +19,6 @@
|
|
|
#include <igl/trackball.h>
|
|
|
#include <igl/snap_to_canonical_view_quat.h>
|
|
|
#include <igl/REDRUM.h>
|
|
|
-#include <igl/Camera.h>
|
|
|
#include <igl/ReAntTweakBar.h>
|
|
|
#include <igl/get_seconds.h>
|
|
|
#include <igl/jet.h>
|
|
@@ -31,7 +30,7 @@
|
|
|
//#include <igl/embree/orient_outward_ao.h>
|
|
|
#include <igl/unique_simplices.h>
|
|
|
#include <igl/C_STR.h>
|
|
|
-#include <igl/write.h>
|
|
|
+#include <igl/write_triangle_mesh.h>
|
|
|
|
|
|
#include <Eigen/Core>
|
|
|
#include <Eigen/Geometry>
|
|
@@ -57,6 +56,14 @@
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
+struct Camera
|
|
|
+{
|
|
|
+ Eigen::Vector3d pan;
|
|
|
+ Eigen::Quaterniond rotation;
|
|
|
+ double zoom;
|
|
|
+ double angle;
|
|
|
+ Camera():pan(0,0,0),rotation(1,0,0,0),zoom(1),angle(25){}
|
|
|
+};
|
|
|
|
|
|
// Initialize shadow textures. Should be called on reshape()
|
|
|
//
|
|
@@ -89,9 +96,9 @@ bool initialize_shadows(
|
|
|
glGenTextures(1, &shadowMapTexture);
|
|
|
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
|
|
|
glTexImage2D(
|
|
|
- GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
|
|
|
+ GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
|
|
|
factor*windowWidth,
|
|
|
- factor*windowHeight,
|
|
|
+ factor*windowHeight,
|
|
|
0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
@@ -103,16 +110,16 @@ bool initialize_shadows(
|
|
|
glGenFramebuffersEXT(1, &fbo);
|
|
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
|
|
|
glFramebufferTexture2DEXT(
|
|
|
- GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D,
|
|
|
+ GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D,
|
|
|
shadowMapTexture,0);
|
|
|
// Attach color render buffer
|
|
|
glGenRenderbuffersEXT(1,&cfbo);
|
|
|
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,cfbo);
|
|
|
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8,
|
|
|
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8,
|
|
|
factor*windowWidth, factor*windowHeight);
|
|
|
//-------------------------
|
|
|
//Attach color buffer to FBO
|
|
|
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
|
|
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
|
|
GL_RENDERBUFFER_EXT, cfbo);
|
|
|
//-------------------------
|
|
|
//Does the GPU support current FBO configuration?
|
|
@@ -140,7 +147,7 @@ struct Mesh
|
|
|
Eigen::MatrixXi F;
|
|
|
Eigen::Affine3d a,da;
|
|
|
Mesh():V(),N(),F(),a(Eigen::Affine3d::Identity()),da(Eigen::Affine3d::Identity())
|
|
|
- {
|
|
|
+ {
|
|
|
using namespace Eigen;
|
|
|
Quaterniond r(Eigen::Vector4d::Random());
|
|
|
Quaterniond i(1,0,0,0);
|
|
@@ -154,7 +161,7 @@ std::vector<Mesh> meshes;
|
|
|
|
|
|
struct State
|
|
|
{
|
|
|
- igl::Camera camera;
|
|
|
+ ::Camera camera;
|
|
|
State():
|
|
|
camera()
|
|
|
{
|
|
@@ -175,7 +182,7 @@ std::stack<State> redo_stack;
|
|
|
|
|
|
bool is_rotating = false;
|
|
|
int down_x,down_y;
|
|
|
-igl::Camera down_camera;
|
|
|
+::Camera down_camera;
|
|
|
|
|
|
bool is_animating = false;
|
|
|
double animation_start_time = 0;
|
|
@@ -276,7 +283,7 @@ void push_lightview_camera(const Eigen::Vector4f & light_pos)
|
|
|
0,1,0);
|
|
|
}
|
|
|
|
|
|
-void push_camera(const igl::Camera & camera)
|
|
|
+void push_camera(const ::Camera & camera)
|
|
|
{
|
|
|
using namespace igl;
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
@@ -284,7 +291,7 @@ void push_camera(const igl::Camera & camera)
|
|
|
// scale, pan
|
|
|
glScaled(camera.zoom, camera.zoom, camera.zoom);
|
|
|
double mat[4*4];
|
|
|
- quat_to_mat(camera.rotation,mat);
|
|
|
+ quat_to_mat(camera.rotation.coeffs().data(),mat);
|
|
|
glMultMatrixd(mat);
|
|
|
}
|
|
|
|
|
@@ -368,7 +375,7 @@ void draw_objects()
|
|
|
draw_mesh(mesh.V,mesh.F,mesh.N);
|
|
|
glPopMatrix();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Draw a nice floor
|
|
|
glPushMatrix();
|
|
|
{
|
|
@@ -451,10 +458,10 @@ void display()
|
|
|
is_animating = false;
|
|
|
}
|
|
|
Quaterniond q;
|
|
|
- q.coeffs() =
|
|
|
+ q.coeffs() =
|
|
|
animation_to_quat.coeffs()*t + animation_from_quat.coeffs()*(1.-t);
|
|
|
q.normalize();
|
|
|
- copy(q.coeffs().data(),q.coeffs().data()+4,s.camera.rotation);
|
|
|
+ s.camera.rotation = q;
|
|
|
}
|
|
|
update_meshes();
|
|
|
|
|
@@ -496,7 +503,7 @@ void mouse_wheel(int wheel, int direction, int mouse_x, int mouse_y)
|
|
|
const double a_diff = 1.0;
|
|
|
s.camera.angle += double(direction)*a_diff;
|
|
|
const double min_angle = 15.0;
|
|
|
- s.camera.angle =
|
|
|
+ s.camera.angle =
|
|
|
min(90.0,max(min_angle,s.camera.angle));
|
|
|
}
|
|
|
}
|
|
@@ -577,7 +584,7 @@ void mouse_drag(int mouse_x, int mouse_y)
|
|
|
case ROTATION_TYPE_IGL_TRACKBALL:
|
|
|
{
|
|
|
// Rotate according to trackball
|
|
|
- igl::trackball<double>(
|
|
|
+ igl::trackball(
|
|
|
width,
|
|
|
height,
|
|
|
2.0,
|
|
@@ -591,12 +598,11 @@ void mouse_drag(int mouse_x, int mouse_y)
|
|
|
}
|
|
|
case ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP:
|
|
|
{
|
|
|
- Quaterniond down_q;
|
|
|
- copy(down_camera.rotation,down_camera.rotation+4,down_q.coeffs().data());
|
|
|
+ Quaterniond down_q = down_camera.rotation;
|
|
|
Vector3d axis(0,1,0);
|
|
|
const double speed = 2.0;
|
|
|
Quaterniond q;
|
|
|
- q = down_q *
|
|
|
+ q = down_q *
|
|
|
Quaterniond(
|
|
|
AngleAxisd(
|
|
|
M_PI*((double)(mouse_x-down_x))/(double)width*speed/2.0,
|
|
@@ -607,7 +613,7 @@ void mouse_drag(int mouse_x, int mouse_y)
|
|
|
const double speed = 2.0;
|
|
|
if(axis.norm() != 0)
|
|
|
{
|
|
|
- q =
|
|
|
+ q =
|
|
|
Quaterniond(
|
|
|
AngleAxisd(
|
|
|
M_PI*(mouse_y-down_y)/(double)width*speed/2.0,
|
|
@@ -615,7 +621,7 @@ void mouse_drag(int mouse_x, int mouse_y)
|
|
|
q.normalize();
|
|
|
}
|
|
|
}
|
|
|
- copy(q.coeffs().data(),q.coeffs().data()+4,s.camera.rotation);
|
|
|
+ s.camera.rotation = q;
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
@@ -688,7 +694,7 @@ void key(unsigned char key, int mouse_x, int mouse_y)
|
|
|
}else
|
|
|
{
|
|
|
push_undo();
|
|
|
- igl::snap_to_canonical_view_quat<double>(
|
|
|
+ igl::snap_to_canonical_view_quat(
|
|
|
s.camera.rotation,
|
|
|
1.0,
|
|
|
s.camera.rotation);
|
|
@@ -708,11 +714,11 @@ void TW_CALL set_rotation_type(const void * value, void * clientData)
|
|
|
using namespace igl;
|
|
|
const RotationType old_rotation_type = rotation_type;
|
|
|
rotation_type = *(const RotationType *)(value);
|
|
|
- if(rotation_type == ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP &&
|
|
|
+ if(rotation_type == ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP &&
|
|
|
old_rotation_type != ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP)
|
|
|
{
|
|
|
push_undo();
|
|
|
- copy(s.camera.rotation,s.camera.rotation+4,animation_from_quat.coeffs().data());
|
|
|
+ animation_from_quat = s.camera.rotation;
|
|
|
const Vector3d up = animation_from_quat.matrix() * Vector3d(0,1,0);
|
|
|
Vector3d proj_up(0,up(1),up(2));
|
|
|
if(proj_up.norm() == 0)
|
|
@@ -808,7 +814,7 @@ int main(int argc, char * argv[])
|
|
|
{
|
|
|
return 1;
|
|
|
}
|
|
|
- triangulate(vF,mesh.F);
|
|
|
+ polygon_mesh_to_triangle_mesh(vF,mesh.F);
|
|
|
}
|
|
|
init_mesh(mesh);
|
|
|
}
|
|
@@ -825,7 +831,7 @@ int main(int argc, char * argv[])
|
|
|
rebar.TwNewBar("bar");
|
|
|
TwDefine("bar label='Shadow Mapping' size='200 550' text=light alpha='200' color='68 68 68'");
|
|
|
rebar.TwAddVarRW("camera_zoom", TW_TYPE_DOUBLE,&s.camera.zoom,"");
|
|
|
- rebar.TwAddVarRW("camera_rotation", TW_TYPE_QUAT4D,s.camera.rotation,"");
|
|
|
+ rebar.TwAddVarRW("camera_rotation", TW_TYPE_QUAT4D,s.camera.rotation.coeffs().data(),"");
|
|
|
TwType RotationTypeTW = ReTwDefineEnumFromString("RotationType","igl_trackball,two_axis_fixed_up");
|
|
|
rebar.TwAddVarCB( "rotation_type", RotationTypeTW,
|
|
|
set_rotation_type,get_rotation_type,NULL,"keyIncr=] keyDecr=[");
|
|
@@ -834,7 +840,7 @@ int main(int argc, char * argv[])
|
|
|
rebar.load(REBAR_NAME);
|
|
|
|
|
|
animation_from_quat = Quaterniond(1,0,0,0);
|
|
|
- copy(s.camera.rotation,s.camera.rotation+4,animation_to_quat.coeffs().data());
|
|
|
+ animation_from_quat = s.camera.rotation;
|
|
|
animation_start_time = get_seconds();
|
|
|
|
|
|
// Init antweakbar
|