projects
/
demo
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fixes
[demo]
/
src
/
camera.cc
diff --git
a/src/camera.cc
b/src/camera.cc
index
4db7286
..
7de5501
100644
(file)
--- a/
src/camera.cc
+++ b/
src/camera.cc
@@
-3,16
+3,10
@@
#include <gmath/gmath.h>
#include "camera.h"
#include <gmath/gmath.h>
#include "camera.h"
-#include "state_manager.h"
Camera::Camera() {}
Camera::~Camera() {}
Camera::Camera() {}
Camera::~Camera() {}
-void Camera::use() const
-{
- state_manager.set_state("st_view_matrix", get_view_matrix());
-}
-
OrbitCamera::OrbitCamera()
{
phi = theta = distance = 0;
OrbitCamera::OrbitCamera()
{
phi = theta = distance = 0;
@@
-20,7
+14,7
@@
OrbitCamera::OrbitCamera()
OrbitCamera::~OrbitCamera() {}
OrbitCamera::~OrbitCamera() {}
-void OrbitCamera::set_orbit_params(float phi, float theta, float distance)
+void OrbitCamera::set_orbit_params(float theta, float phi, float distance)
{
this->phi = phi;
this->theta = theta;
{
this->phi = phi;
this->theta = theta;
@@
-30,24
+24,37
@@
void OrbitCamera::set_orbit_params(float phi, float theta, float distance)
Mat4 OrbitCamera::get_view_matrix() const
{
Mat4 view_matrix;
Mat4 OrbitCamera::get_view_matrix() const
{
Mat4 view_matrix;
- view_matrix.translate(Vec3(0, 0, -distance));
- view_matrix.rotate_x(phi * (float)M_PI / 180);
+ view_matrix.translation(-position);
view_matrix.rotate_y(theta * (float)M_PI / 180);
view_matrix.rotate_y(theta * (float)M_PI / 180);
+ view_matrix.rotate_x(phi * (float)M_PI / 180);
+ view_matrix.translate(Vec3(0, 0, -distance));
return view_matrix;
}
return view_matrix;
}
-Mat4 calc_projection_matrix(float f, float n, float aspect, float fov)
+Mat4 calc_projection_matrix(float fov_deg, float aspect, float n, float f)
{
{
+ float fov = fov_deg / 180 * M_PI;
+
float tmp;
tmp = 1 / tan(fov / 2.0);
float tmp;
tmp = 1 / tan(fov / 2.0);
+ /* near - far clipping planes */
+ float range = n - f;
+
Mat4 pmat = Mat4(
Mat4 pmat = Mat4(
- -tmp/aspect, 0, 0, 0,
+ tmp/aspect, 0, 0, 0,
0, tmp, 0, 0,
0, tmp, 0, 0,
- 0, 0, (f + n) / (n - f), (2 * f * n) / (n - f),
- 0, 0, -1, 0
+ 0, 0, (f + n) / range, -1,
+ 0, 0, 2 * n * f / range, 0
);
return pmat;
);
return pmat;
-}
\ No newline at end of file
+}
+
+void OrbitCamera::set_position(float x, float y, float z)
+{
+ position.x = x;
+ position.y = y;
+ position.z = z;
+}