Easy3D 2.6.1
Loading...
Searching...
No Matches
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:
52
53 public:
58 explicit Frustum(ProjectionType type);
59
66 void orient(const vec3 &pos, const vec3& at, const vec3& up);
67
75 void set_perspective(float fovy, float aspect, float znear, float zfar);
83 void set_frustum(float frustum_width, float frustum_height, float znear, float zfar);
93 void set_ortho(float xmin, float xmax, float ymin, float ymax, float znear, float zfar);
94
99 mat4 view_matrix() const;
104 mat4 projection_matrix() const;
105
110 vec3 near_center() const;
115 vec3 far_center() const;
116
121 float near_width() const; // frustum width at near plane
126 float near_height() const; // frustum height at near plane
127
132 float far_width() const; // frustum width at far plane
137 float far_height() const; // frustum height at far plane
138
143 const vec3& position() const { return pos_; }
148 vec3 up_vector() const;
153 vec3 right_vector() const;
154
159 float near_distance() const { return near_; }
164 float far_distance() const { return far_; }
165
170 std::vector<vec3> vertices() const;
171
172 private:
173 ProjectionType type_;
174
175 vec3 pos_;
176 vec3 at_;
177 vec3 up_;
178
179 float near_, far_;
180 float xmin_, xmax_, ymin_, ymax_;
181 float fovy_, ar_;
182 };
183
184}
185
186
187#endif // EASY3D_RENDERER_FRUSTUM_H
void set_frustum(float frustum_width, float frustum_height, float znear, float zfar)
Sets the frustum parameters.
Definition frustum.cpp:80
Frustum(ProjectionType type)
Constructor with projection type.
Definition frustum.cpp:33
void set_perspective(float fovy, float aspect, float znear, float zfar)
Sets the perspective projection parameters.
Definition frustum.cpp:63
vec3 up_vector() const
Returns the up vector of the frustum in world space.
Definition frustum.cpp:130
vec3 near_center() const
Returns the center point of the near plane in world space.
Definition frustum.cpp:113
mat4 view_matrix() const
Returns the view matrix.
Definition frustum.cpp:94
float near_distance() const
Returns the distance to the near clipping plane.
Definition frustum.h:159
float near_height() const
Returns the height of the frustum at the near plane.
Definition frustum.cpp:154
const vec3 & position() const
Returns the position of the frustum in world space.
Definition frustum.h:143
void set_ortho(float xmin, float xmax, float ymin, float ymax, float znear, float zfar)
Sets the orthographic projection parameters.
Definition frustum.cpp:52
mat4 projection_matrix() const
Returns the projection matrix.
Definition frustum.cpp:100
float far_height() const
Returns the height of the frustum at the far plane.
Definition frustum.cpp:172
void orient(const vec3 &pos, const vec3 &at, const vec3 &up)
Sets the orientation of the frustum.
Definition frustum.cpp:44
vec3 far_center() const
Returns the center point of the far plane in world space.
Definition frustum.cpp:121
float near_width() const
Returns the width of the frustum at the near plane.
Definition frustum.cpp:145
vec3 right_vector() const
Returns the right vector of the frustum in world space.
Definition frustum.cpp:137
float far_distance() const
Returns the distance to the far clipping plane.
Definition frustum.h:164
ProjectionType
Types of projection.
Definition frustum.h:48
@ ORTHO
orthographic projection
Definition frustum.h:50
@ PERSPECTIVE
perspective projection
Definition frustum.h:49
std::vector< vec3 > vertices() const
Computes the 8 corner points of the frustum in world space.
Definition frustum.cpp:181
float far_width() const
Returns the width of the frustum at the far plane.
Definition frustum.cpp:163
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
Mat4< float > mat4
A 4 by 4 matrix of float type.
Definition types.h:67