To get the View matrix from the rotation,translation,scale
2017-06-21 21:24
603 查看
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; }
相关文章推荐
- USBView & How to get the Serial Number from a USB disk & qextserialport
- How to get the Projection ProjectionMatrixFromCameraIntrinsics
- failed to get the required ADT version number from the SDK:..../traceview.bat
- HOWTO get multiple value from the same name checkbox elements or radiobution elements
- The method getContextPath() from the type HttpServletRequest refers to the missing type
- 解决failed to get the required adt version from sdkversion问题方法之一
- Xmanager Failed to get the installation date from the system registry的解决方法
- [导入]Unable to get the project ile from the web server错误的解决方法
- 【iOS】Illegal Configuration: The Label outlet from the ViewController to the UILabel is invalid. Outl
- get the nsum of 'Fibonacci'from one to twenty
- get paid from、 to the taste of、expand my horizons、available、by the way
- How to Get the Best Image Quality from Your IP Camera
- JSP URI/URL - How to get the request URI, URL, and Context from a JSP
- redis:Unable to validate object ;Could not get a resource from the pool;(error) MISCONF Redis is con
- The method getContextPath() from the type HttpServletRequest refers to the missing type
- Unable to get view server version from device emulator-5554 解决办法
- How to get parameters from the URL?
- The method getContextPath() from the type HttpServletRequest refers to the missing type
- 解决Missing forwarded port for XXX,Unable to get view server version from deviceXX
- From an inner class, "this" points to the inner object. How do I get a "this" pointer to the enclosing object?