scale(0)
{ }
-Animation::AxisInterpolation::AxisInterpolation(const double *axis1, const double *axis2)
+Animation::AxisInterpolation::AxisInterpolation(const float *axis1, const float *axis2)
{
// Compute a normalized vector halfway between the two endpoints
- double half[3];
- double a1_len = 0;
- double h_len = 0;
+ float half[3];
+ float a1_len = 0;
+ float h_len = 0;
for(unsigned i=0; i<3; ++i)
{
half[i] = (axis1[i]+axis2[i])/2;
}
// Compute correction factors for smooth interpolation
- double cos_half = (axis1[0]*half[0]+axis1[1]*half[1]+axis1[2]*half[2])/sqrt(a1_len*h_len);
- double angle = acos(cos_half);
+ float cos_half = (axis1[0]*half[0]+axis1[1]*half[1]+axis1[2]*half[2])/sqrt(a1_len*h_len);
+ float angle = acos(cos_half);
slope = (angle ? angle/tan(angle) : 1);
scale = cos_half;
}
matrix1(&m1),
matrix2(&m2)
{
- const double *m1_data = matrix1->data();
- const double *m2_data = matrix2->data();
+ const float *m1_data = matrix1->data();
+ const float *m2_data = matrix2->data();
for(unsigned i=0; i<3; ++i)
axes[i] = AxisInterpolation(m1_data+i*4, m2_data+i*4);
}
{
float u = t*2.0f-1.0f;
- double matrix[16];
+ float matrix[16];
for(unsigned i=0; i<4; ++i)
{
- const double *m1_col = matrix1->data()+i*4;
- const double *m2_col = matrix2->data()+i*4;
- double *out_col = matrix+i*4;
+ const float *m1_col = matrix1->data()+i*4;
+ const float *m2_col = matrix2->data()+i*4;
+ float *out_col = matrix+i*4;
if(i<3)
{
float scale;
AxisInterpolation();
- AxisInterpolation(const double *, const double *);
+ AxisInterpolation(const float *, const float *);
};
struct MatrixInterpolation
Vector4 Camera::unproject(const Vector4 &p) const
{
- Vector4 r = invert(proj_matrix)*LinAl::Vector<double, 4>(p.x, p.y, p.z, 1.0f);
+ Vector4 r = invert(proj_matrix)*Vector4(p.x, p.y, p.z, 1.0f);
r = object_matrix*Vector4(r.x, r.y, r.z, p.w);
return r;
}
void Camera::update_object_matrix()
{
Vector3 right_dir = normalize(cross(look_dir, up_dir));
- LinAl::Vector<double, 4> columns[4];
- columns[0] = LinAl::Vector<double, 4>(right_dir, 0.0f);
- columns[1] = LinAl::Vector<double, 4>(cross(right_dir, look_dir), 0.0f);
- columns[2] = LinAl::Vector<double, 4>(-look_dir, 0.0f);
- columns[3] = LinAl::Vector<double, 4>(position, 1.0f);
+ Vector4 columns[4];
+ columns[0] = Vector4(right_dir, 0.0f);
+ columns[1] = Vector4(cross(right_dir, look_dir), 0.0f);
+ columns[2] = Vector4(-look_dir, 0.0f);
+ columns[3] = Vector4(position, 1.0f);
object_matrix = Matrix::from_columns(columns);
view_matrix = invert(object_matrix);
}
{ }
Matrix::Matrix(const float *m):
- Base(LinAl::SquareMatrix<float, 4>(m))
-{ }
-
-Matrix::Matrix(const double *m):
Base(m)
{ }
-Matrix::Matrix(const LinAl::Matrix<double, 4, 4> &other):
+Matrix::Matrix(const LinAl::Matrix<float, 4, 4> &other):
Base(other)
{ }
Vector4 Matrix::operator*(const Vector4 &vec) const
{
- return static_cast<const Base &>(*this)*LinAl::Vector<double, 4>(vec);
+ return static_cast<const Base &>(*this)*LinAl::Vector<float, 4>(vec);
}
Vector3 Matrix::operator*(const Vector3 &vec) const
return Vector3((*this)*Vector4(vec, 1.0f));
}
-double Matrix::operator[](unsigned i) const
+float Matrix::operator[](unsigned i) const
{
if(i>=16)
throw out_of_range("Matrix::operator[]");
Matrix Matrix::translation(const Vector3 &t)
{
- return Geometry::AffineTransformation<double, 3>::translation(t).get_matrix();
+ return Geometry::AffineTransformation<float, 3>::translation(t).get_matrix();
}
Matrix Matrix::rotation(const Angle &a, const Vector3 &x)
{
- return Geometry::AffineTransformation<double, 3>::rotation(a, x).get_matrix();
+ return Geometry::AffineTransformation<float, 3>::rotation(a, x).get_matrix();
}
Matrix Matrix::scaling(const Vector3 &s)
{
- return Geometry::AffineTransformation<double, 3>::scaling(s).get_matrix();
+ return Geometry::AffineTransformation<float, 3>::scaling(s).get_matrix();
}
-Matrix Matrix::ortho(double l, double r, double b, double t, double n, double f)
+Matrix Matrix::ortho(float l, float r, float b, float t, float n, float f)
{
if(l==r || b==t || n==f)
throw invalid_argument("Matrix::ortho");
return result;
}
-Matrix Matrix::ortho_centered(double w, double h)
+Matrix Matrix::ortho_centered(float w, float h)
{
return ortho(-w/2, w/2, -h/2, h/2, -1, 1);
}
-Matrix Matrix::ortho_bottomleft(double w, double h)
+Matrix Matrix::ortho_bottomleft(float w, float h)
{
return ortho(0, w, 0, h, -1, 1);
}
-Matrix Matrix::ortho_topleft(double w, double h)
+Matrix Matrix::ortho_topleft(float w, float h)
{
return ortho(0, w, h, 0, -1, 1);
}
-Matrix Matrix::frustum(double l, double r, double b, double t, double n, double f)
+Matrix Matrix::frustum(float l, float r, float b, float t, float n, float f)
{
if(l==r || b==t || n<=0 || f<=n)
throw invalid_argument("Matrix::frustum");
result(2, 2) = -(f+n)/(f-n);
result(3, 2) = -1;
result(2, 3) = -2*f*n/(f-n);
- result(3 ,3) = 0;
+ result(3, 3) = 0;
return result;
}
-Matrix Matrix::frustum_centered(double w, double h, double n, double f)
+Matrix Matrix::frustum_centered(float w, float h, float n, float f)
{
return frustum(-w/2, w/2, -h/2, h/2, n, f);
}
-Matrix Matrix::perspective(const Angle &h, double a, double n, double f)
+Matrix Matrix::perspective(const Angle &h, float a, float n, float f)
{
- double hh = tan(h/2.0)*n;
+ float hh = tan(h/2.0f)*n;
return frustum(-hh*a, hh*a, -hh, hh, n, f);
}
current_mode = mode;
}
- glLoadMatrixd(matrices.back().data());
+ glLoadMatrixf(matrices.back().data());
}
MatrixStack &MatrixStack::operator=(const Matrix &m)
namespace Msp {
namespace GL {
-class Matrix: public LinAl::SquareMatrix<double, 4>
+class Matrix: public LinAl::SquareMatrix<float, 4>
{
private:
- typedef LinAl::SquareMatrix<double, 4> Base;
- typedef Geometry::Angle<double> Angle;
+ typedef LinAl::SquareMatrix<float, 4> Base;
+ typedef Geometry::Angle<float> Angle;
public:
Matrix();
Matrix(const float *);
- Matrix(const double *);
- Matrix(const LinAl::Matrix<double, 4, 4> &);
+ Matrix(const LinAl::Matrix<float, 4, 4> &);
- const double *data() const { return &Base::operator()(0, 0); }
+ const float *data() const { return &Base::operator()(0, 0); }
void multiply(const Matrix &);
- void translate(double x, double y, double z) { translate(Vector3(x, y, z)); }
+ void translate(float x, float y, float z) { translate(Vector3(x, y, z)); }
void translate(const Vector3 &);
- void rotate(const Angle &a, double x, double y, double z) { rotate(a, Vector3(x, y, z)); }
+ void rotate(const Angle &a, float x, float y, float z) { rotate(a, Vector3(x, y, z)); }
void rotate(const Angle &, const Vector3 &);
- void rotate(double a, double x, double y, double z) { rotate(Angle::from_radians(a), Vector3(x, y, z)); }
- void rotate(double a, const Vector3 &x) { rotate(Angle::from_radians(a), x); }
- void rotate_deg(double a, double x, double y, double z) { rotate(Angle::from_degrees(a), Vector3(x, y, z)); }
- void rotate_deg(double a, const Vector3 & x) { rotate(Angle::from_degrees(a), x); }
- void scale(double s) { scale(Vector3(s, s, s)); }
- void scale(double x, double y, double z) { scale(Vector3(x, y, z)); }
+ void rotate(float a, float x, float y, float z) { rotate(Angle::from_radians(a), Vector3(x, y, z)); }
+ void rotate(float a, const Vector3 &x) { rotate(Angle::from_radians(a), x); }
+ void rotate_deg(float a, float x, float y, float z) { rotate(Angle::from_degrees(a), Vector3(x, y, z)); }
+ void rotate_deg(float a, const Vector3 & x) { rotate(Angle::from_degrees(a), x); }
+ void scale(float s) { scale(Vector3(s, s, s)); }
+ void scale(float x, float y, float z) { scale(Vector3(x, y, z)); }
void scale(const Vector3 &);
Matrix operator*(const Matrix &) const;
Matrix &operator*=(const Matrix &);
Vector4 operator*(const Vector4 &) const;
Vector3 operator*(const Vector3 &) const;
- double operator[](unsigned) const;
+ float operator[](unsigned) const;
- static Matrix translation(double x, double y, double z) { return translation(Vector3(x, y, z)); }
+ static Matrix translation(float x, float y, float z) { return translation(Vector3(x, y, z)); }
static Matrix translation(const Vector3 &);
- static Matrix rotation(const Angle &a, double x, double y, double z) { return rotation(a, Vector3(x, y, z)); }
+ static Matrix rotation(const Angle &a, float x, float y, float z) { return rotation(a, Vector3(x, y, z)); }
static Matrix rotation(const Angle &, const Vector3 &);
- static Matrix rotation(double a, double x, double y, double z) { return rotation(Angle::from_radians(a), Vector3(x, y, z)); }
- static Matrix rotation(double a, const Vector3 &x) { return rotation(Angle::from_radians(a), x); }
- static Matrix rotation_deg(double a, double x, double y, double z) { return rotation(Angle::from_degrees(a), Vector3(x, y, z)); }
- static Matrix rotation_deg(double a, const Vector3 &x) { return rotation(Angle::from_degrees(a), x); }
- static Matrix scaling(double s) { return scaling(Vector3(s, s, s)); }
- static Matrix scaling(double x, double y, double z) { return scaling(Vector3(x, y, z)); }
+ static Matrix rotation(float a, float x, float y, float z) { return rotation(Angle::from_radians(a), Vector3(x, y, z)); }
+ static Matrix rotation(float a, const Vector3 &x) { return rotation(Angle::from_radians(a), x); }
+ static Matrix rotation_deg(float a, float x, float y, float z) { return rotation(Angle::from_degrees(a), Vector3(x, y, z)); }
+ static Matrix rotation_deg(float a, const Vector3 &x) { return rotation(Angle::from_degrees(a), x); }
+ static Matrix scaling(float s) { return scaling(Vector3(s, s, s)); }
+ static Matrix scaling(float x, float y, float z) { return scaling(Vector3(x, y, z)); }
static Matrix scaling(const Vector3 &);
- static Matrix ortho(double, double, double, double, double, double);
- static Matrix ortho_centered(double, double);
- static Matrix ortho_bottomleft(double, double);
- static Matrix ortho_topleft(double, double);
- static Matrix frustum(double, double, double, double, double, double);
- static Matrix frustum_centered(double, double, double, double);
- static Matrix perspective(const Angle &, double, double, double);
+ static Matrix ortho(float, float, float, float, float, float);
+ static Matrix ortho_centered(float, float);
+ static Matrix ortho_bottomleft(float, float);
+ static Matrix ortho_topleft(float, float);
+ static Matrix frustum(float, float, float, float, float, float);
+ static Matrix frustum_centered(float, float, float, float);
+ static Matrix perspective(const Angle &, float, float, float);
};
class MatrixStack
void ProgramData::uniform(const string &name, const Matrix &m)
{
- float v[16];
- copy(m.data(), m.data()+16, v);
- uniform_matrix4(name, v);
+ uniform_matrix4(name, m.data());
}
void ProgramData::uniform_matrix4(const string &name, const float *v)
if(!enabled_passes.count(tag))
return renderer.render(renderable, tag);
- const double *matrix = light_matrix.data();
+ const float *matrix = light_matrix.data();
// Has side effect of changing the current unit
depth_buf.bind_to(unit);