je cherche à faire ma class camera, mais si pour la translation elle marche bien, il n'en va pas de même pour la rotation.
Donc je cherche soit une class toute faite pour prendre exemple, soit si quelqu'un a le courage de se pencher sur mon code...
Je ne souhaite pas utiliser de quaternion, vu que je ne les ai jamais étudié.
Il est important aussi pour moi d'avoir une matrice inversée prête à l'emploi (la matrice back dans mon code).
Enfin, c'est destiné à du calcul assez lourd, donc la classe devra être assez performante.
Voici ma class:
CODE
#include "Camera.hpp"
#include <iostream>
#include "Math3D/Vector3D.hpp"
using namespace std;
Camera::Camera(){
back = Matrix4();
back.loadIdentity();
rx=ry=rz=tx=ty=tz=0;
}
void Camera::rotatef(float angle, float x, float y, float z){
Vector3D v(x,y,z);
Vector3D vt = back*v;
back.rotatef(-angle,x,y,z);
rx+=vt.getX()*angle;
ry+=vt.getY()*angle;
rz+=vt.getZ()*angle;
}
void Camera::translatef(float x, float y, float z){
Vector3D v(-x,-y,-z);
Vector3D vt = back*v;
tx+=vt.getX();
ty+=vt.getY();
tz+=vt.getZ();
back.translatef(x,y,z);
}
void Camera::setPerspective(){
glLoadIdentity();
glRotatef(rx,1,0,0);
glRotatef(ry,0,1,0);
glRotatef(rz,0,0,1);
glTranslatef(tx,ty,tz);
}
J'ai aussi une autre question :
Soit deux rotations successives :
glRotatef(20,1,0,0);
glRotatef(10,0,1,0);
-> Quel serait l'équivalent en un seul appel?
Merci à tous.
Je rajoute le header au cas où :
CODE
#ifndef CAMERA_H
#define CAMERA_H 1
#include "Math3D/Matrix4.hpp"
#include "GL/gl.h"
class Camera{
private:
Matrix4 back;
float tx,ty,tz;
float rx,ry,rz;
protected:
public:
Camera();
void rotatef(float angle, float x, float y, float z);
void translatef(float x, float y, float z);
void setPerspective();
};
#endif
#define CAMERA_H 1
#include "Math3D/Matrix4.hpp"
#include "GL/gl.h"
class Camera{
private:
Matrix4 back;
float tx,ty,tz;
float rx,ry,rz;
protected:
public:
Camera();
void rotatef(float angle, float x, float y, float z);
void translatef(float x, float y, float z);
void setPerspective();
};
#endif