IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Développement 2D, 3D et Jeux Discussion :

Questions sur les quaternions.


Sujet :

Développement 2D, 3D et Jeux

  1. #1
    Rédacteur
    Avatar de Bakura
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    1 386
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 386
    Points : 2 640
    Points
    2 640
    Par défaut Questions sur les quaternions.
    Bonjour,

    Voilà j'apprends actuellement avec le livre 3d Math Primer for Graphics and Game Development les rudiments des mathématiques (matrices, vecteurs, quaternions...). Les vecteurs n'étaient pas nouveaux mais les matrices, quaternions et angles d'euler, si.

    Mais j'ai un peu de soucis à comprendre quelques fonctions qu'ils incluent dans leur code. Par exemple, dans la classe d'une matrice de rotation, il y a deux fonctions pour créer une matrice de rotation à partir d'un quaternion : fromInertialToObjectQuaternion et fromObjectToInertialQuaternion, le suel changement étant certains signes. J'ai bien compris ce qu'était les coordonnées objet et inertial (comment on dit en français ?), mais je comprends pas l'intérêt de ces deux fonctions, alors que la FAQ n'en donne qu'une seule.

  2. #2
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Je n'ai jamais vu une telle distinction dans les moteurs 3D que j'ai pu utiliser. C'est quoi la différence entre "object" et "inertial" ?

  3. #3
    Rédacteur
    Avatar de Bakura
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    1 386
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 386
    Points : 2 640
    Points
    2 640
    Par défaut
    Moi aussi ça m'étonne, mais ils font cette distinction partout. Dans la classe EulerAngles tu as :

    fromObjectToIntertialQuaternion
    fromInertialToObjectQuaternion

    fromObjectToWorldMatrix
    fromWorldToObjectMatrix

    Pour les quaternions !

    setRotateObjectToInertial (const EulerAngles & orientation)
    setRotateInertialToObject ("")

    Et pour le cas précis que j'ai dit en premier message :

    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
    //---------------------------------------------------------------------------
    // RotationMatrix::fromInertialToObjectQuaternion
    //
    // Setup the matrix, given a quaternion that performs an inertial->object
    // rotation
    //
    // See 10.6.3
     
    void	RotationMatrix::fromInertialToObjectQuaternion(const Quaternion &q) {
     
    	// Fill in the matrix elements.  This could possibly be
    	// optimized since there are many common subexpressions.
    	// We'll leave that up to the compiler...
     
    	m11 = 1.0f - 2.0f * (q.y*q.y + q.z*q.z);
    	m12 = 2.0f * (q.x*q.y + q.w*q.z);
    	m13 = 2.0f * (q.x*q.z - q.w*q.y);
     
    	m21 = 2.0f * (q.x*q.y - q.w*q.z);
    	m22 = 1.0f - 2.0f * (q.x*q.x + q.z*q.z);
    	m23 = 2.0f * (q.y*q.z + q.w*q.x);
     
    	m31 = 2.0f * (q.x*q.z + q.w*q.y);
    	m32 = 2.0f * (q.y*q.z - q.w*q.x);
    	m33 = 1.0f - 2.0f * (q.x*q.x + q.y*q.y);
     
    }
     
    //---------------------------------------------------------------------------
    // RotationMatrix::fromObjectToInertialQuaternion
    //
    // Setup the matrix, given a quaternion that performs an object->inertial
    // rotation
    //
    // See 10.6.3
     
    void	RotationMatrix::fromObjectToInertialQuaternion(const Quaternion &q) {
     
    	// Fill in the matrix elements.  This could possibly be
    	// optimized since there are many common subexpressions.
    	// We'll leave that up to the compiler...
     
    	m11 = 1.0f - 2.0f * (q.y*q.y + q.z*q.z);
    	m12 = 2.0f * (q.x*q.y - q.w*q.z);
    	m13 = 2.0f * (q.x*q.z + q.w*q.y);
     
    	m21 = 2.0f * (q.x*q.y + q.w*q.z);
    	m22 = 1.0f - 2.0f * (q.x*q.x + q.z*q.z);
    	m23 = 2.0f * (q.y*q.z - q.w*q.x);
     
    	m31 = 2.0f * (q.x*q.z - q.w*q.y);
    	m32 = 2.0f * (q.y*q.z + q.w*q.x);
    	m33 = 1.0f - 2.0f * (q.x*q.x + q.y*q.y);
    }
     
    //---------------------------------------------------------------------------
    // RotationMatrix::inertialToObject
    //
    // Rotate a vector from inertial to object space
     
    Vector3	RotationMatrix::inertialToObject(const Vector3 &v) const {
     
    	// Perform the matrix multiplication in the "standard" way.
     
    	return Vector3(
    		m11*v.x + m21*v.y + m31*v.z,
    		m12*v.x + m22*v.y + m32*v.z,
    		m13*v.x + m23*v.y + m33*v.z
    	);
    }
     
    //---------------------------------------------------------------------------
    // RotationMatrix::objectToInertial
    //
    // Rotate a vector from object to inertial space
     
    Vector3	RotationMatrix::objectToInertial(const Vector3 &v) const {
     
    	// Multiply by the transpose
     
    	return Vector3(
    		m11*v.x + m12*v.y + m13*v.z,
    		m21*v.x + m22*v.y + m23*v.z,
    		m31*v.x + m32*v.y + m33*v.z
    	);
    J'avoue être un petit peu perdu dans tout ça... Là je suis en train d'écrire mes classes, je ne sais pas du tout si je choisi les bonnes fonctions...

  4. #4
    Rédacteur
    Avatar de Bakura
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    1 386
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 386
    Points : 2 640
    Points
    2 640
    Par défaut
    Et je rajoute aussi la fonction pour calculer la matrice de rotation à partir d'un triplet d'angle d'Euler. Je ne sais pas si elle est correct

    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
    // On initialise la matrice avec une orientation via un triplet d'angles d'Euler
    			RotationMatrix & initFromEulerAngles (const EulerAngles<T> & euler)
    			{
    				// On commence par calculer les cosinus et sinus des angles, en radians
    				T cHeading (cos (euler.heading)), sHeading (sin (euler.heading));
    				T cPitch (cos (euler.pitch)), sPitch (sin (euler.pitch));
    				T cBank (cos (euler.bank)), sBank (sin (euler.bank));
     
    				// Puis on construit la matrice de rotation
    				m00 = cHeading * cBank + sHeading * sPitch * sBank;
    				m01 = -cHeading * sBank + sHeading * sPitch * cBank;
    				m02 = sHeading * cPitch;
     
    				m10 = sBank * cPitch;
    				m11 = cBank * cPitch;
    				m12 = -sPitch;
     
    				m20 = -sHeading * cBank + cHeading * sPitch * sBank;
    				m21 = sBank * sHeading + cHeading * sPitch * cBank;
    				m22 = cHeading * cPitch;
     
    				return *this;
    			}

  5. #5
    Membre averti
    Homme Profil pro
    Game Graphics Programmer
    Inscrit en
    Août 2006
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Game Graphics Programmer
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2006
    Messages : 408
    Points : 392
    Points
    392
    Par défaut
    Bah, WorldMatrix est la matrice du monde est ObjectMatrix est la matrice locale d'un objet. Un point défini localement sur un objet doit être transformé en point dans la matrice du monde avant d'être affiché.
    Je suppose que c'est la même chose pour IntertialQuaternion et ObjectQuaternion (pour les rotations ou les points, dans ce cas).

  6. #6
    Rédacteur
    Avatar de Bakura
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    1 386
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 386
    Points : 2 640
    Points
    2 640
    Par défaut
    Merci Kurisu pour ta réponse.

    J'aurais une petite question supplémentaire : comment dit-on en français une matrice "column major" ou "row major" ? J'ai pensé à matrice à colonne mais ça me paraît étrange...

  7. #7
    Membre averti
    Homme Profil pro
    Game Graphics Programmer
    Inscrit en
    Août 2006
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Game Graphics Programmer
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2006
    Messages : 408
    Points : 392
    Points
    392
    Par défaut
    "majeur de colonne" et "majeur de ligne"
    J'en sais rien à vrai dire...

  8. #8
    Rédacteur
    Avatar de bafman
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    2 574
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2003
    Messages : 2 574
    Points : 5 323
    Points
    5 323
    Par défaut
    moi, je dirait ordonnée par colonne ou ordonnée par ligne, tout simplement
    * Il est infiniment plus simple de faire rapidement un code qui marche que de faire un code rapide qui marche
    * pour faciliter les recherches, n'oubliez pas de voter pour les réponses pertinentes
    Mes articles

  9. #9
    Rédacteur
    Avatar de Bakura
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2005
    Messages
    1 386
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 386
    Points : 2 640
    Points
    2 640
    Par défaut
    ordonné par colonne, ça me paraît bien en effet . Parceque majeur de colonne, ça fait bizarre :p.

Discussions similaires

  1. Question sur les quaternions, demande de concret
    Par LapinGarou dans le forum Moteurs 3D
    Réponses: 5
    Dernier message: 11/04/2007, 17h09
  2. question sur les vertex buffer et index buffer
    Par airseb dans le forum DirectX
    Réponses: 9
    Dernier message: 25/08/2003, 02h38
  3. question sur les variables globales et les thread posix
    Par souris_sonic dans le forum POSIX
    Réponses: 5
    Dernier message: 13/06/2003, 13h59
  4. Question sur les handles et les couleurs...
    Par MrDuChnok dans le forum C++Builder
    Réponses: 7
    Dernier message: 29/10/2002, 08h45
  5. question sur les message box !
    Par krown dans le forum Langage
    Réponses: 7
    Dernier message: 02/08/2002, 16h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo