gKit3
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 );
31
33 Transform& column( const int id, const float t0, const float t1, const float t2, const float t3 );
34
36 Transform& row( const int id, const float t0, const float t1, const float t2, const float t3 );
37
39 Transform& column_major( const float matrix[16] );
40
42 Transform& row_major( const float matrix[16] );
43
45 Vector operator[] ( const int c ) const;
46
48 Point operator() ( const Point& p ) const;
50 Vector operator() ( const Vector& v ) const;
52 vec4 operator() ( const vec4& v ) const;
53
55 Transform operator() ( const Transform& b ) const;
56
58 Transform transpose( ) const;
60 Transform inverse( ) const;
62 Transform normal( ) const;
63
65 const float *data( ) const { return &m[0][0]; }
66
67 float m[4][4];
68};
69
72
74Transform Transpose( const Transform& m );
76Transform Inverse( const Transform& m );
78Transform Normal( const Transform& m );
79
81Transform Scale( const float x, const float y, const float z );
82inline Transform Scale( const float s ) { return Scale(s, s, s); }
83
85Transform Translation( const Vector& v );
87Transform Translation( const float x, const float y, const float z );
88
90Transform RotationX( const float angle );
92Transform RotationY( const float angle );
94Transform RotationZ( const float angle );
96Transform Rotation( const Vector& axis, const float angle );
97
99Transform Rotation( const Vector&u, const Vector& v );
100
102Transform Viewport( const float width, const float height );
104Transform Perspective( const float fov, const float aspect, const float znear, const float zfar );
106Transform Ortho( const float left, const float right, const float bottom, const float top, const float znear, const float zfar );
108Transform Lookat( const Point& from, const Point& to, const Vector& up );
109
111Transform compose_transform( const Transform& a, const Transform& b );
113Transform operator* ( const Transform& a, const Transform& b );
114
115#include <iostream>
116
117inline std::ostream& operator<<(std::ostream& o, const Transform& t)
118{
119 o << t.m[0][0] << " " << t.m[0][1] << " " << t.m[0][2] << " " << t.m[0][3] << " " << std::endl;
120 o << t.m[1][0] << " " << t.m[1][1] << " " << t.m[1][2] << " " << t.m[1][3] << " " << std::endl;
121 o << t.m[2][0] << " " << t.m[2][1] << " " << t.m[2][2] << " " << t.m[2][3] << " " << std::endl;
122 o << t.m[3][0] << " " << t.m[3][1] << " " << t.m[3][2] << " " << t.m[3][3] << " " << std::endl;
123 return o;
124}
125
126
128#endif
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Definition mat.cpp:163
Transform Transpose(const Transform &m)
renvoie la transposee de la matrice.
Definition mat.cpp:158
Transform Normal(const Transform &m)
renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m.
Definition mat.cpp:168
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:232
Transform Viewport(const float width, const float height)
renvoie la matrice representant une transformation viewport.
Definition mat.cpp:323
float degrees(const float rad)
conversion en degres.
Definition mat.cpp:15
Transform Identity()
construit la transformation identite.
Definition mat.cpp:153
Transform RotationX(const float angle)
renvoie la matrice representation une rotation de angle degree autour de l'axe X.
Definition mat.cpp:196
Transform compose_transform(const Transform &a, const Transform &b)
renvoie la composition des transformations a et b, t= a * b.
Definition mat.cpp:350
Transform RotationY(const float angle)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Definition mat.cpp:208
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:295
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:309
Transform operator*(const Transform &a, const Transform &b)
renvoie la composition des transformations a et b, t = a * b.
Definition mat.cpp:360
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:182
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:335
Transform RotationZ(const float angle)
renvoie la matrice representation une rotation de angle degree autour de l'axe Z.
Definition mat.cpp:220
Transform Scale(const float x, const float y, const float z)
renvoie la matrice representant une mise a l'echelle / etirement.
Definition mat.cpp:173
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:50
Transform & row_major(const float matrix[16])
initialise la matrice avec 16 floats organises par ligne.
Definition mat.cpp:57
Transform & column(const int 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:32
Transform & row(const int id, const float t0, const float t1, const float t2, const float t3)
initialise une ligne de la matrice.
Definition mat.cpp:41
Transform normal() const
renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m.
Definition mat.cpp:147
const float * data() const
renvoie l'adresse de la premiere valeur de la matrice.
Definition mat.h:65
Transform inverse() const
renvoie l'inverse de la matrice.
Definition mat.cpp:365
Vector operator[](const int c) const
renvoie le Vector colonne c de la matrice
Definition mat.cpp:72
Point operator()(const Point &p) const
renvoie le point transforme.
Definition mat.cpp:80
Transform transpose() const
renvoie la transposee de la matrice.
Definition mat.cpp:131
representation d'un vecteur 3d.
Definition vec.h:58
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:171