camera.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2014 Google Inc. All Rights Reserved.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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   // Color camera's coordinates has y pointing downwards so we negate this term.
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 }  // namespace tango_gl


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:15