return *this;
}
+Vector4 Matrix::operator*(const Vector4 &vec) const
+{
+ if(flags==IDENTITY)
+ return vec;
+ else if(flags==TRANSLATE)
+ return Vector4(vec.x+vec.w*matrix[12], vec.y+vec.w*matrix[13], vec.z+vec.w*matrix[14], vec.w);
+ else if(flags==SCALE)
+ return Vector4(vec.x*matrix[0], vec.y*matrix[5], vec.z*matrix[10], vec.w);
+ else
+ {
+ Vector4 result;
+ result.x = vec.x*matrix[0]+vec.y*matrix[4]+vec.z*matrix[8]+vec.w*matrix[12];
+ result.y = vec.x*matrix[1]+vec.y*matrix[5]+vec.z*matrix[9]+vec.w*matrix[13];
+ result.z = vec.x*matrix[2]+vec.y*matrix[6]+vec.z*matrix[10]+vec.w*matrix[14];
+ result.w = vec.x*matrix[3]+vec.y*matrix[7]+vec.z*matrix[11]+vec.w*matrix[15];
+ return result;
+ }
+}
+
double Matrix::operator[](unsigned i) const
{
if(i>=16)
#include <list>
#include "gl.h"
+#include "vector.h"
namespace Msp {
namespace GL {
void multiply(const Matrix &);
void translate(double, double, double);
+ void translate(const Vector3 &t) { translate(t.x, t.y, t.z); }
void rotate(double, double, double, double);
+ void rotate(double a, const Vector3 &x) { rotate(a, x.x, x.y, x.z); }
void rotate_deg(double, double, double, double);
+ void rotate_deg(double a, const Vector3 & x) { rotate_deg(a, x.x, x.y, x.z); }
void scale(double);
void scale(double, double, double);
Matrix operator*(const Matrix &) const;
Matrix &operator*=(const Matrix &);
+ Vector4 operator*(const Vector4 &) const;
double operator[](unsigned) const;
static Matrix translation(double, double, double);
+ static Matrix translation(const Vector3 &t) { return translation(t.x, t.y, t.z); }
static Matrix rotation(double, double, double, double);
+ static Matrix rotation(double a, const Vector3 &x) { return rotation(a, x.x, x.y, x.z); }
static Matrix rotation_deg(double, double, double, double);
+ static Matrix rotation_deg(double a, const Vector3 &x) { return rotation_deg(a, x.x, x.y, x.z); }
static Matrix scaling(double);
static Matrix scaling(double, double, double);
namespace Msp {
namespace GL {
+struct Vector4;
+
struct Vector3
{
float x, y, z;
Vector3(): x(0), y(0), z(0) { }
Vector3(float x_, float y_, float z_): x(x_), y(y_), z(z_) { }
+ Vector3(const Vector4 &);
};
struct Vector4
Vector4(const Vector3 &v): x(v.x), y(v.y), z(v.z), w(1) { }
};
+inline Vector3::Vector3(const Vector4 &v):
+ x(v.x/v.w), y(v.y/v.w), z(v.z/v.w)
+{ }
+
} // namespace GL
} // namespace Msp