Transform.cpp: implementation of the Transform class C++

// Transform.cpp: implementation of the Transform class.


#include "Transform.h"
#include <iostream>

//Please implement the following functions:

// Helper rotation function.
mat3 Transform::rotate(const float degrees, const vec3& axis) {
  mat3 alongMat = mat3(
 axis.x*axis.x, axis.x*axis.y, axis.x*axis.z,
 axis.x*axis.y, axis.y*axis.y, axis.y*axis.z,
 axis.x*axis.z, axis.y*axis.z, axis.z*axis.z
  );
  mat3 perpMat = mat3(
 0, axis.z, -axis.y,
 -axis.z, 0 , axis.x,
 axis.y, -axis.x, 0
  );
  return cos(glm::radians(degrees))*mat3(1.0) + (1-cos(glm::radians(degrees)))*alongMat + sin(glm::radians(degrees))*perpMat;
}

// Transforms the camera left around the "crystal ball" interface
void Transform::left(float degrees, vec3& eye, vec3& up) {
eye = eye * rotate(degrees, up);
up = up * rotate(degrees, up);
}

// Transforms the camera up around the "crystal ball" interface
void Transform::up(float degrees, vec3& eye, vec3& up) {
vec3 pivot = glm::normalize(glm::cross(up, eye));
eye = eye * rotate(degrees, pivot);
up = up * rotate(degrees, pivot);
}

// Your implementation of the glm::lookAt matrix
mat4 Transform::lookAt(vec3 eye, vec3 up) {
vec3 a = eye/*-vec3(4.0,5.1,3.2)*/;
vec3 b = up;
// eye = glm::normalize(eye);
vec3 w = a/glm::length(a);
vec3 u = glm::cross(b,w)/glm::length(glm::cross(b,w));
vec3 v = glm::cross(w,u);
mat4 M = mat4(
vec4(u.x,v.x,w.x,0),
vec4(u.y,v.y,w.y,0),
vec4(u.z,v.z,w.z,0),
vec4(
-u.x*eye.x-u.y*eye.y-u.z*eye.z,
-v.x*eye.x-v.y*eye.y-v.z*eye.z,
-w.x*eye.x-w.y*eye.y-w.z*eye.z,
1
)
);

  return M;
}

Transform::Transform()
{

}

Transform::~Transform()
{

}


Learn More :

Learn More Multiple Choice Question :

Pages