GLMを使うと、「glm::perspective関数」のようなもので行列を作ることができるが、
gluLookAt関数に対応するものがなさそう。
これを作るとこんな感じになる
glm::mat4x4 myBuildLookAtMatf(GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ,
GLfloat centerX, GLfloat centerY, GLfloat centerZ,
GLfloat upX, GLfloat upY, GLfloat upZ)
{
glm::vec3 target(centerX, centerY, centerZ);
glm::vec3 eye(eyeX, eyeY, eyeZ);
glm::vec3 up(upX, upY, upZ);
glm::vec3 f(glm::normalize(target-eye)),
s(glm::normalize(glm::cross(f, glm::normalize(up)))),
u(glm::normalize(glm::cross(s, f)));
glm::mat4 m(s[0], s[1], s[2], 0,
u[0], u[1], u[2], 0,
-f[0], -f[1], -f[2], 0,
0, 0, 0, 1);
return glm::translate<float>(glm::inverse(m), -eye);
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION); //行列モード切替
glLoadIdentity(); //行列初期化
glm::mat4x4 proj = glm::perspective<float>(30,float(w)/h,1,100);
glMultMatrixf(&proj[0][0]);
glMatrixMode(GL_MODELVIEW); //行列モード切替
glLoadIdentity();
//gluLookAt関数の代わり
glm::mat4x4 lookAtM = myBuildLookAtMatf(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glMultMatrixf(&lookAtM[0][0]);//行列を演算
}
▲計算方法は定義通りそのままを記述