zenilib: zenilib/jni/external/zenilib/zeni/Zeni/Camera.hxx Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Camera.hxx
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef ZENI_CAMERA_HXX
19 #define ZENI_CAMERA_HXX
20
21 // HXXed below
22 #include <Zeni/Coordinate.h>
23 #include <Zeni/Matrix4f.h>
24 #include <Zeni/Quaternion.h>
25
26 #include <Zeni/Camera.h>
27 #include <cmath>
28
29 #include <Zeni/Define.h>
30
31 namespace Zeni {
32
33 Vector3f Camera::get_forward() const {
34 return orientation * ZENI_DEFAULT_FORWARD_VECTOR;
35 }
36
37 Vector3f Camera::get_up() const {
38 return orientation * ZENI_DEFAULT_UP_VECTOR;
39 }
40
41 Vector3f Camera::get_left() const {
42 return orientation * ZENI_DEFAULT_LEFT_VECTOR;
43 }
44 float Camera::get_fov_deg() const {
45 return fov_rad * 180.0f / Global::pi;
46 }
47
48 void Camera::set_fov_deg(const float &degrees) {
49 fov_rad = degrees * Global::pi / 180.0f;
50 }
51
52 Point3f Camera::get_tunneled_position() const {
53 return position + (1.0f - tunnel_vision_factor) * near_clip * get_forward();
54 }
55
56 float Camera::get_tunneled_near_clip() const {
57 return near_clip * tunnel_vision_factor;
58 }
59
60 float Camera::get_tunneled_far_clip() const {
61 return far_clip - near_clip + get_tunneled_near_clip();
62 }
63
64 float Camera::get_tunneled_fov_deg() const {
65 return get_tunneled_fov_rad() * 180.0f / Global::pi;
66 }
67
68 float Camera::get_tunneled_fov_rad() const {
69 return 2.0f * std::atan((near_clip * std::tan(0.5f * fov_rad)) / get_tunneled_near_clip());
70 }
71
72 Matrix4f Camera::get_view_matrix() const {
73 return Matrix4f::View(get_tunneled_position(), get_forward(), get_up());
74 }
75
76 Matrix4f Camera::get_projection_matrix(const std::pair<Point2i, Point2i> &viewport) const {
77 return Matrix4f::Perspective(get_tunneled_fov_rad(),
78 float(viewport.second.x - viewport.first.x) / (viewport.second.y - viewport.first.y),
79 get_tunneled_near_clip(), get_tunneled_far_clip());
80 }
81
82 }
83
84 #include <Zeni/Undefine.h>
85
86 #include <Zeni/Coordinate.hxx>
87 #include <Zeni/Matrix4f.hxx>
88 #include <Zeni/Quaternion.hxx>
89
90 #endif
Quaternion.hxx
Zeni::Camera::get_tunneled_fov_rad
float get_tunneled_fov_rad() const
Get the field of view (in the y-axis) in radians, shifted by tunnel vision.
Definition: Camera.hxx:68
Zeni::Camera::get_forward
Vector3f get_forward() const
Get the vector indicating the direction in which the camera is pointing.
Definition: Camera.hxx:33
f
GLclampf f
Definition: glew.h:3390
Zeni::Camera::orientation
Quaternion orientation
Definition: Camera.h:91
Coordinate.hxx
Zeni::Camera::get_fov_deg
float get_fov_deg() const
Get the field of view (in the y-axis) in degrees.
Definition: Camera.hxx:44
Zeni::Camera::get_tunneled_position
Point3f get_tunneled_position() const
Get the position shifted by tunnel vision.
Definition: Camera.hxx:52
Undefine.h
Zeni::Camera::near_clip
float near_clip
Definition: Camera.h:93
Zeni::Camera::fov_rad
float fov_rad
Definition: Camera.h:95
Zeni::Camera::get_projection_matrix
Matrix4f get_projection_matrix(const std::pair< Point2i, Point2i > &viewport) const
Equivalent to gluPerspective + tunnel_vision_factor.
Definition: Camera.hxx:76
Zeni::Point3f
A 3D Point represented with floats.
Definition: Coordinate.h:133
Matrix4f.hxx
Coordinate.h
Zeni::Vector3f
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
Zeni::Global::pi
const float pi
pi == 3.1415926...
Definition: Vector3f.cpp:27
Define.h
Matrix4f.h
Zeni::Camera::far_clip
float far_clip
Definition: Camera.h:94
Quaternion.h
Zeni::Camera::position
Point3f position
Definition: Camera.h:90
Zeni::Matrix4f::View
static Matrix4f View(const Point3f &position, const Vector3f &forward, const Vector3f &up)
Similar to gluLookAt.
Definition: Matrix4f.hxx:77
Zeni::Camera::get_tunneled_near_clip
float get_tunneled_near_clip() const
Get the near clip shifted by tunnel vision.
Definition: Camera.hxx:56
Zeni::Camera::get_tunneled_fov_deg
float get_tunneled_fov_deg() const
Get the field of view (in the y-axis) in degrees, shifted by tunnel vision.
Definition: Camera.hxx:64
Zeni::Camera::get_tunneled_far_clip
float get_tunneled_far_clip() const
Get the far clip shifted by tunnel vision.
Definition: Camera.hxx:60
Camera.h
Zeni::Camera::tunnel_vision_factor
float tunnel_vision_factor
Definition: Camera.h:97
Zeni::Camera::set_fov_deg
void set_fov_deg(const float &degrees)
Set the field of view (in the y-axis) in degrees.
Definition: Camera.hxx:48
Zeni::Camera::get_left
Vector3f get_left() const
Get the vector indicating what is &quot;left&quot; from the perspective of the camera.
Definition: Camera.hxx:41
atan
double atan(double x)
Definition: s_atan.c:67
Zeni::Matrix4f
A Featureful 4-Space Matrix Class.
Definition: Matrix4f.h:47
Zeni::Matrix4f::Perspective
static Matrix4f Perspective(const float &fov_rad_y, const float &aspect, const float &near, const float &far)
Similar to gluPerspective.
Definition: Matrix4f.hxx:104
Zeni::Camera::get_view_matrix
Matrix4f get_view_matrix() const
Equivalent to gluLookAt + tunnel_vision_factor.
Definition: Camera.hxx:72
Zeni::Camera::get_up
Vector3f get_up() const
Get the vector indicating what is &quot;up&quot; from the perspective of the camera.
Definition: Camera.hxx:37
ZENI_DEFAULT_LEFT_VECTOR
#define ZENI_DEFAULT_LEFT_VECTOR
Definition: Define.h:34
ZENI_DEFAULT_UP_VECTOR
#define ZENI_DEFAULT_UP_VECTOR
Definition: Define.h:33
ZENI_DEFAULT_FORWARD_VECTOR
#define ZENI_DEFAULT_FORWARD_VECTOR
Definition: Define.h:32