Accueil > > > OPENGL: CLASSE CAMERA QUI GÈRE LE GLULOOKAT
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
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
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
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|