glm::mat4 Camera::GetViewMatrix() const { return glm::inverse(GetTransformationMatrix()); }
glm::vec3 position_; //translation vector (tx,ty,tz) glm::quat rotation_; //quat (w,x,y,z) glm::vec3 scale_; //scale(scale_x,scale_y,scale_z)
glm::mat4 Transform::GetTransformationMatrix() const { glm::mat4 trans_mat = glm::scale(glm::mat4_cast(rotation_), scale_); trans_mat[3][0] = position_.x; trans_mat[3][1] = position_.y; trans_mat[3][2] = position_.z; glm::mat4 parent_mat = glm::mat4(1.0f); if (parent_ != NULL) { parent_mat = parent_->GetTransformationMatrix(); trans_mat = parent_mat * trans_mat; } return trans_mat; }
template <typename T, precision P> GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> scale ( detail::tmat4x4<T, P> const & m, detail::tvec3<T, P> const & v ) { detail::tmat4x4<T, P> Result(detail::tmat4x4<T, P>::_null); Result[0] = m[0] * v[0]; Result[1] = m[1] * v[1]; Result[2] = m[2] * v[2]; Result[3] = m[3]; return Result; }
GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> mat4_cast ( detail::tquat<T, P> const & q ) { return detail::tmat4x4<T, P>(mat3_cast(q)); }
template <typename T, precision P> GLM_FUNC_QUALIFIER detail::tmat3x3<T, P> mat3_cast ( detail::tquat<T, P> const & q ) { detail::tmat3x3<T, P> Result(T(1)); T qxx(q.x * q.x); T qyy(q.y * q.y); T qzz(q.z * q.z); T qxz(q.x * q.z); T qxy(q.x * q.y); T qyz(q.y * q.z); T qwx(q.w * q.x); T qwy(q.w * q.y); T qwz(q.w * q.z); Result[0][0] = 1 - 2 * (qyy + qzz); Result[0][1] = 2 * (qxy + qwz); Result[0][2] = 2 * (qxz - qwy); Result[1][0] = 2 * (qxy - qwz); Result[1][1] = 1 - 2 * (qxx + qzz); Result[1][2] = 2 * (qyz + qwx); Result[2][0] = 2 * (qxz + qwy); Result[2][1] = 2 * (qyz - qwx); Result[2][2] = 1 - 2 * (qxx + qyy); return Result; }