Subversion Repositories gelsvn

Rev

Rev 594 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 594 Rev 623
Line 4... Line 4...
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
#include "gel_glu.h"
7
#include "gel_glu.h"
8
#include "GLViewController.h"
8
#include "GLViewController.h"
-
 
9
#include "../CGLA/Mat3x3f.h"
9
 
10
 
10
using namespace std;
11
using namespace std;
11
using namespace CGLA;
12
using namespace CGLA;
12
 
13
 
13
namespace GLGraphics
14
namespace GLGraphics
Line 101... Line 102...
101
    znear = 0.01f*rad;
102
    znear = 0.01f*rad;
102
    zfar = 3*rad;
103
    zfar = 3*rad;
103
    reset_projection();
104
    reset_projection();
104
  }
105
  }
105
 
106
 
-
 
107
  void GLViewController::set_view_param(const Vec3f& e, const Vec3f& c, const Vec3f& u)
-
 
108
  {
-
 
109
    // native viewing direction is the negative z-axis
-
 
110
    // while right is the x-axis and up is the y-axis
-
 
111
    Vec3f view = c - e;
-
 
112
    float eye_dist = length(view);
-
 
113
    view /= eye_dist;
-
 
114
    Vec3f right = normalize(cross(view, u));
-
 
115
    Vec3f up = cross(right, view);
-
 
116
    Mat3x3f rot(right, up, -view);
-
 
117
    rot = transpose(rot); // since matrix is row-major
-
 
118
 
-
 
119
    // convert the change-of-basis matrix to a quaternion
-
 
120
    Quatf qrot;
-
 
121
    qrot.make_rot(rot);
-
 
122
    set_rotation(qrot);
-
 
123
    set_centre(c);
-
 
124
    set_eye_dist(eye_dist);
-
 
125
  }
-
 
126
 
106
  bool GLViewController::load(std::ifstream& ifs)
127
  bool GLViewController::load(std::ifstream& ifs)
107
  {
128
  {
108
    if(ifs)
129
    if(ifs)
109
    {
130
    {
110
      ifs.read(reinterpret_cast<char*>(this), sizeof(GLViewController));
131
      ifs.read(reinterpret_cast<char*>(this), sizeof(GLViewController));
Line 112... Line 133...
112
      ball.set_screen_window(WINX, WINY);
133
      ball.set_screen_window(WINX, WINY);
113
      return true;
134
      return true;
114
    }
135
    }
115
    return false;
136
    return false;
116
  }
137
  }
-
 
138
 
117
  bool GLViewController::save(std::ofstream& ofs) const
139
  bool GLViewController::save(std::ofstream& ofs) const
118
  {
140
  {
119
    if(ofs)
141
    if(ofs)
120
    {
142
    {
121
      ofs.write(reinterpret_cast<const char*>(this), sizeof(GLViewController));
143
      ofs.write(reinterpret_cast<const char*>(this), sizeof(GLViewController));