glm::lookAt

template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> lookAt(tvec3<T, P> const & eye, tvec3<T, P> const & center, tvec3<T, P> const & up)
{
#  if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED
return lookAtLH(eye, center, up);
#  else
return lookAtRH(eye, center, up);
#  endif
}

template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> lookAtRH
(
tvec3<T, P> const & eye,
tvec3<T, P> const & center,
tvec3<T, P> const & up
)
{
tvec3<T, P> const f(normalize(center – eye));
tvec3<T, P> const s(normalize(cross(f, up)));
tvec3<T, P> const u(cross(s, f));

tmat4x4<T, P> Result(1);
Result[0][0] = s.x;
Result[1][0] = s.y;
Result[2][0] = s.z;
Result[0][1] = u.x;
Result[1][1] = u.y;
Result[2][1] = u.z;
Result[0][2] =-f.x;
Result[1][2] =-f.y;
Result[2][2] =-f.z;
Result[3][0] =-dot(s, eye);
Result[3][1] =-dot(u, eye);
Result[3][2] = dot(f, eye);
return Result;
}

template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> lookAtLH
(
tvec3<T, P> const & eye,
tvec3<T, P> const & center,
tvec3<T, P> const & up
)
{
tvec3<T, P> const f(normalize(center – eye));
tvec3<T, P> const s(normalize(cross(up, f)));
tvec3<T, P> const u(cross(f, s));

tmat4x4<T, P> Result(1);
Result[0][0] = s.x;
Result[1][0] = s.y;
Result[2][0] = s.z;
Result[0][1] = u.x;
Result[1][1] = u.y;
Result[2][1] = u.z;
Result[0][2] = f.x;
Result[1][2] = f.y;
Result[2][2] = f.z;
Result[3][0] = -dot(s, eye);
Result[3][1] = -dot(u, eye);
Result[3][2] = -dot(f, eye);
return Result;
}

Projection Matrix

Orthographic Projection

OpenGL Orthographic Volume and NDC

ortho_matrix

template <typename T>
 GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> ortho
 (
  T left,
  T right,
  T bottom,
  T top,
  T zNear,
  T zFar
 )
 {
  tmat4x4<T, defaultp> Result(1);
  Result[0][0] = static_cast<T>(2) / (right - left);
  Result[1][1] = static_cast<T>(2) / (top - bottom);
  Result[2][2] = - static_cast<T>(2) / (zFar - zNear);
  Result[3][0] = - (right + left) / (right - left);
  Result[3][1] = - (top + bottom) / (top - bottom);
  Result[3][2] = - (zFar + zNear) / (zFar - zNear);
  return Result;
 }

Perspective Projection

frustum

 template <typename T>
 GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> frustum
 (
  T left,
  T right,
  T bottom,
  T top,
  T nearVal,
  T farVal
 )
 {
  tmat4x4<T, defaultp> Result(0);
  Result[0][0] = (static_cast<T>(2) * nearVal) / (right - left);
  Result[1][1] = (static_cast<T>(2) * nearVal) / (top - bottom);
  Result[2][0] = (right + left) / (right - left);
  Result[2][1] = (top + bottom) / (top - bottom);
  Result[2][2] = -(farVal + nearVal) / (farVal - nearVal);
  Result[2][3] = static_cast<T>(-1);
  Result[3][2] = -(static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal);
  return Result;
 }

OpenGL Perspective Projection Matrix

http://www.songho.ca/opengl/gl_projectionmatrix.html

HW5

lab8-GeometryPositionColorHierachicalTransformation 에서 제공하는 클래스를 이용하여, 본인이 원하는 3차원 객체를 2~3개 만들어서 하나의 장면(예: 본인 이름 등)을 만든다.

그리고 lab9-GeometryPositionColorOrientation에서 사용한 orientation을 참고하여 transformation matrix를 사용한 animation 움직임을 넣는다. (Due by 11/9) (10점)

-your 3D hierachical transformation geometry object (eg. your name, spaceship, etc) & scene 를 만들어서 장면을 완성하고 움직임을 추가

GeometryPositionColorOrientation

lab9-GeometryPositionColorOrientation

 

// Yaw/Pitch/Roll -> Rotation Matrix

glm::yawPitchRoll(yaw, pitch, roll) ;

float yaw,   // by y-axis (in radians)

float pitch,   // by x-axis (in radians)

float roll  // by z-axis (in radians)

 

//R1 != R2

glm::mat4 R1, R2, Rx, Ry, Rz;

Ry = glm::rotate(glm::mat4(1), 60, glm::vec3(0, 1, 0));

Rx = glm::rotate(glm::mat4(1), 30, glm::vec3(1, 0, 0));

Rz = glm::rotate(glm::mat4(1), 45, glm::vec3(0, 0, 1));

R1 = Ry * Rx * Rz;

R2 = glm::yawPitchRoll(60, 30, 45);