Go to the documentation of this file.00001
00005
00006
00007
00008
00009 #include <qglv/opengl.hpp>
00010
00011 #include "../../include/qglv/primitives/qgl_pose.hpp"
00012 #include "../../include/qglv/objects/camera.hpp"
00013
00014
00015
00016
00017
00018 namespace qglv {
00019
00020
00021
00022
00023
00024 Camera::Camera(const float& width, const float& height,
00025 const float& u0,
00026 const float& v0,
00027 const float& focal_length_in_pixels,
00028 const Sophus::SE3f& pose
00029 )
00030 : width(width),
00031 height(height),
00032 principal_point(u0, v0),
00033 focal_length(focal_length_in_pixels),
00034 pose(pose)
00035 {
00036
00037 const float arb_distance = 500.0f;
00038 float l, r, t, b;
00039 l = -arb_distance * principal_point.x() / focal_length;
00040 t = -arb_distance * principal_point.y() / focal_length;
00041 r = arb_distance * (static_cast<float>(width)-principal_point.x()) / focal_length;
00042 b = arb_distance * (static_cast<float>(height)-principal_point.y()) / focal_length;
00043 frustum[0] = Eigen::Vector3f(l,t,arb_distance);
00044 frustum[1] = Eigen::Vector3f(r,t,arb_distance);
00045 frustum[2] = Eigen::Vector3f(r,b,arb_distance);
00046 frustum[3] = Eigen::Vector3f(l,b,arb_distance);
00047 }
00048
00058 void Camera::setPose(const Sophus::SE3f& T_cam_rel_map) {
00059 pose = T_cam_rel_map.inverse();
00060 for ( unsigned int i = 0; i < 4; ++i ) {
00061 updated_frustum[i] = pose*frustum[i];
00062 }
00063 }
00064
00065
00066 void Camera::draw() {
00067
00068 poseQGLStyle(pose, 1.0);
00069
00070
00071 glPushMatrix();
00072
00073 glColor4f(0.3f, 0.0f, 1.0f, 0.5f);
00074 Eigen::Vector3f fpoint[4];
00075 for( int i(0); i<4; i++ )
00076 {
00077 fpoint[i] = pose * (frustum[i] / 500.0f);
00078 line( pose.translation(), fpoint[i] );
00079 }
00080
00081 line( fpoint[0], fpoint[1] );
00082 line( fpoint[1], fpoint[2] );
00083 line( fpoint[2], fpoint[3] );
00084 line( fpoint[3], fpoint[0] );
00085
00086 glColor4f(1.0f,0.0f,0.0f, 0.5f); point( fpoint[0], 2.0f );
00087 glColor4f(0.0f,1.0f,0.0f, 0.5f); point( fpoint[1], 2.0f );
00088 glColor4f(0.0f,0.0f,1.0f, 0.5f); point( fpoint[2], 2.0f );
00089
00090 glPopMatrix();
00091 }
00092
00093 }
00094