#include <cmath>
#include "camera.h"
#include "matrix.h"
-#include "projection.h"
namespace Msp {
namespace GL {
position(0, 0, 0),
look_dir(0, 0, -1),
up_dir(0, 1, 0)
-{
- for(unsigned i=0; i<16; ++i)
- matrix[i] = (i%5 ? 0 : 1);
- matrix[10] = -1;
-}
+{ }
void Camera::set_field_of_view(float f)
{
void Camera::apply() const
{
- float h = tan(fov/2)*2*clip_near;
-
- matrix_mode(PROJECTION);
- load_identity();
- frustum_centered(h*aspect, h, clip_near, clip_far);
-
- matrix_mode(MODELVIEW);
- load_matrix(matrix);
+ MatrixStack::projection() = Matrix::perspective(fov, aspect, clip_near, clip_far);
+ MatrixStack::modelview() = matrix;
}
void Camera::compute_matrix()
float y = look_dir.z*up_dir.x-look_dir.x*up_dir.z;
float z = look_dir.x*up_dir.y-look_dir.y*up_dir.x;
float len = sqrt(x*x+y*y+z*z);
+ double mdata[16];
+
+ mdata[0] = x/len;
+ mdata[4] = y/len;
+ mdata[8] = z/len;
+
+ mdata[1] = mdata[4]*look_dir.z-mdata[8]*look_dir.y;
+ mdata[5] = mdata[8]*look_dir.x-mdata[0]*look_dir.z;
+ mdata[9] = mdata[0]*look_dir.y-mdata[4]*look_dir.x;
- matrix[0] = x/len;
- matrix[4] = y/len;
- matrix[8] = z/len;
+ mdata[2] = -look_dir.x;
+ mdata[6] = -look_dir.y;
+ mdata[10] = -look_dir.z;
- matrix[1] = matrix[4]*look_dir.z-matrix[8]*look_dir.y;
- matrix[5] = matrix[8]*look_dir.x-matrix[0]*look_dir.z;
- matrix[9] = matrix[0]*look_dir.y-matrix[4]*look_dir.x;
+ mdata[12] = -position.x*mdata[0]-position.y*mdata[4]-position.z*mdata[8];
+ mdata[13] = -position.x*mdata[1]-position.y*mdata[5]-position.z*mdata[9];
+ mdata[14] = -position.x*mdata[2]-position.y*mdata[6]-position.z*mdata[10];
- matrix[2] = -look_dir.x;
- matrix[6] = -look_dir.y;
- matrix[10] = -look_dir.z;
+ mdata[3] = 0;
+ mdata[7] = 0;
+ mdata[11] = 0;
+ mdata[15] = 1;
- matrix[12] = -position.x*matrix[0]-position.y*matrix[4]-position.z*matrix[8];
- matrix[13] = -position.x*matrix[1]-position.y*matrix[5]-position.z*matrix[9];
- matrix[14] = -position.x*matrix[2]-position.y*matrix[6]-position.z*matrix[10];
+ matrix = mdata;
}
} // namespace GL
#include "light.h"
#include "matrix.h"
#include "misc.h"
-#include "projection.h"
#include "scene.h"
#include "shadowmap.h"
#include "texunit.h"
matrix[15] = 1;
{
- matrix_mode(PROJECTION);
- push_matrix();
- load_identity();
- ortho(-radius, radius, -radius, radius, -radius, radius);
- matrix_mode(MODELVIEW);
- push_matrix();
- load_matrix(matrix);
+ MatrixStack::Push push_mv(MatrixStack::modelview());
+ MatrixStack::Push push_proj(MatrixStack::projection());
+
+ MatrixStack::projection() = Matrix::ortho(-radius, radius, -radius, radius, -radius, radius);
+ MatrixStack::modelview() = matrix;
Bind bind_fbo(fbo, true);
fbo.clear(DEPTH_BUFFER_BIT);
scene.render("shadow");
-
- matrix_mode(PROJECTION);
- pop_matrix();
- matrix_mode(MODELVIEW);
- pop_matrix();
}
depth_buf.bind_to(unit);