Visual Computing Library  devel
Loading...
Searching...
No Matches
camera_drawer.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
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
28#include <vclib/render/viewer/lights.h>
29
30#include <vclib/algorithms/core.h>
31#include <vclib/space/core.h>
32
33namespace vcl {
34template<typename Scalar, typename DerivedRenderApp>
35class CameraDrawerT : public vcl::EventDrawer<DerivedRenderApp>
36{
37public:
38 using ScalarType = Scalar;
40 using PointType = CameraType::PointType;
41 using MatrixType = CameraType::MatrixType;
43
44protected:
45 CameraType mCamera;
46
47public:
49
50 CameraDrawerT(uint width = 100, uint height = 768) : Base(width, height)
51 {
52 onResize(width, height);
53 }
54
55 MatrixType viewMatrix() const { return mCamera.viewMatrix(); }
56
57 MatrixType projectionMatrix() const { return mCamera.projectionMatrix(); }
58
59 const CameraType& camera() const { return mCamera; }
60
61 LightType light() const { return LightType(); }
62
63 void reset() { mCamera.reset(); }
64
65 void focus(const PointType& p) { mCamera.center() = p; }
66
67 void fitScene(const PointType& p, Scalar s)
68 {
69 mCamera.center() = p;
70 mCamera.eye() = p + PointType(0, 0, 1);
71 mCamera.verticalHeight() = s;
72 mCamera.setFieldOfViewAdaptingEyeDistance(mCamera.fieldOfView());
73 }
74
75 void onResize(uint width, uint height) override
76 {
77 mCamera.aspectRatio() = Scalar(double(width) / height);
78 }
79};
80
81template<typename DerivedRenderApp>
83
84} // namespace vcl
85
86#endif // VCL_RENDER_DRAWERS_CAMERA_DRAWER_H
Definition camera_drawer.h:36
The EventDrawer class is a base class for drawers that can handle events.
Definition event_drawer.h:44
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
PointT PointType
The type of point used to represent the endpoint points of the segment.
Definition segment.h:50