zenilib: zenilib/jni/external/zenilib/zeni/Camera.cpp 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.cpp
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 #include <zeni.h>
19
20 #include <cmath>
21
22 #include <Zeni/Define.h>
23
24 namespace Zeni {
25
26 Camera::Camera(const Point3f &position_, const Quaternion &orientation_, const float &near_clip_, const float &far_clip_, const float &fov_rad_, const float &tunnel_vision_factor_)
27 : position(position_),
28 orientation(orientation_),
29 near_clip(near_clip_),
30 far_clip(far_clip_),
31 fov_rad(fov_rad_),
32 tunnel_vision_factor(tunnel_vision_factor_)
33 {
34 }
35
36 void Camera::adjust_yaw(const float &theta) {
37 orientation = Quaternion::Axis_Angle(get_up(), theta) * orientation;
38 }
39
40 void Camera::adjust_pitch(const float &phi) {
41 orientation = Quaternion::Axis_Angle(get_left(), phi) * orientation;
42 }
43
44 void Camera::adjust_roll(const float &rho) {
45 orientation = Quaternion::Axis_Angle(get_forward(), rho) * orientation;
46 }
47
48 void Camera::move_forward_xy(const float &distance) {
49 position += get_forward().get_ij().normalized() * distance;
50 }
51
52 void Camera::move_left_xy(const float &distance) {
53 position += get_left().get_ij().normalized() * distance;
54 }
55
56 void Camera::turn_left_xy(const float &theta) {
57 orientation = Quaternion::Axis_Angle(ZENI_DEFAULT_UP_VECTOR, theta) * orientation;
58 }
59
60 void Camera::look_at(const Point3f &world_coord, const Vector3f &horizon_plane_normal) {
61 const Vector3f forward = (world_coord - position).normalized();
62 const Vector3f left = (horizon_plane_normal % forward).normalized();
63 const Vector3f up = (forward % left).normalized();
64
65 orientation = Quaternion::Forward_Up(forward, up,
66 ZENI_DEFAULT_FORWARD_VECTOR,
67 ZENI_DEFAULT_UP_VECTOR);
68 }
69
70 void Camera::look_at(const Point3f &world_coord, const Collision::Plane &horizon_plane) {
71 look_at(world_coord, horizon_plane.get_normal());
72 }
73
74 }
75
76 #include <Zeni/Undefine.h>
Zeni::Camera::Camera
Camera(const Point3f &position=ZENI_DEFAULT_CAMERA_POSITION, const Quaternion &orientation=ZENI_DEFAULT_CAMERA_ORIENTATION, const float &near_clip=ZENI_DEFAULT_CAMERA_NEAR_CLIP, const float &far_clip=ZENI_DEFAULT_CAMERA_FAR_CLIP, const float &fov_rad_=ZENI_DEFAULT_CAMERA_FOV, const float &tunnel_vision_factor=ZENI_DEFAULT_CAMERA_TUNNEL_VISION)
The Camera constructor is an alternative to using the numerous setter functions.
Definition: Camera.cpp:26
Zeni::Camera::get_forward
Vector3f get_forward() const
Get the vector indicating the direction in which the camera is pointing.
Definition: Camera.hxx:33
left
GLint left
Definition: glew.h:7291
Zeni::Camera::orientation
Quaternion orientation
Definition: Camera.h:91
normalized
GLint GLenum GLboolean normalized
Definition: glew.h:1891
Zeni::Camera::adjust_yaw
void adjust_yaw(const float &theta)
Adjust the orientation of the camera: left == positive;.
Definition: Camera.cpp:36
Zeni::Quaternion::Axis_Angle
static Quaternion Axis_Angle(const Vector3f &v, const float &theta)
Create a Quaternion from an Axis/Angle pair.
Definition: Quaternion.cpp:56
Zeni::Collision::Plane::get_normal
const Vector3f & get_normal() const
Definition: Collision.h:226
Undefine.h
Zeni::Vector3f::get_ij
Vector3f get_ij() const
Get just the i and j parts.
Definition: Vector3f.hxx:158
Zeni::Point3f
A 3D Point represented with floats.
Definition: Coordinate.h:133
Zeni::Vector3f
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
Define.h
distance
GLsizei GLsizei GLfloat distance
Definition: glew.h:12423
Zeni::Quaternion
A Featureful Quaternion Class.
Definition: Quaternion.h:44
Zeni::Quaternion::Forward_Up
static Quaternion Forward_Up(const Vector3f &destination_forward, const Vector3f &destination_up, const Vector3f &default_forward=ZENI_DEFAULT_FORWARD_VECTOR, const Vector3f &default_up=ZENI_DEFAULT_UP_VECTOR)
Create a Quaternion from a Forward/Up Vector3f pair.
Definition: Quaternion.cpp:66
Zeni::Camera::move_left_xy
void move_left_xy(const float &distance)
Move the camera in the left direction, projected onto the xy-plane.
Definition: Camera.cpp:52
Zeni::Camera::turn_left_xy
void turn_left_xy(const float &theta)
Turn the camera left about the z-axis.
Definition: Camera.cpp:56
Zeni::Camera::position
Point3f position
Definition: Camera.h:90
Zeni::Collision::Plane
Collision Plane.
Definition: Collision.h:207
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
zeni.h
Zeni::Camera::adjust_pitch
void adjust_pitch(const float &phi)
Adjust the orientation of the camera: up == positive;.
Definition: Camera.cpp:40
Zeni::Camera::look_at
void look_at(const Point3f &world_coord, const Vector3f &horizon_plane_normal=ZENI_DEFAULT_UP_VECTOR)
Set the Camera to look at a specific Point3f while maintaining a horizontal horizon for a Plane with ...
Definition: Camera.cpp:60
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::Vector3f::normalized
Vector3f normalized() const
Get the normalized vector.
Definition: Vector3f.cpp:58
Zeni::Camera::adjust_roll
void adjust_roll(const float &rho)
Adjust the orientation of the camera: spin right == positive;.
Definition: Camera.cpp:44
ZENI_DEFAULT_UP_VECTOR
#define ZENI_DEFAULT_UP_VECTOR
Definition: Define.h:33
Zeni::Camera::move_forward_xy
void move_forward_xy(const float &distance)
Move the camera in the forward direction, projected onto the xy-plane.
Definition: Camera.cpp:48
ZENI_DEFAULT_FORWARD_VECTOR
#define ZENI_DEFAULT_FORWARD_VECTOR
Definition: Define.h:32