Easy3D 2.5.3
frustum.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_RENDERER_FRUSTUM_H
28#define EASY3D_RENDERER_FRUSTUM_H
29
30
31#include <vector>
32
33#include <easy3d/core/types.h>
34
35
36namespace easy3d {
37
42 class Frustum
43 {
44 public:
45 enum ProjectionType { PERSPECTIVE, ORTHO };
46
47 public:
48 explicit Frustum(ProjectionType type);
49
50 // To define a working frustum, you need to call two functions:
51 // - orient(), defining the view matrix.
52 // - set_perspective()/set_frustum(), or set_ortho(), defining the projection matrix.
53 void orient(const vec3 &pos, const vec3& at, const vec3& up);
54
55 // NOTE: fovy is in radians
56 void set_perspective(float fovy, float aspect, float znear, float zfar);
57 void set_frustum(float frustum_width, float frustum_height, float znear, float zfar);
58
59 void set_ortho(float xmin, float xmax, float ymin, float ymax, float znear, float zfar);
60
61 mat4 view_matrix() const;
62 mat4 projection_matrix() const;
63
64 // the center point of the near/far planes in world space
65 vec3 near_center() const;
66 vec3 far_center() const;
67
68 float near_width() const; // frustum width at near plane
69 float near_height() const; // frustum height at near plane
70
71 float far_width() const; // frustum width at far plane
72 float far_height() const; // frustum height at far plane
73
74 // in world space
75 const vec3& position() const { return pos_; }
76 // the up/right vector in world space
77 vec3 up_vector() const;
78 vec3 right_vector() const;
79
80 float near_distance() const { return near_; }
81 float far_distance() const { return far_; }
82
83 // compute the 8 corner points in world space
84 std::vector<vec3> vertices() const;
85
86 private:
87 ProjectionType type_;
88
89 vec3 pos_;
90 vec3 at_;
91 vec3 up_;
92
93 float near_, far_;
94 float xmin_, xmax_, ymin_, ymax_;
95 float fovy_, ar_;
96 };
97
98}
99
100
101#endif // EASY3D_RENDERER_FRUSTUM_H
A Frustum description for perspective projection.
Definition: frustum.h:43
Definition: collider.cpp:182