Easy3D 3.0.0
Loading...
Searching...
No Matches
Tutorial_205_RealCamera

Rendering a scene through a real calibrated camera and converting between pixels and 3D rays.

Overview

This tutorial reconstructs the viewpoint of a real photograph. Given camera parameters recovered by calibration or structure-from-motion (here read from a Bundler file), it places the Easy3D camera so the 3D point cloud is seen exactly as in the original image, shows that image as an overlay, and lets you move the cursor to project between image pixels and 3D rays/points. The viewer subclass (TutorialRealCamera, shown after this file) does all the work.

The technique

A pinhole camera is described by intrinsics K (focal length fx/fy, principal point cx/cy, skew) and extrinsics [R|t] (rotation and translation from world to camera coordinates). A 3D world point p projects to the image as x = K [R|t] p, with the result divided by its depth (the perspective divide). Inverting this maps an image pixel back to a 3D ray through the camera center. Two conventions must be reconciled: computer vision uses X right, Y down, Z forward, while OpenGL/Easy3D uses X right, Y up, Z toward the viewer, so Y and Z are flipped when converting. A common pitfall is treating t as the camera position; the true world-space camera center is C = -R^{-1} t = -R^T t. The vertical field of view follows from the focal length and image height: fov = 2 atan(h / (2 fy)). See Camera::set_from_calibration() and the helper functions in TutorialRealCamera for the exact math.

Easy3D API

Running it

Press 'space' to cycle through the recovered views (the window resizes to each image's aspect ratio); '1'/'2' toggle calibration vs. ground-truth pose; 'h' shows/hides the camera frusta. Move the cursor over the overlaid photo to see the corresponding 3D ray; move it over the 3D scene to see where that point lands in the image.

1
27#include "viewer.h"
28#include <easy3d/util/resource.h>
29#include <easy3d/util/initializer.h>
30
81using namespace easy3d;
82
83int main(int argc, char **argv) {
84 // Bootstrap Easy3D (logging, resource directory, ...). Must come first.
85 initialize();
86
87 // The Bundler output holds the recovered camera intrinsics/extrinsics (we use only those).
88 const std::string bundler_file = resource::directory() + "/data/fountain/bundle.out";
89 // The reconstructed 3D point cloud that the cameras observed.
90 const std::string cloud_file = resource::directory() + "/data/fountain/pointcloud.ply";
91
92 // The subclass loads both files, builds the camera poses, and sets up the overlays.
93 TutorialRealCamera viewer(EXAMPLE_TITLE, bundler_file, cloud_file);
94
95 // Enter the interactive render loop; returns only when the window is closed.
96 return viewer.run();
97}
Definition collider.cpp:182

The header file of the viewer class:

1
27#ifndef EASY3D_TUTORIAL_REAL_CAMERA_H
28#define EASY3D_TUTORIAL_REAL_CAMERA_H
29
30#include <easy3d/viewer/viewer.h>
31
32// This RealCamera class visualizes a model from the view point
33// given the camera's intrinsic and extrinsic parameters. These
34// camera parameters can (usually) be recovered using camera
35// calibration or structure from motion techniques.
36
37namespace easy3d {
38 class Camera;
39 class LinesDrawable;
40} // namespace easy3d
41
52class TutorialRealCamera : public easy3d::Viewer {
53public:
54 // Loads the point cloud and the Bundler camera parameters, then sets up the scene/overlays.
55 TutorialRealCamera(const std::string &title, const std::string &bundler_file, const std::string &cloud_file);
56
58
67 static easy3d::vec3 camera_pos(const easy3d::mat3 &R, const easy3d::vec3 &t);
68
93 static easy3d::vec3 pixel_to_ray(int img_x,
94 int img_y,
95 float fx,
96 float fy,
97 float skew,
98 float cx,
99 float cy,
100 const easy3d::mat3 &R,
101 const easy3d::vec3 &t,
102 bool convert = true);
103
126 static easy3d::vec2 point_to_pixel(const easy3d::vec3 &p,
127 float fx,
128 float fy,
129 float skew,
130 float cx,
131 float cy,
132 const easy3d::mat3 &R,
133 const easy3d::vec3 &t,
134 bool convert = true);
135
136protected:
137 // Cycles views ('space'), toggles calibration/ground-truth ('1'/'2'), and hides cameras ('h').
138 bool key_press_event(int key, int modifiers) override;
139 // Projects between the cursor position and 3D: pixel->ray over the image, point->pixel over the scene.
140 bool mouse_free_move_event(int x, int y, int dx, int dy, int modifiers) override;
141
142 // Computes where the source photo is drawn on screen, preserving its aspect ratio.
143 easy3d::Rect calculate_image_rect() const;
144
145private:
146 // One recovered camera: image size, intrinsics (fx, fy, cx, cy), and extrinsics (R, t).
147 struct CameraPara {
148 int w, h; // image size
149 float fx, fy; // focal length
150 float cx, cy; // principal point
151 easy3d::mat3 R; // rotation
152 easy3d::vec3 t; // the translation
153 };
154 std::vector<CameraPara> views_;
155 int current_view_;
156
157 // Parses the Bundler file into views_ (implemented in read_bundler_file.cpp).
158 bool read_bundler_file(const std::string &file_name);
159
160 // K [R t] -> easy3d camera representation
161 bool KRT_to_camera(int view_index, easy3d::Camera *c, bool ground_truth);
162
163 // Rebuilds the line drawable that draws every camera frustum in the scene.
164 void update_cameras_drawable(bool ground_truth);
165
166 // Loads the photo corresponding to current_view_ for the 2D overlay.
167 void load_image();
168
169 void pre_draw() override; // builds/updates the image and crosshair overlays each frame
170 void post_resize(int, int) override; // invalidates the cursor marker on resize
171 // Cached overlay state: rebuilt only when something relevant changes (see pre_draw()).
172 std::shared_ptr<const easy3d::graphics::Image> image_;
173 int image_view_ = -1;
174 easy3d::Rect overlay_rect_{0, 0, 0, 0};
175 const easy3d::graphics::Image *overlay_image_ = nullptr;
176 bool cross_geometry_dirty_ = true;
177 std::vector<easy3d::vec3> cross_points_;
178 bool cross_overlay_visible_ = false;
179 int overlay_width_ = 0, overlay_height_ = 0;
180 std::vector<easy3d::graphics::DrawCommand> image_commands_;
181 easy3d::graphics::DrawCommand cross_command_;
182
183private:
184 easy3d::LinesDrawable *cameras_drawable_;
185 easy3d::LinesDrawable *ray_drawable_; // in 3D
186 bool cross_visible_ = false; // 2D annotation, never a scene drawable
187};
188
189#endif // EASY3D_TUTORIAL_REAL_CAMERA_H
A perspective or orthographic camera.
Definition camera.h:142
The drawable for rendering a set of line segments, e.g., edges of a mesh, vector fields.
Definition drawable_lines.h:40
The default viewer implementation for both OpenGL and Vulkan backends.
Definition viewer.h:143
Immutable RGBA8 image with explicit sampler state.
Definition render_device.h:173
Complete backend-independent description of a draw operation.
Definition render_device.h:219

The source file of the viewer class:

1
27#include "viewer.h"
28
29#include <easy3d/core/point_cloud.h>
30#include <easy3d/renderer/drawable_points.h>
31#include <easy3d/renderer/drawable_lines.h>
32#include <easy3d/renderer/camera.h>
33#include <easy3d/renderer/manipulated_camera_frame.h>
34#include <easy3d/renderer/shape.h>
35#include <easy3d/renderer/renderer.h>
36#include <easy3d/renderer/transform.h>
37#include <easy3d/util/string.h>
38#include <easy3d/util/file_system.h>
39#include <easy3d/util/resource.h>
40#include <easy3d/fileio/image_io.h>
41
42using namespace easy3d;
43
44// \cond
45
46// The source photos are shown (and the window sized) at this fraction of their pixel size.
47const float scale = 0.3f;
48
49TutorialRealCamera::TutorialRealCamera(const std::string &title,
50 const std::string &bundler_file,
51 const std::string &cloud_file)
52 : Viewer(title), current_view_(0), cameras_drawable_(nullptr), ray_drawable_(nullptr) {
53 // Read the point cloud
54 if (add_model(cloud_file)) {
55 // Make the reconstructed points large enough to see.
56 auto drawable = current_model()->renderer()->get_points_drawable("vertices");
57 drawable->set_point_size(2.0f);
58
59 // Read the camera parameters from the bundler file.
60 if (read_bundler_file(bundler_file))
61 update_cameras_drawable(true); // draw a frustum for every recovered camera
62 else
63 std::cerr << "failed to load bundler file" << std::endl;
64
65 // Start from a neutral overview of the whole cloud.
66 camera()->set_up_vector(vec3(0, 1, 0));
67 camera()->set_view_direction(vec3(0, 0, -1));
68 camera()->show_entire_scene();
69 load_image();
70 } else
71 std::cerr << "failed to load point cloud" << std::endl;
72
73 // hint_ is shown in the viewer HUD; it lists the interactive controls.
74 hint_ =
75 "Press 'Space' to switch views \n"
76 "Press 'h' to show/hide the cameras \n"
77 "Move cursor on image to show corresponding 3D ray \n"
78 "Move cursor on scene to show corresponding image point";
79}
80
81bool TutorialRealCamera::key_press_event(int key, int modifiers) {
82 // Clear any cursor-driven annotations before handling a view change.
83 if (ray_drawable_)
84 ray_drawable_->set_visible(false);
85 cross_visible_ = false;
86 pre_draw(); // default snapshot shortcuts must see the cleared screen marker
87
88 if (key == KEY_SPACE) {
89 if (!views_.empty()) {
90 // Advance to the next recovered view (wrapping around).
91 current_view_ = (current_view_ + 1) % static_cast<int>(views_.size());
92 const bool ground_truth = true;
93 if (KRT_to_camera(current_view_, camera(), ground_truth)) {
94 update_cameras_drawable(ground_truth);
95 std::cout << "----- view " << current_view_ << ": "
96 << (ground_truth ? "ground truth view" : "calibration view") << std::endl;
97 set_title("TutorialRealCamera: View_" + std::to_string(current_view_));
98 const CameraPara &c = views_[current_view_];
99 // Resize the window to the image's aspect ratio so the overlay is undistorted
100 // make sure the aspect ratio (actual size does not matter)
101 resize(static_cast<int>(static_cast<float>(c.w) * scale),
102 static_cast<int>(static_cast<float>(c.h) * scale));
103 }
104 }
105 return true;
106 } else if (key == KEY_1) {
107 if (!views_.empty()) {
108 // '1' shows the pose built directly from the calibration parameters.
109 const bool ground_truth = false;
110 if (KRT_to_camera(current_view_, camera(), ground_truth)) {
111 update_cameras_drawable(ground_truth);
112 std::cout << "----- view " << current_view_ << ": "
113 << (ground_truth ? "ground truth view" : "calibration view") << std::endl;
114 set_title("TutorialRealCamera: View_" + std::to_string(current_view_));
115 const CameraPara &c = views_[current_view_];
116 // make sure the aspect ratio (actual size does not matter)
117 resize(static_cast<int>(static_cast<float>(c.w) * scale),
118 static_cast<int>(static_cast<float>(c.h) * scale));
119 }
120 }
121 return true;
122 } else if (key == KEY_2) {
123 if (!views_.empty()) {
124 // '2' shows the equivalent "ground truth" pose derived from R, t, and the fov.
125 const bool ground_truth = true;
126 if (KRT_to_camera(current_view_, camera(), ground_truth)) {
127 update_cameras_drawable(ground_truth);
128 std::cout << "----- view " << current_view_ << ": "
129 << (ground_truth ? "ground truth view" : "calibration view") << std::endl;
130 set_title("TutorialRealCamera: View_" + std::to_string(current_view_));
131 const CameraPara &c = views_[current_view_];
132 // make sure the aspect ratio (actual size does not matter)
133 resize(static_cast<int>(static_cast<float>(c.w) * scale),
134 static_cast<int>(static_cast<float>(c.h) * scale));
135 }
136 }
137 return true;
138 } else if (key == KEY_H) {
139 // Toggle visibility of all the camera frusta.
140 if (cameras_drawable_) {
141 cameras_drawable_->set_visible(!cameras_drawable_->is_visible());
142 update();
143 }
144 return true;
145 } else
146 return Viewer::key_press_event(key, modifiers);
147}
148
149// Loads the photo for the current view as an RGBA texture used by the 2D overlay.
150void TutorialRealCamera::load_image() {
151 // Images are named by zero-padded view index, e.g. images/0000.jpg.
152 const std::string image_file =
153 resource::directory() + "/data/fountain/images/" + string::to_string(current_view_, 4, '0') + ".jpg";
154 if (image_view_ == current_view_)
155 return; // already loaded this view's image
156 image_.reset();
157 image_view_ = current_view_;
158 int w = 0, h = 0, channels = 0;
159 std::vector<unsigned char> rgba;
160 if (file_system::is_file(image_file) && ImageIO::load(image_file, rgba, w, h, channels, 4, false)) {
161 graphics::Sampler sampler;
162 sampler.filter = graphics::TextureFilter::linear;
163 image_ = std::make_shared<graphics::Image>(w, h, std::move(rgba), sampler);
164 }
165 update();
166}
167
168// Converts a recovered K [R|t] camera into an Easy3D Camera pose. Two equivalent routes are
169// shown: an explicit "ground truth" pose, and the convenience set_from_calibration() helper.
170bool TutorialRealCamera::KRT_to_camera(int view_index, Camera *c, bool ground_truth) {
171 if (view_index < 0 || view_index >= views_.size()) {
172 std::cerr << "Error: invalid view index (" << view_index << ")" << std::endl;
173 return false;
174 }
175
176 const CameraPara &cam = views_[view_index];
177
178 if (ground_truth) {
179 // R: rotation matrix of world frame in camera frame
180 // The camera orientation is the inverse rotation (camera frame -> world frame).
181 const quat q(inverse(cam.R)); // the inverse rotation represented by a quaternion
182 c->set_orientation(q);
183 c->set_position(-q.rotate(cam.t)); // camera position: -inverse(rot) * t
184 // Derive the vertical field of view from fy and the image height:
185 // proj[1][1] = 2 fy / h, and fov = 2 atan(1 / proj[1][1]).
186 const float proj11 = 2.0f * cam.fy / static_cast<float>(cam.h); // proj[1][1]
187 const float fov = 2.0f * std::atan(1.0f / proj11);
188 c->set_field_of_view(fov);
189 } else {
190 // Let Easy3D build position, orientation, and fov directly from the calibration.
191 c->set_from_calibration(cam.fx, cam.fy, 0.0f, cam.cx, cam.cy, cam.R, cam.t, true);
192 }
193
194 if (c == camera())
195 load_image(); // the active view changed, so refresh the overlaid photo
196
197 return true;
198}
199
200// Builds a line drawable showing a small frustum for every recovered camera, placed in world
201// space using each camera's frame. This makes the capture geometry visible in the 3D scene.
202void TutorialRealCamera::update_cameras_drawable(bool ground_truth) {
203 if (!cameras_drawable_) {
204 cameras_drawable_ = new LinesDrawable("cameras");
205 add_drawable(std::shared_ptr<LinesDrawable>(cameras_drawable_)); // add the camera drawable to the viewer
206 cameras_drawable_->set_uniform_coloring(vec4(0, 0, 1, 1.0f));
207 cameras_drawable_->set_line_width(1.0f);
208 }
209
210 std::vector<vec3> vertices;
211 for (std::size_t i = 0; i < views_.size(); ++i) {
212 // Build a temporary camera for this view, then generate its frustum wireframe.
213 Camera c;
214 KRT_to_camera(static_cast<int>(i), &c, ground_truth);
215 std::vector<vec3> points;
216 shape::create_camera(points, c.scene_radius() * 0.03f, c.field_of_view(),
217 static_cast<float>(views_[i].h) / static_cast<float>(views_[i].w));
218 // Transform the frustum from the camera's local frame into world coordinates.
219 const mat4 &m = c.frame()->world_matrix();
220 for (auto &p : points)
221 vertices.push_back(m * p);
222 }
223
224 cameras_drawable_->update_vertex_buffer(vertices);
225}
226
227// Fits the source photo into the window preserving its aspect ratio, anchored near the
228// top-left with a DPI-scaled margin. Returns the on-screen rectangle the overlay occupies.
229Rect TutorialRealCamera::calculate_image_rect() const {
230 if (!image_)
231 return {0, 0, 0, 0};
232 int tex_w = int(image_->width()), tex_h = int(image_->height());
233 const float image_as = static_cast<float>(tex_w) / static_cast<float>(tex_h);
234 int fw = 0, fh = 0;
235 framebuffer_size(fw, fh);
236 const float viewer_as = static_cast<float>(fw) / static_cast<float>(fh);
237 if (image_as < viewer_as) { // thin
238 // Image is taller than the window: constrain by height, derive width.
239 tex_h = static_cast<int>(static_cast<float>(fh) * scale);
240 tex_w = static_cast<int>(static_cast<float>(tex_h) * image_as);
241 } else {
242 // Image is wider than the window: constrain by width, derive height.
243 tex_w = static_cast<int>(static_cast<float>(fw) * scale);
244 tex_h = static_cast<int>(static_cast<float>(tex_w) / image_as);
245 }
246
247 const float xmax = static_cast<float>(fw) - 20 * dpi_scaling();
248 const float ymin = 22.5f * dpi_scaling(); // aligned with Easy3D logo
249 return Rect(
250 xmax - static_cast<float>(tex_w), xmax,
251 ymin, ymin + static_cast<float>(tex_h)
252 );
253}
254
255void TutorialRealCamera::post_resize(int, int) {
256 // The cursor marker is in screen space, so it is meaningless after a resize.
257 cross_visible_ = false;
258}
259// Builds the 2D overlays (the source photo, its red border, and an optional green crosshair).
260// Geometry is cached and only rebuilt when the image, framebuffer size, rectangle, or marker
261// changes, to avoid rebuilding the geometry snapshot every frame.
262void TutorialRealCamera::pre_draw() {
263 Viewer::pre_draw();
264 if (!image_) {
265 if (overlay_image_) {
266 set_overlays({});
267 image_commands_.clear();
268 overlay_image_ = nullptr;
269 }
270 return;
271 }
272 int fw = 0, fh = 0;
273 framebuffer_size(fw, fh);
274 const Rect rect = calculate_image_rect();
275 const bool changed = overlay_image_ != image_.get() || overlay_width_ != fw ||
276 overlay_height_ != fh || overlay_rect_.x_min() != rect.x_min() ||
277 overlay_rect_.x_max() != rect.x_max() || overlay_rect_.y_min() != rect.y_min() ||
278 overlay_rect_.y_max() != rect.y_max();
279 if (changed) {
280 graphics::DrawCommand image = graphics::shape::draw_quad_textured(rect, image_, fw, fh);
281 image_commands_ = {image, graphics::shape::draw_quad_wire(rect, vec4(1, 0, 0, 1), fw, fh, dpi_scaling())};
282 overlay_image_ = image_.get();
283 overlay_rect_ = rect;
284 overlay_width_ = fw;
285 overlay_height_ = fh;
286 }
287 const bool visible = cross_visible_;
288 const bool cross_changed = visible != cross_overlay_visible_ || cross_geometry_dirty_ || changed;
289 if (visible && cross_changed) {
290 std::vector<vec2> segments;
291 for (const auto &p : cross_points_)
292 segments.emplace_back(p.x, p.y);
293 cross_command_ = graphics::shape::draw_lines_2d(segments, vec4(0, 1, 0, 1), fw, fh, 3 * dpi_scaling());
294 }
295 if (changed || cross_changed) {
296 auto commands = image_commands_;
297 if (visible)
298 commands.push_back(cross_command_);
299 set_overlays(std::move(commands));
300 cross_overlay_visible_ = visible;
301 cross_geometry_dirty_ = false;
302 }
303}
304
305bool TutorialRealCamera::mouse_free_move_event(int x, int y, int dx, int dy, int modifiers) {
306 (void) dx;
307 (void) dy;
308 (void) modifiers;
309
310 if (current_view_ < 0 || current_view_ >= views_.size()) {
311 std::cerr << "Error: invalid view index (" << current_view_ << ")" << std::endl;
312 return false;
313 }
314
315 int fw = 0, fh = 0;
316 framebuffer_size(fw, fh);
317 int w = 0, h = 0;
318 viewer_size(w, h);
319 const float pixel_x = float(x) * fw / w;
320 const float pixel_y = float(y) * fh / h;
321 const CameraPara &cam = views_[current_view_];
322 const Rect image_rect = calculate_image_rect();
323 cross_visible_ = false;
324 // cursor is inside the image rectangle
325 if (pixel_x >= image_rect.x_min() && pixel_x <= image_rect.x_max() &&
326 pixel_y >= image_rect.y_min() && pixel_y <= image_rect.y_max()) {
327 const float image_x =
328 (pixel_x - image_rect.x_min()) / image_rect.width() * static_cast<float>(cam.w);
329 const float image_y =
330 (pixel_y - image_rect.y_min()) / image_rect.height() * static_cast<float>(cam.h);
331 if (!ray_drawable_) {
332 ray_drawable_ = new LinesDrawable("ray");
333 add_drawable(std::shared_ptr<LinesDrawable>(ray_drawable_)); // add the ray drawable to the viewer
334 ray_drawable_->set_uniform_coloring(vec4(0, 1, 0, 1.0f));
335 ray_drawable_->set_line_width(3.0f);
336 ray_drawable_->set_impostor_type(easy3d::LinesDrawable::CYLINDER);
337 }
338 const vec3 pos = camera_pos(cam.R, cam.t);
339 const vec3 dir = pixel_to_ray(static_cast<int>(image_x), static_cast<int>(image_y), cam.fx, cam.fy, 0, cam.cx,
340 cam.cy, cam.R, cam.t, true);
341 const std::vector<vec3> points = {pos, pos + dir};
342 ray_drawable_->update_vertex_buffer(points);
343 ray_drawable_->set_visible(true);
344 update();
345 } else {
346 if (ray_drawable_)
347 ray_drawable_->set_visible(false);
348
349 bool found(false);
350 const vec3 p = point_under_pixel(x, y, found);
351 if (found) {
352 const vec2 q = point_to_pixel(p, cam.fx, cam.fy, 0, cam.cx, cam.cy, cam.R, cam.t);
353
354 // visualize the image point (that must be within the image)
355 if (q.x >= 0 && q.x <= static_cast<float>(cam.w) && q.y >= 0 && q.y <= static_cast<float>(cam.h)) {
356 const float screen_x = q.x / static_cast<float>(cam.w) * image_rect.width() + image_rect.x_min();
357 const float screen_y = q.y / static_cast<float>(cam.h) * image_rect.height() + image_rect.y_min();
358
359 const float size = 10 * dpi_scaling();
360 const std::vector<vec3> points = {
361 vec3(screen_x - size, screen_y, 0.5f), vec3(screen_x + size, screen_y, 0.5f),
362 vec3(screen_x, screen_y - size, 0.5f), vec3(screen_x, screen_y + size, 0.5f)};
363 cross_points_ = points;
364 cross_geometry_dirty_ = true;
365 cross_visible_ = true;
366 }
367 } else {
368 cross_visible_ = false;
369 }
370
371 update();
372 }
373
374 return false;
375}
376
377vec3 TutorialRealCamera::camera_pos(const mat3 &R, const vec3 &t) {
378 return -inverse(R) * t; // inverse(R) * (vec3(0, 0, 0) - cam.t);
379}
380
381vec3 TutorialRealCamera::pixel_to_ray(int image_x,
382 int image_y,
383 float fx,
384 float fy,
385 float skew,
386 float cx,
387 float cy,
388 const mat3 &R,
389 const vec3 &t,
390 bool convert) {
391 mat3 K(fx, skew, cx, 0, fy, cy, 0, 0, 1);
392
393 // image point in the camera coordinate system (because p_image = K * p_cam).
394 vec3 P = inverse(K) * vec3(static_cast<float>(image_x), static_cast<float>(image_y), 1);
395 if (convert) {
398 P.y *= -1;
399 P.z *= -1;
400 }
401
402 // in the world coordinate system (because p_cam = R * p_world + t)
403 P = transpose(R) * (P - t);
404
405 return P - camera_pos(R, t);
406}
407
408vec2 TutorialRealCamera::point_to_pixel(const easy3d::vec3 &p,
409 float fx,
410 float fy,
411 float skew,
412 float cx,
413 float cy,
414 const easy3d::mat3 &R,
415 const easy3d::vec3 &t,
416 bool convert) {
417 mat3 K(fx, skew, cx, 0, fy, cy, 0, 0, 1);
418 mat34 Rt;
419 Rt.set_col(0, R.col(0));
420 Rt.set_col(1, R.col(1));
421 Rt.set_col(2, R.col(2));
422 Rt.set_col(3, t);
423
424 if (convert) {
427 mat3 flip(1.0);
428 flip(1, 1) = -1; // invert the Y axis
429 flip(2, 2) = -1; // invert the Z axis
430 Rt = flip * Rt;
431 }
432
433 vec3 q = K * (Rt * vec4(p, 1.0));
434 q /= q.z;
435
436 return vec2(q.x, q.y);
437}
438
439// \endcond
void set_field_of_view(float fov)
Set the field of view of the camera.
void set_from_calibration(float fx, float fy, float skew, float cx, float cy, const mat3 &R, const vec3 &t, bool convert=true)
Defines the position(), orientation() and field_of_view() of the camera from calibrated camera intrin...
float scene_radius() const
Returns the radius of the scene observed by the Camera.
Definition camera.h:648
void set_orientation(const quat &q) const
Set the orientation of the camera.
void set_position(const vec3 &pos) const
Set the position of the camera.
float field_of_view() const
Returns the vertical field of view of the camera (in radians).
Definition camera.h:433
ManipulatedCameraFrame * frame() const
Returns the ManipulatedCameraFrame attached to the Camera.
Definition camera.h:707
mat4 world_matrix() const
Returns the world transformation matrix of the Frame.
FT & x_min()
Returns the minimum x-coordinate.
Definition rect.h:79
FT height() const
Returns the height of the rectangle.
Definition rect.h:146
FT width() const
Returns the width of the rectangle.
Definition rect.h:141
FT & x_max()
Returns the maximum x-coordinate.
Definition rect.h:89
FT & y_min()
Returns the minimum y-coordinate.
Definition rect.h:84
FT & y_max()
Returns the maximum y-coordinate.
Definition rect.h:94
@ CYLINDER
The lines will be drawn as cylinders.
Definition drawable_lines.h:60
Base class for matrix types.
Definition mat.h:64
Vec< N, T > col(size_t col) const
Returns the specified column as a vector.
Definition mat.h:728
void set_col(size_t col, const Vec< vN, T > &v)
Sets the specified column from a vector.
Definition mat.h:751
Mat< M, N, T > transpose(const Mat< N, M, T > &m)
Transposes a matrix.
Definition mat.h:1126
Mat< N, N, T > inverse(const Mat< N, N, T > &m)
Returns the inverse of an N x N (square) matrix.
Definition mat.h:1210
Texture addressing and filtering configuration.
Definition render_device.h:165
TextureFilter filter
Interpolation used when sampling between texels.
Definition render_device.h:169
See also
Camera, TutorialRealCamera, LinesDrawable, Tutorial_206_CameraInterpolation