Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "tango-gl/camera.h"
00018 #include "tango-gl/util.h"
00019
00020 namespace tango_gl {
00021
00022 Camera::Camera() {
00023 field_of_view_ = 45.0f * DEGREE_2_RADIANS;
00024 aspect_ratio_ = 4.0f / 3.0f;
00025 near_clip_plane_ = 0.1f;
00026 far_clip_plane_ = 100.0f;
00027 }
00028
00029 glm::mat4 Camera::GetViewMatrix() {
00030 return glm::inverse(GetTransformationMatrix());
00031 }
00032
00033 glm::mat4 Camera::GetProjectionMatrix() {
00034 return glm::perspective(field_of_view_, aspect_ratio_,
00035 near_clip_plane_, far_clip_plane_);
00036 }
00037
00038 void Camera::SetAspectRatio(float aspect_ratio) {
00039 aspect_ratio_ = aspect_ratio;
00040 }
00041
00042 void Camera::SetFieldOfView(float fov) {
00043 field_of_view_ = fov * DEGREE_2_RADIANS;
00044 }
00045
00046 Camera::~Camera() {
00047 }
00048
00049 glm::mat4 Camera::ProjectionMatrixForCameraIntrinsics(float width, float height,
00050 float fx, float fy,
00051 float cx, float cy,
00052 float near, float far) {
00053 const float xscale = near / fx;
00054 const float yscale = near / fy;
00055
00056 const float xoffset = (cx - (width / 2.0)) * xscale;
00057
00058 const float yoffset = -(cy - (height / 2.0)) * yscale;
00059
00060 return glm::frustum(xscale * -width / 2.0f - xoffset,
00061 xscale * width / 2.0f - xoffset,
00062 yscale * -height / 2.0f - yoffset,
00063 yscale * height / 2.0f - yoffset,
00064 near, far);
00065 }
00066
00067 }