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

OpenGL Discussion :

Concepts géométriques complexes


Sujet :

OpenGL

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur Autodidacte
    Inscrit en
    Janvier 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Autodidacte

    Informations forums :
    Inscription : Janvier 2008
    Messages : 46
    Points : 36
    Points
    36
    Par défaut Concepts géométriques complexes
    Bonjour

    Je cherche les équations mathématiques permettant de se déplacer le long d'une droite dans un espace 3D.
    Lorsque cette droite correspond à l'un des axes il suffit de modifier la position sur cet axe, mais lorsque cette droite correspond à une diagonale entre les axes cela ce complique.

    J'ai lu des tutoriels sur les caméra «freefly» et des cours sur la trigonométrie sphérique et les coordonnées homogènes, mais je n'arrive toujours pas à calculer correctement les déplacements des objets de ma scène.

    Je n'ai pas peur des math, mais j'ai de la difficulté car je tente d'apprendre trop de nouvelles choses simultanément.
    Pouvez-vous m'aider à orienter mes recherches car je ne connais même pas les noms des notions de géométrie que je dois chercher à apprendre?

    Merci

  2. #2
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 031
    Points : 11 476
    Points
    11 476
    Billets dans le blog
    11
    Par défaut
    Si ton déplacement est linéaire, il s'agit d'une bête interpolation entre 2 points : Le départ et l'arrivée.
    Soit P1( x1, y1, z1 ) le point de départ et P2( x2, y2, z2 ) le point d'arrivée.
    A l'instant T les coordonnées d'un objet se déplaçant linéairement sur le segment P1P2 seront :

    Pt( x1 + T * (x2 - x1), y1 + T * (y2 - y1), z1 + T * (z2 - z1) )

    Il est tout à fait possible et fréquent de remplacer T par un pourcentage.
    A 0% on se trouverait donc avec Pt = P1.
    A 100% on se trouverait donc avec Pt = P2.
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Développeur Autodidacte
    Inscrit en
    Janvier 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Autodidacte

    Informations forums :
    Inscription : Janvier 2008
    Messages : 46
    Points : 36
    Points
    36
    Par défaut
    Je vais essayer de mieux expliquer mon problème...

    Je tente de calculer les déplacements en fonction de la direction du regard
    de la caméra. La direction de la caméra est déterminée pas deux angles par
    rapport à l'axe Z. On peut imaginer une droite passant par l'origine et
    formant les mêmes angles.

    Le problème c'est que je ne cherche pas à effectuer les déplacement sur
    cette droite, mais parallèlement ou perpendiculairement à celle-ci.

    P1 est donc la position initiale de l'objet, mais P2 est inconnue.
    P2 doit former avec P1 une droite parallèle à la direction de la caméra dans
    le cas d'un déplacement frontal et perpendiculaire à la direction de la
    caméra dans le cas d'un déplacement latéral.

  4. #4
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Par rapport aux angles, vous pouvez déterminer le vecteur de direction. Pour cela, c'est un bête jeu de sinus/cosinus, sur le cercle (ou la sphère) trigonométrique. Il y a une explication dans ce tutoriel : http://jeux.developpez.com/tutoriels...-souris/#LIV-A

    Une fois que vous avez la direction, c'est plus que facile. Il suffit de faire : position + direction = nouvellePosition. Tada.

    Après, si l'équation d'une droite est :
    a +db.
    Une droite parallèle se détermine en modifiant le "a".
    Une droite perpendiculaire, hum, je n'ai pas de souvenir de savoir le faire
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  5. #5
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 031
    Points : 11 476
    Points
    11 476
    Billets dans le blog
    11
    Par défaut
    Pour la droite perpendiculaire, un produit vectoriel entre le vecteur direction et le vecteur "top" devrait faire l'affaire, en inversant les opérandes pour aller à gauche ou à droite.
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  6. #6
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Ah oui, merci, je cherchais où était le vecteur qui me manquait
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  7. #7
    Membre actif Avatar de monwarez
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 144
    Points : 293
    Points
    293
    Par défaut
    Bon je pense que les précédents post répondent à la question posée , mais bon je suppose qu'au vu du titre vous ne souhaiterais pas vous limiter au cas particulier de droite dans l'espace.
    Ceci étant dis , on peut alors être amené à vouloir faire des déplacements sur des courbes de l'espace : cercle, ellipse , spirale logarithmique, etc... , pour celà il suffit juste de
    paramétrer la courbe(lorsque c'est possible), c'est à dire , trouver une fonction f(t) = (x(t),y(t),z(t)) tel que lorsque l'on fait varier t sur le domaine(inclus dans R) fixé, f parcours toute la courbe.
    Et par exemple si vous voulez faire déplacer votre objet le long d'une courbe et que vous en connaissez une paramétrisation , vous n'avais qu'à faire varier le paramètre t pour avoir
    les positions successives. De plus si la paramétrisation est C¹ (les dérivées x',y',z' existent et sont continues) vous pourrez faire en sorte que l'orientation de votre objet soit "cohérent"
    avec la courbe(utiliser les x',y',z' comme vecteur directeur). Les notions mathématiques qui peuvent être utiles font appel à la géométrie différentielle ( en tout cas la partie
    traitant des courbes et courbures)

  8. #8
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Et je rajouter à la réponse de monwarez que les courbes de Bezier sont un exemple largement utilisé pour la création de courbes continues et "fluides".
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  9. #9
    Invité
    Invité(e)
    Par défaut
    Salut, pour les déplacement à la souris, moi je déplace le personnage d'un point a vers un point b grâce à une grille (toutes les entités de mon monde sont placé dans les cellules de cette grille, la taille des cellules dépend entièrement de moi et mon monde peut avoir plusieurs grilles. (Qui ne sont rien d'autre que des gestionnaires d'entités que j'utilise pour récupérer les entités qui se trouvent dans la caméra, pour sélectionner les entités avec la souris, etc..., etc...)
    Je recherche la cellule qui contient la position de départ et celle qui contient la position d'arrivée, ensuite j'insère tout les centre des cellules intermédiaires dans un std::vector.

    Pour savoir ou mon personnage se trouve à un instant T, je fais ceci :

    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
     
    Vec3f Computer::getPosOnPathFromTime(Vec3f actualPos, std::vector<Vec3f> path, sf::Time time, float speed) {
     
        //The number of point must be greater than 1. (Otherwise it's not a path.)
        if (path.size() > 1) {
                unsigned int currentPathIndex = 0;
                //We check the direction of the first segment of the path and the direction between out actual position and the first point of the first segment of our path.
                Vec3f dir1 = (path[currentPathIndex+1] - path[currentPathIndex]).normalize();
                Vec3f dir2 = (actualPos - path[currentPathIndex]).normalize();
                //If the number of point is greater than 2, we need to check on which segment of the path our actual position is.
                //If the directions are not the same it means that the point is not on this segment of the path.
                while (currentPathIndex < path.size() - 1 && dir1 != dir2) {
                    //We need to check if the actual position is on the next segment of the path.
                    currentPathIndex++;
                    //If we are arrived on the last point of the path, we don't need to check anymore, it means that our position is not on the path. (Or we are already at the end of the path)
                    if (currentPathIndex < path.size() - 1) {
                        dir1 = (path[currentPathIndex+1] - path[currentPathIndex]).normalize();
                        dir2 = (actualPos - path[currentPathIndex]).normalize();
     
                    }
                }
                //Our actual position is not on the path so we return our actual position.
                if (currentPathIndex == path.size() -1)
                    return actualPos;
                //If the time is positive, we need to check a position on the path in the future.
                if (time.asMicroseconds() > 0) {
                    /*We check the direction of the segment, the next position and the distances between the two point of the segment and
                    * the distance between the next position and the first point of the segment.
                    */
                    Vec3f v2 = (path[currentPathIndex+1] - path[currentPathIndex]);
                    Vec3f dir = v2.normalize();
                    Vec3f nextPos = actualPos + dir * speed * time.asMicroseconds();
                    Vec3f v1 = (nextPos - path[currentPathIndex]);
                    int dist = v1.magnitude();
                    int dist2 = v2.magnitude();
                    /*If the actual position is not on the same segment of the path than the final position, we need to check on which segment of the path our next position"ll be.
                    * If the distance between the two points of the segment is shorter than the distance between the next position and the first point of the path, it means that
                    * the next position is not on this segment of the path.
                    */
                    while (currentPathIndex < path.size() - 1 && dist > dist2) {
                        //We need to check the next position on the next segment of the path.
                        currentPathIndex++;
                        //If we are arrived on the last point of the path, we don't need to check anymore because we are at the end of the path.
                        if (currentPathIndex < path.size() - 1) {
                            v2 = (path[currentPathIndex+1] - path[currentPathIndex]);
                            dir = v2.normalize();
                            nextPos = path[currentPathIndex] + dir * (dist - dist2);
                            v1 = (nextPos - path[currentPathIndex]);
                            dist = v1.magnitude();
                            dist2 = v2.magnitude();
                        }
                    }
                    //If we reach the last point of the path it means that we are at the end of the path, otherwise we return the next position.
                    return (currentPathIndex == path.size() - 1)  ? path[currentPathIndex] : nextPos;
                }
                //A negative time give a position on the path in the past, so, we need to do go back on our path.
                if (time.asMicroseconds() < 0) {
                    //The same as above except that we need to check the distance between the last point of the segment of the path.
                    Vec3f v2 = (path[currentPathIndex+1] - path[currentPathIndex]);
                    Vec3f dir = v2.normalize();
                    Vec3f prevPos = actualPos - dir * speed * time.asMicroseconds();
                    Vec3f v1 = (prevPos - path[currentPathIndex+1]);
                    int dist = v1.magnitude();
                    int dist2 = v2.magnitude();
                    while (currentPathIndex > 0 && dist > dist2) {
                        currentPathIndex--;
                        //If the current index is 0, we don't need to check anymore because we are at the beginning of the path.
                        if (currentPathIndex > 0) {
                            v2 = (path[currentPathIndex+1] - path[currentPathIndex]);
                            dir = v2.normalize();
                            prevPos = path[currentPathIndex+1] - dir * (dist - dist2);
                            v1 = (prevPos - path[currentPathIndex+1]);
                            dist = v1.magnitude();
                            dist2 = v2.magnitude();
                        }
                    }
                    //If we reach the last point of the path it means that we are at the end of the path, otherwise we return the next position.
                    return (currentPathIndex == 0)  ? path[currentPathIndex] : prevPos;
                }
            //If the time is equal to zero we have just to return the actual position.
            return actualPos;
        }
     
        return actualPos;
    }
    actualPos est la position actuelle du personnage.
    path est l'ensemble des points de la courbe.
    time est le temps à un instant T.
    Et speed la vitesse à laquelle le personnage se déplace.

    Je me sers également de ça pour effectuer l'IA, et la prédiction de mouvement en réseau.

    J'espère que ça à pu t'aider, je sais pas si mon algorithme fonctionne car j'ai pas encore eu le temps de le tester mais ça résume bien l'idée.

    PS : si vous vous demander l'utilité de la grille c'est pour éviter que le personnage passe à des endroits ou il ne peut pas, en effet, si il y a collision j'affecte une variable booléenne à la cellule qui indique que le personnage ne peux pas passer dessus, mais, il y a peut être un autre moyen de le faire mais c'est la manière la plus simple que j'ai trouvé pour déplacer un personnage d'un point à un un point B tout en évitant les collisions.

  10. #10
    Invité
    Invité(e)
    Par défaut
    Voici le code source corrigé, j'ai du cependant calculer l'angle entre les 2 directions à cause des problèmes d'imprécisions du aux flottants.

    Code cpp : 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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
     
    //The number of point must be greater than 1. (Otherwise it's not a path.)
        if (path.size() > 1) {
                unsigned int currentPathIndex = 0;
                //We check the direction of the first segment of the path and the direction between out actual position and the first point of the first segment of our path.
                Vec3f dir1 = (path[currentPathIndex+1] - path[currentPathIndex]).normalize();
                Vec3f dir2 = (actualPos - path[currentPathIndex]).normalize();
                float d1 = (path[currentPathIndex+1] - path[currentPathIndex]).magnitude();
                float d2 = (actualPos - path[currentPathIndex]).magnitude();
               /* std::cout<<"dir 1 "<<dir1<<"dir 2 : "<<dir2<<"angle : "<<Math::toDegrees(dir1.getAngleBetween(dir2, dir1.cross(dir2)))<<std::endl;
                std::cout<<"dist 1 : "<<d1<<" dist 2 : "<<d2<<std::endl;*/
     
     
                //If the number of point is greater than 2, we need to check on which segment of the path our actual position is.
                //If the directions are not the same it means that the point is not on this segment of the path.
                while (currentPathIndex < path.size() - 1 && !dir2.isNulVector() && !(Math::abs(Math::toDegrees(dir1.getAngleBetween(dir2, dir1.cross(dir2)))) <= 0.1f && d2 < d1)) {
                    //We need to check if the actual position is on the next segment of the path.
                    currentPathIndex++;
                    //If we are arrived on the last point of the path, we don't need to check anymore, it means that our position is not on the path. (Or we are already at the end of the path)
                    if (currentPathIndex < path.size() - 1) {
                        dir1 = (path[currentPathIndex+1] - path[currentPathIndex]).normalize();
                        dir2 = (actualPos - path[currentPathIndex]).normalize();
                        d1 = (path[currentPathIndex+1] - path[currentPathIndex]).magnitude();
                        d2 = (actualPos - path[currentPathIndex]).magnitude();
                        /*std::cout<<"dir 1 : "<<dir1<<"dir 2 : "<<dir2<<"angle : "<<Math::toDegrees(dir1.getAngleBetween(dir2, dir1.cross(dir2)))<<std::endl;
                        std::cout<<"dist 1 : "<<d1<<" dist 2 : "<<d2<<std::endl;*/
                        //std::cout<<"current index path : "<<currentPathIndex<<std::endl;
     
                    }
                }
                //std::cout<<"current index path : "<<currentPathIndex<<"size : "<<path.size()<<std::endl;
               /*std::string str;
                std::cin>>str;*/
                //Our actual position is not on the path so we return our actual position.
                if (currentPathIndex == path.size() -1 && time > 0 || currentPathIndex == 0 && time < 0)
                    return actualPos;
                //If the time is positive, we need to check a position on the path in the future.
                if (time > 0) {
                    /*We check the direction of the segment, the next position and the distances between the two point of the segment and
                    * the distance between the next position and the first point of the segment.
                    */
                    //dir1 = (path[currentPathIndex+1] - path[currentPathIndex]).normalize();
                    Vec3f nextPos = actualPos + dir1 * speed * time;
                    dir2 = (nextPos - path[currentPathIndex]).normalize();
                    d2 = (nextPos - path[currentPathIndex]).magnitude();
                    float dot = dir1.dot(dir2);
                   // std::cout<<"actual pos : "<<actualPos<<" next pos : "<<nextPos<<std::endl;
                    //std::cout<<"dir 1 : "<<dir1<<"dir 2 : "<<dir2<<"d1 : "<<d1<<"d2 : "<<d2<<std::endl;
                    /*If the actual position is not on the same segment of the path than the final position, we need to check on which segment of the path our next position"ll be.
                    * If the distance between the two points of the segment is shorter than the distance between the next position and the first point of the path, it means that
                    * the next position is not on this segment of the path.
                    */
     
                    while (currentPathIndex < path.size() - 1 && !dir2.isNulVector() && d2 > d1) {
                        //We need to check the next position on the next segment of the path.
                        currentPathIndex++;
                        //If we are arrived on the last point of the path, we don't need to check anymore because we are at the end of the path.
                        if (currentPathIndex < path.size() - 1) {
                            dir1 = (path[currentPathIndex+1] - path[currentPathIndex]).normalize();
                            nextPos = path[currentPathIndex] + dir1 * (d2 - d1) * dot;
                            //std::cout<<"next pos : "<<nextPos<<"dir 1 : "<<dir1<<" dir 2 : "<<dir2<<" d1 : "<<d1<<" d2 : "<<d2<<"d2 - d1 : "<<d2 - d1<<" dot : "<<dot<<std::endl;
     
                            dir2 = (nextPos - path[currentPathIndex]).normalize();
                            dot = dir1.dot(dir2);
                            d1 = (path[currentPathIndex+1] - path[currentPathIndex]).magnitude();
                            d2 = (nextPos - path[currentPathIndex]).magnitude();
                            /*std::cout<<"dir 1 : "<<dir1<<" dir 2 : "<<dir2<<" d1 : "<<d1<<" d2 : "<<d2<<"d2 - d1 : "<<d2 - d1<<" dot : "<<dot<<std::endl;
                            std::string ok;
                            std::cin>>ok;*/
                        }
                    }
                    //std::cout<<"next pos : "<<nextPos<<" current path index : "<<currentPathIndex<<"size : "<<path.size()<<std::endl;
                    //If we reach the last point of the path it means that we are at the end of the path, otherwise we return the next position.
                    return (currentPathIndex == path.size() - 1)  ? path[currentPathIndex] : nextPos;
                }
                //A negative time give a position on the path in the past, so, we need to do go back on our path.
                if (time < 0) {
                    //The same as above except that we need to check the distance between the last point of the segment of the path.
                    dir1 = (path[currentPathIndex] - path[currentPathIndex+1]).normalize();
                    d1 = (path[currentPathIndex] - path[currentPathIndex+1]).magnitude();
                    Vec3f prevPos = actualPos - dir1 * speed * time;
                    dir2 = (prevPos - path[currentPathIndex+1]).normalize();
                    d2 = (prevPos - path[currentPathIndex+1]).magnitude();
                    float dot = dir1.dot(dir2);
                    std::cout<<"prev pos : "<<prevPos<<std::endl;
                    while (currentPathIndex > 0 && !dir2.isNulVector() && d2 > d1) {
                        currentPathIndex--;
                        //If the current index is 0, we don't need to check anymore because we are at the beginning of the path.
                        if (currentPathIndex > 0) {
                            dir1 = (path[currentPathIndex] - path[currentPathIndex+1]).normalize();
                            prevPos = path[currentPathIndex+1] - dir1 * (d1 - d2) * dot;
                            dir2 = (prevPos - path[currentPathIndex+1]).normalize();
                            dot = dir1.dot(dir2);
                            d1 = (path[currentPathIndex+1] - path[currentPathIndex]).magnitude();
                            d2 = (prevPos - path[currentPathIndex+1]).magnitude();
                        }
                    }
                    //If we reach the last point of the path it means that we are at the end of the path, otherwise we return the next position.
                    return (currentPathIndex == 0)  ? path[currentPathIndex] : prevPos;
                }
            //If the time is equal to zero we have just to return the actual position.
            return actualPos;
        }
     
        return actualPos;

    Bref ce code me donner bien le position du personnage sur la courbe en fonction du temps (c'est plutôt une ligne brisée qu'une courbe dans mon cas mais, l'algorithme ne change pas)

  11. #11
    Nouveau membre du Club
    Homme Profil pro
    Développeur Autodidacte
    Inscrit en
    Janvier 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Autodidacte

    Informations forums :
    Inscription : Janvier 2008
    Messages : 46
    Points : 36
    Points
    36
    Par défaut
    Merci de vos réponses.

    Je crois que j'imaginais le problème beaucoup plus grand qu'il ne l'était en réalité.

    J'ai réussi à créer l'effet que je voulais dans mon programme, mais avant d'ajouter la mention résolu à cette discussion j'ai décidé de tenter de calculer des courbes pour ne pas décevoir les habitués d'Opengl.

    J'ai essayé la courbe de bézier cubique:

    Nom : image1.png
Affichages : 93
Taille : 2,6 Ko

    C'est magnifique!
    Par contre, la spirale logarithmique me cause quelques problèmes.

    Wikipédia me dit que l'équation paramétrique d'une spirale logarithmique est:

    Nom : image2.png
Affichages : 97
Taille : 1,1 Ko

    Voici l'exemple qu'il me donne:

    Nom : image3.png
Affichages : 97
Taille : 25,9 Ko
    Nom : image4.png
Affichages : 96
Taille : 423 octets

    J'ai tenté d'ajouter ce calcul à mon programme et voici le résultat:

    Nom : image5.png
Affichages : 204
Taille : 2,9 Ko

    Cette spirale n'est pas très jolie et ce n'est pas celle de l'exemple.

    Voici ce que je fais:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    #include <math.h>
     
    glBegin(GL_LINE_STRIP);
    for(unsigned int t=0; t<360; t++)
    {
    	glVertex3f(a * (log(t) / log(b)) * cos(t * M_PI / 180),
    		a * (log(t) / log(b)) * sin(t * M_PI / 180),
    		0);
    }
    glEnd();
    Je me demande si j'ai bien compris et je ne suis pas certain quels valeurs donner à a et b.
    Dois-je les modifier au cours du calcul de la spirale?

  12. #12
    Inactif
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mai 2014
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Mai 2014
    Messages : 2
    Points : 7
    Points
    7
    Par défaut
    Si ça peut t'aider voici le code que j'ai fait et que j'utilise pour ma caméra je sais pas si c'est bien en tout cas ça marche cadeau :

    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
    if(Mouse.isButtonDown(0)){
    			Mouse.setGrabbed(false);
    		}
     
    		if(Mouse.isButtonDown(1)){
    			Mouse.setGrabbed(true);
    		}
     
    		if(Mouse.isGrabbed()){
     
    			int cptx = Mouse.getDX();
    			int cpty = Mouse.getDY();				
     
    			angle_cote = (float) ((angle_cote+0.001*cptx*sensibilite)%360);
    			angle_hetb = (float) ((angle_hetb+0.001*cpty*sensibilite)%360);
     
    			camDir.x = (float) (Math.sin(angle_cote*Math.PI/180)*Math.cos(angle_hetb*Math.PI/180));
    			camDir.z = (float) (-Math.cos(angle_cote*Math.PI/180)*Math.cos(angle_hetb*Math.PI/180));
    			camDir.y = (float) Math.sin(angle_hetb*Math.PI/180);
     
    		}
     
    		if(Keyboard.isKeyDown(Keyboard.KEY_Z)){
     
    			camPos.x += camDir.x*vitesse*delta;
    			camPos.z += camDir.z*vitesse*delta;
    			camPos.y += camDir.y*vitesse*delta;
     
    		}
     
    		if(Keyboard.isKeyDown(Keyboard.KEY_S)){
     
    			camPos.x -= camDir.x*vitesse*delta;
    			camPos.z -= camDir.z*vitesse*delta;
    			camPos.y -= camDir.y*vitesse*delta;
     
    		}
     
    		if(Keyboard.isKeyDown(Keyboard.KEY_Q)){
     
    			camPos.x = (float) (camPos.x - Math.cos(angle_cote*Math.PI/180)*vitesse*delta);
    			camPos.z = (float) (camPos.z - Math.sin(angle_cote*Math.PI/180)*vitesse*delta);
     
    		}		
     
    		if(Keyboard.isKeyDown(Keyboard.KEY_D)){
     
    			camPos.x = (float) (camPos.x + Math.cos(angle_cote*Math.PI/180)*vitesse*delta);
    			camPos.z = (float) (camPos.z + Math.sin(angle_cote*Math.PI/180)*vitesse*delta);
    		}
     
    		if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){			
    			System.exit(0);
    		}
     
     
    		GLU.gluLookAt( camPos.x,camPos.y,camPos.z,
    				camDir.x+camPos.x,camDir.y+camPos.y,camDir.z+camPos.z,
    				0.0f,1.0f,0.0f
    				);

    bon c'est du java mais une formule reste une formule ^^.

  13. #13
    Nouveau membre du Club
    Homme Profil pro
    Développeur Autodidacte
    Inscrit en
    Janvier 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Autodidacte

    Informations forums :
    Inscription : Janvier 2008
    Messages : 46
    Points : 36
    Points
    36
    Par défaut
    Personne n'a de conseil à me donner pour la spirale logarithmique?

  14. #14
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Je viens de penser, dans ce cas là, ce n'est pas "log2", qu'il faille utiliser ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

Discussions similaires

  1. Réponses: 0
    Dernier message: 20/10/2013, 20h30
  2. Conception requête complexe
    Par HadanMarv dans le forum Langage SQL
    Réponses: 3
    Dernier message: 17/02/2012, 11h51
  3. Réponses: 0
    Dernier message: 17/08/2010, 17h23
  4. Conception GUI "complexe"
    Par panda31 dans le forum Tkinter
    Réponses: 9
    Dernier message: 14/05/2009, 11h17
  5. [Conception] Réalisation d'un sondage complexe
    Par jehhej dans le forum PHP & Base de données
    Réponses: 9
    Dernier message: 26/01/2006, 10h30

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