Browse Source

fixed bug in camera and better parameterization of draw floor

Former-commit-id: 42f1a38255ecc5f70deeb6f594dac7811c084d72
Alec Jacobson (jalec 11 years ago
parent
commit
ccbdc48e71

+ 4 - 0
examples/multi-viewport/example.cpp

@@ -131,6 +131,10 @@ void reshape_viewports()
   viewports[1].reshape(         0,eff_h*height,     eff_v*width,(1.-eff_h)*height);
   viewports[2].reshape(         0,           0,     eff_v*width,eff_h*height);
   viewports[3].reshape(eff_v*width,           0,(1.-eff_v)*width,eff_h*height);
+  for(auto & vp : viewports)
+  {
+    vp.camera.m_aspect = (double)vp.width/(double)vp.height;
+  }
 }
 
 void reshape(int width,int height)

+ 6 - 4
examples/quicklook-mesh/Makefile

@@ -2,10 +2,12 @@
 
 # Seems that we unfortunately must use llvm or else we get issues trying to
 # include the Foundation headers
-%CXX=llvm-g++
-%C=llvm-gcc
-CXX=clang++-mp-3.4
-C=clang-mp-3.4
+#CXX=llvm-g++
+#C=llvm-gcc
+CXX=clang++
+C=clang
+#CXX=clang++-mp-3.4
+#C=clang-mp-3.4
 CXXFLAGS += -stdlib=libc++ -std=c++11
 
 EIGEN=/opt/local/include/eigen3/

+ 7 - 1
include/igl/Camera.h

@@ -351,8 +351,14 @@ inline void igl::Camera::look_at(
   Quaterniond a,b;
   a.setFromTwoVectors(Vector3d(0,0,-1),-F);
   b.setFromTwoVectors(a*Vector3d(0,1,0),proj_up);
-  m_rotation_conj = (a*b).conjugate();
+  m_rotation_conj = (b*a).conjugate();
   m_translation = m_rotation_conj * eye;
+  //cout<<"m_at_dist: "<<m_at_dist<<endl;
+  //cout<<"proj_up: "<<proj_up.transpose()<<endl;
+  //cout<<"F: "<<F.transpose()<<endl;
+  //cout<<"eye(): "<<this->eye().transpose()<<endl;
+  //cout<<"at(): "<<this->at().transpose()<<endl;
+  //cout<<"eye()-at(): "<<(this->eye()-this->at()).normalized().transpose()<<endl;
   assert(           (eye-this->eye()).squaredNorm() < DOUBLE_EPS);
   assert((F-(this->eye()-this->at()).normalized()).squaredNorm() < 
     DOUBLE_EPS);

+ 10 - 6
include/igl/draw_floor.cpp

@@ -10,12 +10,12 @@
 
 #include "OpenGL_convenience.h"
 
-static const int GridSizeX = 100;
-static const int GridSizeY = 100;
-static const float SizeX = 0.5f;
-static const float SizeY = 0.5f;
-IGL_INLINE void igl::draw_floor(const float * colorA, const float * colorB)
+IGL_INLINE void igl::draw_floor(const float * colorA, const float * colorB,
+  const int GridSizeX,
+  const int GridSizeY)
 {
+  const float SizeX = 0.5f*100./(double)GridSizeX;
+  const float SizeY = 0.5f*100./(double)GridSizeY;
   // old settings
   int old_lighting=0,old_color_material=0;
   glGetIntegerv(GL_LIGHTING,&old_lighting);
@@ -73,8 +73,12 @@ IGL_INLINE void igl::draw_floor()
   igl::draw_floor(grey,white);
 }
 
-IGL_INLINE void igl::draw_floor_outline(const float * colorA, const float * colorB)
+IGL_INLINE void igl::draw_floor_outline(const float * colorA, const float * colorB,
+  const int GridSizeX,
+  const int GridSizeY)
 {
+  const float SizeX = 0.5f*100./(double)GridSizeX;
+  const float SizeY = 0.5f*100./(double)GridSizeY;
   float old_line_width =0;
   // old settings
   int old_lighting=0,old_color_material=0;

+ 10 - 2
include/igl/draw_floor.h

@@ -36,10 +36,18 @@ namespace igl
   //   glPopMatrix();
   //   glDisable(GL_CULL_FACE);
   //
-  IGL_INLINE void draw_floor(const float * colorA, const float * colorB);
+  IGL_INLINE void draw_floor(
+    const float * colorA, 
+    const float * colorB, 
+    const int GridSizeX=100, 
+    const int GridSizeY=100);
   // Wrapper with default colors
   IGL_INLINE void draw_floor();
-  IGL_INLINE void draw_floor_outline(const float * colorA, const float * colorB);
+  IGL_INLINE void draw_floor_outline(
+    const float * colorA, 
+    const float * colorB, 
+    const int GridSizeX=100, 
+    const int GridSizeY=100);
   // Wrapper with default colors
   IGL_INLINE void draw_floor_outline();
 }