Bonjour à tous,

J'ai voulut me créer une camera opengl 3, donc on oublie les glRotates et glTranslate...

Mais j'ai un problèmes sur les rotations, en effet j'ai l'impression que cela joue sur la position de la camera et/ou sur la matrice de perspective...

camera.h
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
 
#ifndef CAMERA_H
#define CAMERA_H
 
#include "math_3d.h"
 
class Camera
{
protected:
    Math::Vector3 m_pos;
    Math::Vector3 m_target;
    Math::Vector3 m_up;
private:
    void rotate(float angleX,float angleY, float angleZ);
public:
    Camera();
    Camera(Math::Vector3 pos, Math::Vector3 target, Math::Vector3 up);
 
    void pitch(float angle);
    void roll(float angle);
    void yaw(float angle);
    void move(float dist);
    void lateralStep(float dist);
 
    void reset();
 
    const Math::Vector3 Pos() const{return m_pos;}
    const Math::Vector3 Target() const{return m_target;}
    const Math::Vector3 Up() const{return m_up;}
 
};
 
#endif // CAMERA_H
et le code cpp de la metode pitch (le reste ce doit être la mếme erreur un peu partout :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
void Camera::pitch(float angle)
{
    Math::Mat4 rot;
    Math::Vector3 axe = m_target^m_up;
    rot.InitRotateTransformFromAxis(axe,angle);
    m_target = rot * m_target;
    m_up = rot * m_up;
    m_target.normalize();
    m_up.normalize();
}
Ainsi que la construction de la matrice :
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
 
void Mat4::InitRotateTransformFromAxis(const Vector3 v, const float angle)
        {
            float alpha = ToRadian(angle);
            float x=v[0];
            float x2 = x*x;
            float y=v[1];
            float y2 = y*y;
            float z=v[2];
            float z2 = z*z;
            float c = cos(alpha);
            float s = sin(alpha);
            m_mat[0][0] = x2+(1-x2)*c;   m_mat[0][1] = x*y*(1-c)-z*s; m_mat[0][2] = x*z*(1-c)+y*s; m_mat[0][3] = 0.0f;
            m_mat[1][0] = x*y*(1-c)-z*s; m_mat[1][1] =y2+(1-y2)*c;    m_mat[1][2] = y*z*(1-c)+x*s; m_mat[1][3] = 0.0f;
            m_mat[2][0] = x*z*(1-c)+y*s; m_mat[2][1] = y*z*(1-c)+x*s; m_mat[2][2] = z2+(1-z2)*c;   m_mat[2][3] = 0.0f;
            m_mat[3][0] = 0.0f;          m_mat[3][1] = 0.0f;          m_mat[3][2] = 0.0f;          m_mat[3][3] = 1.0f;
 
        }
Je pourrais utiliser glm, mais j'essaye de tout coder "from scratch", pour bien comprendre. Si vous avez ne serait-ce qu'une piste pour l'erreur, je suis preneur.