|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
OPENGL: CLASSE CAMERA QUI GÈRE LE GLULOOKAT
Information sur la source
Description
Bonjour. c'est une petite classe pour gérer la Camera qui se veut être suffisante pour tous les programmes opengl que j'aurais envie d'écrire il manque principalement l'option Lock pour les rotations et les déplacement mais je pense que cette option s'implémente facilement au cas par cas je me sers de la classe "vecteur 3d" NxVec3 du physx SDK d'ageia
Source
- #define NxReal double
-
- NxReal from[3] = {-10,0,0};
- NxReal to[3] = {0,0,0};
- NxReal up[3] = {0,1,0};
- camera = new Camera(from,to,up);
- camera->setModeLock(true,true,false);
- camera->setMinMaxCurrentUpDown(-M_PI/6,M_PI/6,0);
- camera->setMinMaxCurrentLeftRight(-M_PI/12,M_PI/12,0);
-
- /************************************************************************/
- switch ( key ) {
- case 'q':
- case 27: // la touche Echappement
- exit( 0 );
- break;
- case 'o':
- camera->rotateUpLockSrc();
- break;
- case 'l':
- camera->rotateDownLockSrc();
- break;
- case 'i':
- camera->rotateUpLockDst();
- break;
- case 'k':
- camera->rotateDownLockDst();
- break;
- case 'u':
- camera->rotateSideLeft();
- break;
- case 'j':
- camera->rotateSideRight();
- break;
- case 'r':
- camera->moveFront(0.5);
- break;
- case 'f':
- camera->moveBack(0.5);
- break;
- case 'd':
- camera->moveLeft(0.5);
- break;
- case 'g':
- camera->moveRight(0.5);
- break;
- case 'w':
- camera->rotateLeftLockSrc();
- break;
- case 'x':
- camera->rotateRightLockSrc();
- break;
- case 'h':
- camera->rotateUpLockSrcKeepUpAndFront();
- break;
- case 'n':
- camera->rotateDownLockSrcKeepUpAndFront();
- break;
- case '+':
- camera->setDistanceFromToLockTo(camera->distanceFromTo/1.3);
- break;
- case '-':
- camera->setDistanceFromToLockTo(camera->distanceFromTo*1.3);
- break;
- }
- /************************************************************************/
- class Camera {
- public:
- Camera(NxReal *_from, NxReal *_to, NxReal *_up);
- void lookAt();
- void moveFront();
- void moveBack();
- void moveUp();
- void moveDown();
- void moveLeft();
- void moveRight();
- void rotateUpLockSrc();
- void rotateDownLockSrc();
- void rotateUpLockSrcKeepUpAndFront();
- void rotateDownLockSrcKeepUpAndFront();
- void rotateLeftLockSrc();
- void rotateRightLockSrc();
- void rotateUpLockDst();
- void rotateDownLockDst();
- void rotateLeftLockDst();
- void rotateRightLockDst();
- void rotateSideLeft();
- void rotateSideRight();
- void move(NxReal *_direction);
- void moveFront(NxReal _distance);
- void moveBack(NxReal _distance);
- void moveUp(NxReal _distance);
- void moveDown(NxReal _distance);
- void moveLeft(NxReal _distance);
- void moveRight(NxReal _distance);
- void rotateUpLockSrc(NxReal _angle);
- void rotateDownLockSrc(NxReal _angle);
- void rotateUpLockSrcKeepUpAndFront(NxReal _angle);
- void rotateDownLockSrcKeepUpAndFront(NxReal _angle);
- void rotateLeftLockSrc(NxReal _angle);
- void rotateRightLockSrc(NxReal _angle);
- void rotateUpLockDst(NxReal _angle);
- void rotateDownLockDst(NxReal _angle);
- void rotateLeftLockDst(NxReal _angle);
- void rotateRightLockDst(NxReal _angle);
- void rotateSideLeft(NxReal _angle);
- void rotateSideRight(NxReal _angle);
- void setDistanceStep(NxReal _magnitudeStepUp, NxReal _magnitudeStepFront, NxReal _magnitudeStepLeft);
- void setAllAngleStep(NxReal _angle);
- void setAngleStep(NxReal _stepAngleUpDown, NxReal _stepAngleLeftRight, NxReal _stepAngleSide);
- void setFrom(NxReal *_from);
- void setTo(NxReal *_to);
- void setUp(NxReal *_up);
- void setFromToUp(NxReal *_from, NxReal *_to, NxReal *_up);
- void setDistanceFromToLockFrom(NxReal _distanceFromTo);
- void setDistanceFromToLockTo(NxReal _distanceFromTo);
- void setModeLock(bool _modeLockUpDown, bool _modeLockLeftRight, bool _modeLockSide);
- void setMinMaxCurrentUpDown(NxReal _minUpDown, NxReal _maxUpDown, NxReal _currentUpDown);
- void setMinMaxCurrentLeftRight(NxReal _minLeftRight, NxReal _maxLeftRight, NxReal _currentLeftRight);
- void setMinMaxCurrentSide(NxReal _minSide, NxReal _maxSide, NxReal _currentSide);
- void setAllMinMaxCurrent(NxReal _angle);
- void calculateStepVectors();
- NxVec3 // points:
- from,
- to,
- // normalized vectors:
- up,
- left,
- front,
- // balanced vectors:
- stepUp,
- stepLeft,
- stepFront;
-
- NxReal sinUpDown,
- cosUpDown,
- stepAngleUpDown,
- sinLeftRight,
- cosLeftRight,
- stepAngleLeftRight,
- sinSide,
- cosSide,
- stepAngleSide;
- // distance and vector from - to :
- NxReal distanceFromTo;
- NxVec3 fromTo;
-
- bool modeLockUpDown,
- modeLockLeftRight,
- modeLockSide;
-
- NxReal magnitudeStepUp,
- magnitudeStepFront,
- magnitudeStepLeft,
- maxUpDown,
- minUpDown,
- currentUpDown,
- maxLeftRight,
- minLeftRight,
- currentLeftRight,
- maxSide,
- minSide,
- currentSide;
- };
- /************************************************************************/
- class NxVec3
- {
- public:
- NxVec3 ();
- NxVec3 (NxReal a);
- NxVec3 (NxReal nx, NxReal ny, NxReal nz);
- NxVec3 (const NxReal v[]);
- NxVec3 (const NxReal v[], bool normalized);
- NxVec3 (const NxVec3& v);
- NxVec3 (const NxVec3& v, bool normalized);
- const NxVec3& operator=(const NxVec3&);
- const NxReal *get() const;
- NxReal* get();
- bool operator< (const NxVec3&) const;
- bool operator==(const NxVec3&) const;
- bool operator!=(const NxVec3&) const;
- void set(const NxVec3 &);
- void setx(const NxReal & d);
- void sety(const NxReal & d);
- void setz(const NxReal & d);
- void setNegative(const NxVec3 &a);
- void setNegative();
- void set(NxReal, NxReal, NxReal);
- void set(NxReal);
- void zero();
- void setPlusInfinity();
- void setMinusInfinity();
- void add(const NxVec3 & a, const NxVec3 & b);
- void subtract(const NxVec3 &a, const NxVec3 &b);
- void multiply(NxReal s, const NxVec3 & a);
- void arrayMultiply(const NxVec3 &a, const NxVec3 &b);
- void multiplyAdd(NxReal s, const NxVec3 & a, const NxVec3 & b);
- NxReal normalize();
- void setMagnitude(NxReal);
- bool isFinite() const;
- NxReal dot(const NxVec3 &other) const;
- bool sameDirection(const NxVec3 &) const;
- NxReal magnitude() const;
- NxReal magnitudeSquared() const;
- NxReal distance(const NxVec3 &) const;
- NxReal distanceSquared(const NxVec3 &v) const;
- void cross(const NxVec3 &left, const NxVec3 & right);
- void cross(const NxVec3 &left, const NxVec3 & right, bool normalized);
- bool equals(const NxVec3 &, NxReal epsilon) const;
- void rotate (NxReal angle, const NxVec3 &axe);
- void rotate (NxReal sin_angle, NxReal cos_angle, const NxVec3 &axe);
- void rotate (const NxVec3 &axe);
- NxVec3 operator -() const;
- NxVec3 operator +(const NxVec3 & v) const;
- NxVec3 operator -(const NxVec3 & v) const;
- NxVec3 operator *(NxReal f) const;
- NxVec3 operator /(NxReal f) const;
- NxVec3 &operator +=(const NxVec3& v);
- NxVec3 &operator -=(const NxVec3& v);
- NxVec3 &operator *=(NxReal f);
- NxVec3 &operator /=(NxReal f);
- NxVec3 cross(const NxVec3& v) const;
- NxVec3 operator^(const NxVec3& v) const;
- NxReal operator|(const NxVec3& v) const;
- NxReal x,y,z;
- };
#define NxReal double
NxReal from[3] = {-10,0,0};
NxReal to[3] = {0,0,0};
NxReal up[3] = {0,1,0};
camera = new Camera(from,to,up);
camera->setModeLock(true,true,false);
camera->setMinMaxCurrentUpDown(-M_PI/6,M_PI/6,0);
camera->setMinMaxCurrentLeftRight(-M_PI/12,M_PI/12,0);
/************************************************************************/
switch ( key ) {
case 'q':
case 27: // la touche Echappement
exit( 0 );
break;
case 'o':
camera->rotateUpLockSrc();
break;
case 'l':
camera->rotateDownLockSrc();
break;
case 'i':
camera->rotateUpLockDst();
break;
case 'k':
camera->rotateDownLockDst();
break;
case 'u':
camera->rotateSideLeft();
break;
case 'j':
camera->rotateSideRight();
break;
case 'r':
camera->moveFront(0.5);
break;
case 'f':
camera->moveBack(0.5);
break;
case 'd':
camera->moveLeft(0.5);
break;
case 'g':
camera->moveRight(0.5);
break;
case 'w':
camera->rotateLeftLockSrc();
break;
case 'x':
camera->rotateRightLockSrc();
break;
case 'h':
camera->rotateUpLockSrcKeepUpAndFront();
break;
case 'n':
camera->rotateDownLockSrcKeepUpAndFront();
break;
case '+':
camera->setDistanceFromToLockTo(camera->distanceFromTo/1.3);
break;
case '-':
camera->setDistanceFromToLockTo(camera->distanceFromTo*1.3);
break;
}
/************************************************************************/
class Camera {
public:
Camera(NxReal *_from, NxReal *_to, NxReal *_up);
void lookAt();
void moveFront();
void moveBack();
void moveUp();
void moveDown();
void moveLeft();
void moveRight();
void rotateUpLockSrc();
void rotateDownLockSrc();
void rotateUpLockSrcKeepUpAndFront();
void rotateDownLockSrcKeepUpAndFront();
void rotateLeftLockSrc();
void rotateRightLockSrc();
void rotateUpLockDst();
void rotateDownLockDst();
void rotateLeftLockDst();
void rotateRightLockDst();
void rotateSideLeft();
void rotateSideRight();
void move(NxReal *_direction);
void moveFront(NxReal _distance);
void moveBack(NxReal _distance);
void moveUp(NxReal _distance);
void moveDown(NxReal _distance);
void moveLeft(NxReal _distance);
void moveRight(NxReal _distance);
void rotateUpLockSrc(NxReal _angle);
void rotateDownLockSrc(NxReal _angle);
void rotateUpLockSrcKeepUpAndFront(NxReal _angle);
void rotateDownLockSrcKeepUpAndFront(NxReal _angle);
void rotateLeftLockSrc(NxReal _angle);
void rotateRightLockSrc(NxReal _angle);
void rotateUpLockDst(NxReal _angle);
void rotateDownLockDst(NxReal _angle);
void rotateLeftLockDst(NxReal _angle);
void rotateRightLockDst(NxReal _angle);
void rotateSideLeft(NxReal _angle);
void rotateSideRight(NxReal _angle);
void setDistanceStep(NxReal _magnitudeStepUp, NxReal _magnitudeStepFront, NxReal _magnitudeStepLeft);
void setAllAngleStep(NxReal _angle);
void setAngleStep(NxReal _stepAngleUpDown, NxReal _stepAngleLeftRight, NxReal _stepAngleSide);
void setFrom(NxReal *_from);
void setTo(NxReal *_to);
void setUp(NxReal *_up);
void setFromToUp(NxReal *_from, NxReal *_to, NxReal *_up);
void setDistanceFromToLockFrom(NxReal _distanceFromTo);
void setDistanceFromToLockTo(NxReal _distanceFromTo);
void setModeLock(bool _modeLockUpDown, bool _modeLockLeftRight, bool _modeLockSide);
void setMinMaxCurrentUpDown(NxReal _minUpDown, NxReal _maxUpDown, NxReal _currentUpDown);
void setMinMaxCurrentLeftRight(NxReal _minLeftRight, NxReal _maxLeftRight, NxReal _currentLeftRight);
void setMinMaxCurrentSide(NxReal _minSide, NxReal _maxSide, NxReal _currentSide);
void setAllMinMaxCurrent(NxReal _angle);
void calculateStepVectors();
NxVec3 // points:
from,
to,
// normalized vectors:
up,
left,
front,
// balanced vectors:
stepUp,
stepLeft,
stepFront;
NxReal sinUpDown,
cosUpDown,
stepAngleUpDown,
sinLeftRight,
cosLeftRight,
stepAngleLeftRight,
sinSide,
cosSide,
stepAngleSide;
// distance and vector from - to :
NxReal distanceFromTo;
NxVec3 fromTo;
bool modeLockUpDown,
modeLockLeftRight,
modeLockSide;
NxReal magnitudeStepUp,
magnitudeStepFront,
magnitudeStepLeft,
maxUpDown,
minUpDown,
currentUpDown,
maxLeftRight,
minLeftRight,
currentLeftRight,
maxSide,
minSide,
currentSide;
};
/************************************************************************/
class NxVec3
{
public:
NxVec3 ();
NxVec3 (NxReal a);
NxVec3 (NxReal nx, NxReal ny, NxReal nz);
NxVec3 (const NxReal v[]);
NxVec3 (const NxReal v[], bool normalized);
NxVec3 (const NxVec3& v);
NxVec3 (const NxVec3& v, bool normalized);
const NxVec3& operator=(const NxVec3&);
const NxReal *get() const;
NxReal* get();
bool operator< (const NxVec3&) const;
bool operator==(const NxVec3&) const;
bool operator!=(const NxVec3&) const;
void set(const NxVec3 &);
void setx(const NxReal & d);
void sety(const NxReal & d);
void setz(const NxReal & d);
void setNegative(const NxVec3 &a);
void setNegative();
void set(NxReal, NxReal, NxReal);
void set(NxReal);
void zero();
void setPlusInfinity();
void setMinusInfinity();
void add(const NxVec3 & a, const NxVec3 & b);
void subtract(const NxVec3 &a, const NxVec3 &b);
void multiply(NxReal s, const NxVec3 & a);
void arrayMultiply(const NxVec3 &a, const NxVec3 &b);
void multiplyAdd(NxReal s, const NxVec3 & a, const NxVec3 & b);
NxReal normalize();
void setMagnitude(NxReal);
bool isFinite() const;
NxReal dot(const NxVec3 &other) const;
bool sameDirection(const NxVec3 &) const;
NxReal magnitude() const;
NxReal magnitudeSquared() const;
NxReal distance(const NxVec3 &) const;
NxReal distanceSquared(const NxVec3 &v) const;
void cross(const NxVec3 &left, const NxVec3 & right);
void cross(const NxVec3 &left, const NxVec3 & right, bool normalized);
bool equals(const NxVec3 &, NxReal epsilon) const;
void rotate (NxReal angle, const NxVec3 &axe);
void rotate (NxReal sin_angle, NxReal cos_angle, const NxVec3 &axe);
void rotate (const NxVec3 &axe);
NxVec3 operator -() const;
NxVec3 operator +(const NxVec3 & v) const;
NxVec3 operator -(const NxVec3 & v) const;
NxVec3 operator *(NxReal f) const;
NxVec3 operator /(NxReal f) const;
NxVec3 &operator +=(const NxVec3& v);
NxVec3 &operator -=(const NxVec3& v);
NxVec3 &operator *=(NxReal f);
NxVec3 &operator /=(NxReal f);
NxVec3 cross(const NxVec3& v) const;
NxVec3 operator^(const NxVec3& v) const;
NxReal operator|(const NxVec3& v) const;
NxReal x,y,z;
};
Conclusion
si quelqu'un a des commentaires sur pourquoi il faut tout refaire, ou encore mieux des idées pour l'améliorer... :) merci
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Historique
- 04 mars 2007 20:04:34 :
- pas de mise à jour
- 05 mars 2007 17:07:05 :
- ajout/modification de méthodes: ajout du mode lock pour les rotations, et de la rotation haut bas qui garde l'horizontale et la verticale (présente dans beaucoup de jeux)
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Moteur 3d OpenGL [ par Stormy ]
Salut. Je recherche des personnes motives pour travailler sur un moteur 3d sous OpenGL. Les bases sont deja etablies (Detection de collisions, sons, m
Objects 3D Opengl [ par mastave ]
Comment inclure dans un fenêtre OpenGl un fichier 3D DXF ou3DS???
Camera Opengl [ par sniperfou ]
Salut a tous,j'ai un probleme avec opengl car je voudrais faire tourner ma camera autour d'un cube mais je ne connait pas les fonctions qui permettent
OpenGl et objets 3D [ par mshn ]
bonjour, est ce qu'on peux céer des objets 3D sous OpenGl, et les manipuler (animer et déplacer) par programme en utilisant un environnement de C++ ?
opengl bug [ par darmoor ]
Voila je vien de debuter dans l'openGL et selon le tutorial jai fait ce qu'il falai et sa me marque une erreur:le code:#include <windows.h>#incl
Charger un model 3D en C++ avec opengl [ par smoove5198 ]
Bonjour,j'essaye depuis un moment de charger un model 3D avec opengl en C++, pour ca j'utilise le seul format de fichier que je connaisse et dont j'ai
Projet OpenGl [ par barraq ]
salut,Voila j'ai un projet a faire pour ma fac, je doit réaliser tout un environement 3d en opengl .Je doit pouvoir me deplacer dans une map donnée et
3d opengl [ par darvil ]
Qui peu m'aider?je cherche de quoi developer sur mac en 3d . Je cherche une adreese ou tlecharger un compilateur des logiciels 3d. comment fair march
Problème avec OpenGL [ par Xaviou ]
Bonjour, Je suis en train de réaliser un prog permettant de visualiser des fichiers 3D au format STL. Si j'éxécute mon prog depuis Visu
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|