gKit2 light
Loading...
Searching...
No Matches
mat.h
Go to the documentation of this file.
1
2#ifndef _MAT_H
3#define _MAT_H
4
5#include "vec.h"
6
7
10
13
15float radians( const float deg );
17float degrees( const float rad );
18
21{
23 Transform (
24 const float t00= 1, const float t01= 0, const float t02= 0, const float t03= 0,
25 const float t10= 0, const float t11= 1, const float t12= 0, const float t13= 0,
26 const float t20= 0, const float t21= 0, const float t22= 1, const float t23= 0,
27 const float t30= 0, const float t31= 0, const float t32= 0, const float t33= 1 );
28
30 Transform( const Vector& x, const Vector& y, const Vector& z, const Vector& w );
32 Transform( const vec4& x, const vec4& y, const vec4& z, const vec4& w );
33
35 Transform& column( const unsigned id, const float t0, const float t1, const float t2, const float t3 );
37 vec4 column( const unsigned id ) const;
39 vec4 column( const unsigned id );
40
42 Transform& row( const unsigned id, const float t0, const float t1, const float t2, const float t3 );
44 vec4 row( const unsigned id ) const;
46 vec4 row( const unsigned id );
47
49 Transform& column_major( const float matrix[16] );
50
52 Transform& row_major( const float matrix[16] );
53
55 Vector operator[] ( const unsigned c ) const;
56
58 Point operator() ( const Point& p ) const;
60 Vector operator() ( const Vector& v ) const;
62 vec4 operator() ( const vec4& v ) const;
63
65 Transform operator() ( const Transform& b ) const;
66
68 Transform transpose( ) const;
70 Transform inverse( ) const;
72 Transform normal( ) const;
73
75 const float *data( ) const { return &m[0][0]; }
76
77 float m[4][4];
78};
79
82
84Transform Transpose( const Transform& m );
86Transform Inverse( const Transform& m );
88Transform Normal( const Transform& m );
89
91Transform Scale( const float x, const float y, const float z );
92inline Transform Scale( const float s ) { return Scale(s, s, s); }
93
95Transform Translation( const Vector& v );
97Transform Translation( const float x, const float y, const float z );
98
100Transform RotationX( const float angle );
102Transform RotationY( const float angle );
104Transform RotationZ( const float angle );
106Transform Rotation( const Vector& axis, const float angle );
107
109Transform Rotation( const Vector&u, const Vector& v );
110
112Transform Viewport( const float width, const float height );
114Transform Perspective( const float fov, const float aspect, const float znear, const float zfar );
116Transform Ortho( const float left, const float right, const float bottom, const float top, const float znear, const float zfar );
118Transform Lookat( const Point& from, const Point& to, const Vector& up );
119
121Transform compose_transform( const Transform& a, const Transform& b );
123Transform operator* ( const Transform& a, const Transform& b );
124
125#include <iostream>
126
127inline std::ostream& operator<<(std::ostream& o, const Transform& t)
128{
129 o << t.m[0][0] << " " << t.m[0][1] << " " << t.m[0][2] << " " << t.m[0][3] << " " << std::endl;
130 o << t.m[1][0] << " " << t.m[1][1] << " " << t.m[1][2] << " " << t.m[1][3] << " " << std::endl;
131 o << t.m[2][0] << " " << t.m[2][1] << " " << t.m[2][2] << " " << t.m[2][3] << " " << std::endl;
132 o << t.m[3][0] << " " << t.m[3][1] << " " << t.m[3][2] << " " << t.m[3][3] << " " << std::endl;
133 return o;
134}
135
136
138#endif
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Definition mat.cpp:197
Transform Transpose(const Transform &m)
renvoie la transposee de la matrice.
Definition mat.cpp:192
Transform Normal(const Transform &m)
renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m.
Definition mat.cpp:202
Transform Rotation(const Vector &axis, const float angle)
renvoie la matrice representation une rotation de angle degree autour de l'axe axis.
Definition mat.cpp:266
Transform Viewport(const float width, const float height)
renvoie la matrice representant une transformation viewport.
Definition mat.cpp:357
float degrees(const float rad)
conversion en degres.
Definition mat.cpp:15
Transform Identity()
construit la transformation identite.
Definition mat.cpp:187
Transform RotationX(const float angle)
renvoie la matrice representation une rotation de angle degree autour de l'axe X.
Definition mat.cpp:230
Transform compose_transform(const Transform &a, const Transform &b)
renvoie la composition des transformations a et b, t= a * b.
Definition mat.cpp:384
Transform RotationY(const float angle)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Definition mat.cpp:242
Transform Perspective(const float fov, const float aspect, const float znear, const float zfar)
renvoie la matrice representant une transformation projection perspective.
Definition mat.cpp:329
Transform Ortho(const float left, const float right, const float bottom, const float top, const float znear, const float zfar)
renvoie la matrice representant une transformation orthographique, passage d'un cube []x[]x[] vers [-...
Definition mat.cpp:343
Transform operator*(const Transform &a, const Transform &b)
renvoie la composition des transformations a et b, t = a * b.
Definition mat.cpp:394
float radians(const float deg)
conversion en radians.
Definition mat.cpp:10
Transform Translation(const Vector &v)
renvoie la matrice representant une translation par un vecteur.
Definition mat.cpp:216
Transform Lookat(const Point &from, const Point &to, const Vector &up)
renvoie la matrice representant le placement et l'orientation d'une camera pour observer le point to.
Definition mat.cpp:369
Transform RotationZ(const float angle)
renvoie la matrice representation une rotation de angle degree autour de l'axe Z.
Definition mat.cpp:254
Transform Scale(const float x, const float y, const float z)
renvoie la matrice representant une mise a l'echelle / etirement.
Definition mat.cpp:207
representation d'un point 3d.
Definition vec.h:21
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition mat.h:21
Transform & column_major(const float matrix[16])
initialise la matrice avec 16 floats organises par colonne.
Definition mat.cpp:32
Transform & row_major(const float matrix[16])
initialise la matrice avec 16 floats organises par ligne.
Definition mat.cpp:39
Transform(const float t00=1, const float t01=0, const float t02=0, const float t03=0, const float t10=0, const float t11=1, const float t12=0, const float t13=0, const float t20=0, const float t21=0, const float t22=1, const float t23=0, const float t30=0, const float t31=0, const float t32=0, const float t33=1)
constructeur.
Definition mat.cpp:20
Vector operator[](const unsigned c) const
renvoie le Vector colonne c de la matrice
Definition mat.cpp:106
Transform & column(const unsigned id, const float t0, const float t1, const float t2, const float t3)
initialise une colonne de la matrice a partir de 4 floats.
Definition mat.cpp:46
Transform normal() const
renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m.
Definition mat.cpp:181
const float * data() const
renvoie l'adresse de la premiere valeur de la matrice.
Definition mat.h:75
Transform inverse() const
renvoie l'inverse de la matrice.
Definition mat.cpp:399
Transform & row(const unsigned id, const float t0, const float t1, const float t2, const float t3)
initialise une ligne de la matrice.
Definition mat.cpp:68
Point operator()(const Point &p) const
renvoie le point transforme.
Definition mat.cpp:114
Transform transpose() const
renvoie la transposee de la matrice.
Definition mat.cpp:165
representation d'un vecteur 3d.
Definition vec.h:67
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:192