Bonjour,

Alors voilà, je cherche à faire une classe matrice de transformation pour de la 2D.
Avant toute chose, je sais qu'il existe des librairies qui pourraient faire ce que je cherche à faire. Mais tout ceci n'a qu'un aspect pédagogique donc je voudrais le faire moi même .

Je sais aussi que le sujet à été traité de nombreuses fois (et j'ai lu les articles), cependant j'aimerais avoir l'avis d'un professionnel.

Que puis-je améliorer dans l'implémentation suivante ?
Je parle essentiellement de la manière donc l'information est stockée ainsi que des méthodes d'accès.

Merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
#ifndef CMATRIX_H
#define CMATRIX_H
 
#include <cassert>
#include <string>
 
#define MATRIX_SIZE 4
 
template<class T>
class CMatrixRow;
 
template<class T = float>
class CMatrix
{
public:
    /*====================================
        Constructeurs & Destructeurs
    ====================================*/
    CMatrix()
    {
        for(uint8_t i = 0; i < MATRIX_SIZE; i++)
        {
            (*this)[i][i] = 1;
        }
    }
 
    CMatrix(const CMatrix& other)
    {
        for(uint8_t i = 0; i < MATRIX_SIZE; i++)
        {
            for(uint8_t j = 0; j < MATRIX_SIZE; j++)
            {
                (*this)[i][j] = other.get(i, j);
            }
        }
    }
 
    CMatrix& operator=(const CMatrix& other)
    {
        if(this != &other)
        {
            for(uint8_t i = 0; i < MATRIX_SIZE; i++)
            {
                for(uint8_t j = 0; j < MATRIX_SIZE; j++)
                {
                    (*this)[i][j] = other.get(i, j);
                }
            }
        }
 
        return *this;
    }
 
    ~CMatrix(){}
 
    /*====================================
       Accesseurs
    ====================================*/
    T get(uint8_t i, uint8_t j) const
    {
        return m_rows[i].get(j);
    }
 
    CMatrixRow<T>& operator[](int index)
    {
        return m_rows[index];
    }
 
private:
    /*====================================
        Données membres
    ====================================*/
    CMatrixRow<T>    m_rows[MATRIX_SIZE];
};
 
/*====================================
    Type intermédiaire CMatrixRow
====================================*/
template<class T = float>
class CMatrixRow{
    friend class CMatrix<T>;
public:
    // Accesseurs
    T get(uint8_t i) const
    {
        return m_column[i];
    }
 
    T& operator[](int index)
    {
        assert(index >= 0 && index < 4);
        return m_column[index];
    }
 
private:
    // Constructeurs
    CMatrixRow()
    {
        for(uint8_t i = 0; i < MATRIX_SIZE; i++)
        {
            m_column[i] = 0;
        }
    }
 
    // Données membres
    T m_column[MATRIX_SIZE];
};
 
#endif // CMATRIX_H