Visual Computing Library  devel
Loading...
Searching...
No Matches
camera_drawer.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_RENDER_DRAWERS_CAMERA_DRAWER_H
24#define VCL_RENDER_DRAWERS_CAMERA_DRAWER_H
25
26#include "event_drawer.h"
27#include <vclib/render/viewer/camera.h>
28#include <vclib/render/viewer/lights.h>
29
30namespace vcl {
31template<typename Scalar, typename DerivedRenderApp>
32class CameraDrawerT : public vcl::EventDrawer<DerivedRenderApp>
33{
34public:
35 using ScalarType = Scalar;
37 using PointType = CameraType::PointType;
38 using MatrixType = CameraType::MatrixType;
40
41protected:
42 CameraType mCamera;
43
44public:
46
47 CameraDrawerT(uint width = 100, uint height = 768) : Base(width, height)
48 {
49 onResize(width, height);
50 }
51
52 MatrixType viewMatrix() const { return mCamera.viewMatrix(); }
53
54 MatrixType projectionMatrix() const { return mCamera.projectionMatrix(); }
55
56 const CameraType& camera() const { return mCamera; }
57
58 LightType light() const { return LightType(); }
59
60 void reset() { mCamera.reset(); }
61
62 void focus(const PointType& p) { mCamera.center() = p; }
63
64 void fitScene(const PointType& p, Scalar s)
65 {
66 mCamera.center() = p;
67 mCamera.eye() = p + PointType(0, 0, 1);
68 mCamera.verticalHeight() = s;
69 mCamera.setFieldOfViewAdaptingEyeDistance(mCamera.fieldOfView());
70 }
71
72 void onResize(uint width, uint height) override
73 {
74 mCamera.aspectRatio() = Scalar(double(width) / height);
75 }
76};
77
78template<typename DerivedRenderApp>
80
81} // namespace vcl
82
83#endif // VCL_RENDER_DRAWERS_CAMERA_DRAWER_H
A class representing a box in N-dimensional space.
Definition box.h:46
PointT PointType
The type of point used to represent the corners of the box.
Definition box.h:54
PointT center() const
Calculates the center point of the box.
Definition box.h:259
Definition camera_drawer.h:33
The EventDrawer class is a base class for drawers that can handle events.
Definition event_drawer.h:44