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 :

gerer la vitesse de la courbe de bezier sur opengl


Sujet :

Développement 2D, 3D et Jeux

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 8
    Points : 7
    Points
    7
    Par défaut gerer la vitesse de la courbe de bezier sur opengl
    salut, en faite je suis un peu bloqué ayant programmé ma courbe de bezier je voulais ajouter la vitesse mais je sais comment on fait tout ce je sais c


    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
    typedef struct point_3d { // Structure for a 3 dimensional point (NEW) 
    double x, y, z; 
    } point_3d; 
     
    typedef struct bpatch { // Structure for a 3rd degree bezier patch (NEW) 
    point_3danchors[4][4]; // 4x4 grid of anchor points 
    GLuint dlBPatch; // Display List for Bezier Patch 
    GLuint texture; // Texture for the patch 
    } 
    BEZIER_PATCH; 
     
    HDC hDC=NULL; // Private GDI Device Context 
    HGLRC hRC=NULL;        // Permanent Rendering Context 
    HWND hWnd=NULL;       // Holds Our Window Handle 
    HINSTANCE hInstance; // Holds The Instance Of The Application 
     
    DEVMODE DMsaved;  // Saves the previous screen settings (NEW) 
    //bool 
    keys[256];     // Array Used For The Keyboard Routine 
    //bool 
    active=TRUE;   // Window Active Flag Set To TRUE By Default 
    //bool 
    fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default 
     
    GLfloat rotz = 0.0f; // Rotation about the Z axis 
    BEZIER_PATCH mybezier; // The bezier patch we're going to use (NEW) 
    BOOL showCPoints=TRUE;// Toggles displaying the control point grid (NEW) 
    int divs = 7; // Number of intrapolations (conrols poly resolution) (NEW) 
     
     
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc 
     
     
    glEnd();  // End the haptic shape. 
    hlEndShape(); 
    //End the haptic frame. 
        hlEndFrame(); 
     
     
     
    }
     
    // Adds 2 points. Don't just use '+' ;) 
    point_3d pointAdd(double 
    point_3d p, point_3d q) { 
    p.x += q.x; p.y += q.y; p.z += q.z; 
    return p; 
    } 
     
    // Multiplies a point and a constant. Don't just use '*' 
    double point_3d pointTimes(double c, point_3d p) { 
    p.x *= c; p.y *= c; p.z *= c; 
    return p; 
    } 
     
    // Function for quick point creation 
    double point_3d makePoint(double a, double b, double c) { 
    point_3d p; 
    p.x = a; p.y = b; p.z = c; 
    return p; 
    } 
     
     
    // Calculates 3rd degree polynomial based on array of 4 points 
    // and a single variable (u) which is generally between 0 and 1 
    point_3d Bernstein(float u, point_3d *p) { 
    point_3d a, b, c, d, r; 
     
    a = pointTimes(pow(u,3), p[0]); 
    b = pointTimes(3*pow(u,2)*(1-u), p[1]); 
    c = pointTimes(3*u*pow((1-u),2), p[2]); 
    d = pointTimes(pow((1-u),3), p[3]); 
     
    r = pointAdd(pointAdd(a, b), pointAdd(c, d)); 
     
    return r; 
    }

  2. #2
    Expert confirmé
    Avatar de shenron666
    Homme Profil pro
    avancé
    Inscrit en
    Avril 2005
    Messages
    2 524
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : avancé

    Informations forums :
    Inscription : Avril 2005
    Messages : 2 524
    Points : 5 184
    Points
    5 184
    Par défaut
    je ne comprend pas vraiment ce que tu veux

    dans une courbe de bézier il y a un paramètre temporel (t) qui varie entre 0 et 1 si ma mémoire est bonne
    la variation de t détermine la position sur la courbe
    si tu te sert de la courbe pour un déplacement (de caméra par exemple), tu fais varier t plus ou moins vite

    si j'ai pas compris, ce serai bien de préciser ta question
    Tutoriels OpenGL
    Je ne répondrai à aucune question en MP
    - Si c'est simple tu dis que c'est compliqué et tu le fait
    - Si c'est compliqué tu dis que c'est simple et tu le sous-traite ou le fait faire par un stagiaire.

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 8
    Points : 7
    Points
    7
    Par défaut le vitesse sur la courbe de bezier
    En faite la vrai est , j'utilise le PHANToM OMNI QUI PERMET DE RETOURNER UN EFFORT de ce faite avec le déplacement via ce phantom je voudrai sentir la variations de la vitesse en fction de t[0,1] variant constante,augmente, qui dimunie. j'attend des propositions des suggestions j'avoue les questions sont pas trés clair, je suis un perdu !!!

    Copyright (c) 2004 SensAble Technologies, Inc. All rights reserved.

    OpenHaptics(TM) toolkit. The material embodied in this software and use of
    this software is subject to the terms and conditions of the clickthrough
    Development License Agreement.

    For questions, comments or bug reports, go to forums at:
    http://dsc.sensable.com

    Module Name:

    HelloHaptics.cpp

    Description:

    Introducing OpenHaptics. This is a minimalistic OpenGL program
    with a simple haptics operation wrapped around it that utilizes
    SensAble's OpenHaptics SDK.

    The openGL program was taken from OpenGL Programming Guide 4th edition
    (Red Book).

    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    #include <stdio.h>
    #include <stdlib.h>
     
    #if defined(WIN32)
    # include <windows.h>
    #endif
     
    #if defined(WIN32) || defined(linux)
    # include <GL/glut.h>
    #elif defined(__APPLE__)
    # include <GLUT/glut.h>
    #endif
     
    // Header files for OpenHaptics.
    #include <HL/hl.h>
    #include <HDU/hduError.h>
     
    // id needed for haptic shape.
    HLuint gMyShapeId;
     
    void display(void) 
    {
    	 // Start a haptic frame.
    	hlBeginFrame();
     
    	// Start the haptic shape.
    /*	hlBeginShape(HL_SHAPE_DEPTH_BUFFER, gMyShapeId);
    GLfloat ctrlpoints[4][3] = {
    	{ -4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0}, 
    	{2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}};*/
     
    	typedef struct point_3d {			// Structure for a 3-dimensional point (NEW)
    	double x, y, z;
    } POINT_3D;
     
    typedef struct bpatch {				// Structure for a 3rd degree bezier patch (NEW)
    	POINT_3D	anchors[4][4];			// 4x4 grid of anchor points
    	GLuint		dlBPatch;				// Display List for Bezier Patch
    	GLuint		texture;				// Texture for the patch
    } 
    BEZIER_PATCH;
     
    HDC				hDC=NULL;			// Private GDI Device Context
    HGLRC			hRC=NULL;			// Permanent Rendering Context
    HWND			hWnd=NULL;			// Holds Our Window Handle
    HINSTANCE		hInstance;			// Holds The Instance Of The Application
     
    DEVMODE			DMsaved;			// Saves the previous screen settings (NEW)
     
    //bool			keys[256];			// Array Used For The Keyboard Routine
    //bool			active=TRUE;		// Window Active Flag Set To TRUE By Default
    //bool			fullscreen=TRUE;	// Fullscreen Flag Set To Fullscreen Mode By Default
     
    GLfloat			rotz = 0.0f;		// Rotation about the Z axis
    BEZIER_PATCH	mybezier;			// The bezier patch we're going to use (NEW)
    BOOL			showCPoints=TRUE;	// Toggles displaying the control point grid (NEW)
    int				divs = 7;			// Number of intrapolations (conrols poly resolution) (NEW)
     
     
    LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	// Declaration For WndProc
     
    // Adds 2 points. Don't just use '+' ;)
    POINT_3D pointAdd(POINT_3D p,POINT_3D q) {
    	p.x += q.x;		p.y += q.y;		p.z += q.z;
    	return p;
    }
     
    // Multiplies a point and a constant. Don't just use '*'
    POINT_3D pointTimes(POINT_3D c, POINT_3D p) {
    	p.x *= c;	p.y *= c;	p.z *= c;
    	return p;
    }
     
    // Function for quick point creation
    POINT_3D makePoint(double a, double b, double c) {
    	POINT_3D p;
    	p.x = a;	p.y = b;	p.z = c;
    	return p;
    }
     
     
    // Calculates 3rd degree polynomial based on array of 4 points
    // and a single variable (u) which is generally between 0 and 1
    POINT_3D Bernstein(float u, POINT_3D *p) {
    	POINT_3D	a, b, c, d, r;
     
    	a = pointTimes(pow(u,3), p[0]);
    	b = pointTimes(3*pow(u,2)*(1-u), p[1]);
    	c = pointTimes(3*u*pow((1-u),2), p[2]);
    	d = pointTimes(pow((1-u),3), p[3]);
     
    	r = pointAdd(pointAdd(a, b), pointAdd(c, d));
     
    	return r;
    }
     
     
    	glEnd();
     
     
    	// End the haptic shape.
    	hlEndShape();
    	//End the haptic frame.
     
        hlEndFrame();
     
     
    }
     
     
    void init(void)
    {
       glClearColor(0.0, 0.0, 0.0, 0.0);
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
     
       // Enable depth buffering to provide depth information for OpenHaptics.
       glDepthFunc(GL_LEQUAL);
       glEnable(GL_DEPTH_TEST);
     
       // OpenHaptics setup follows:
     
       // Create a haptic device instance.
       HDErrorInfo error;
       HHD hHD = hdInitDevice(HD_DEFAULT_DEVICE);
       if (HD_DEVICE_ERROR(error = hdGetError()))
       {
           hduPrintError(stderr, &error, "Failed to initialize haptic device");
           fprintf(stderr, "Press any key to exit");
           getchar();
           exit(-1);
       }
     
       if (HD_SUCCESS != hdGetError().errorCode)
       {
           fprintf(stderr, "Erorr initializing haptic device.\nPress any key to exit");
           getchar();
           exit(-1);
       }
     
       // Create a haptic rendering context and activate it.
       HHLRC hHLRC = hlCreateContext(hHD);
       hlMakeCurrent(hHLRC);
     
       // Reserve an id for the shape
       gMyShapeId = hlGenShapes(1);
     
       // Specify the boundaries for the workspace of the haptic device
       // in millimeters in the cordinates of the haptic device.
       // The haptics engine will map the view volume to this workspace
       hlWorkspace (-80, -80, -70, 80, 80, 20);
     
       // Specify the haptic view volume (in this case it will be
       // the same as the graphic view volume).
       hlMatrixMode(HL_TOUCHWORKSPACE);
       hlLoadIdentity();
       hlOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    }
     
     
    void glutMenu(int ID)
    {
        switch(ID) {
            case 0:
                exit(0);
                break;
        }
    }
     
    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
        glutInitWindowSize(250, 250);
        glutInitWindowPosition(100, 100);
        glutCreateWindow("Hello Haptics");
        glutCreateMenu(glutMenu);
        glutAddMenuEntry("Quit", 0);
        glutAttachMenu(GLUT_RIGHT_BUTTON);
        init();
        glutDisplayFunc(display);
        glutMainLoop();
        return 0;
    }

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    106
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 106
    Points : 153
    Points
    153
    Par défaut
    Le probeleme de la courbe de bezier est qu'il est impossible de connaitre sa taille (et donc de pouvoir avancer a une vitesse constante sur la courbe).

    Il y a tout de meme un moyen (a utiliser avec precaution) c'est de faire du sampling. Ca marche relativement bien et ca permet d'avancer a une vitesse constante sur ta courbe. En gros ca revient a convertir la courbe en beaucoup de segments...

  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
    Citation Envoyé par unmanos Voir le message
    Le probeleme de la courbe de bezier est qu'il est impossible de connaitre sa taille (et donc de pouvoir avancer a une vitesse constante sur la courbe).

    Il y a tout de meme un moyen (a utiliser avec precaution) c'est de faire du sampling. Ca marche relativement bien et ca permet d'avancer a une vitesse constante sur ta courbe. En gros ca revient a convertir la courbe en beaucoup de segments...
    Pourquoi ca? tu peux considérer ta courbe entière comme une interpolation entre 0 et 1, et donc mettre une vitesse en fonction.
    Pour ce qui est de la longueur d'un segment (si tu utilises une courbe qui consiste en plusieurs segments), tu peux approcher la longueur avec la distance directe entre le point de départ et le point d'arrivée du segment ou avec la distance d'un nombre définis de points sur ce segment de courbe.

    J'ajoute que le problème persiste avec d'autres types de courbes (Catmull-Rom, Kochanek-Bartels, ...).
    Cf. Game Programming Gems 3 (je crois) pour un type de courbe qui contient cependant la vitesse, la TCS (time-coordinated spline).

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    106
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 106
    Points : 153
    Points
    153
    Par défaut
    Citation Envoyé par Kurisu Voir le message
    Pourquoi ca? tu peux considérer ta courbe entière comme une interpolation entre 0 et 1, et donc mettre une vitesse en fonction.
    Pour moi une vitesse ca se definit en metres seconde ou autres. Par par un facteur. A moins de sampler, il est impossible de definir une vitesse (en metres par seconde par example) sur une courbe de bezier, par example avancer a 1 metre par seconde sur la courbe. Si la longeur de la courbe est de 10 metres (valeur obtenue avec du sampling, seul moyen a ma conaissance), mettre un t=0.1 ne te garantit pas que tu t'es deplace d'1 metre.

    Citation Envoyé par Kurisu Voir le message
    tu peux approcher la longueur avec la distance directe entre le point de départ et le point d'arrivée du segment ou avec la distance d'un nombre définis de points sur ce segment de courbe.
    Comme tu dis... tu peux approcher mais c'est mathematiquement faux. Ta solution revient a faire du sampling. Il est mathematiquement impossible de connaitre la distance exacte d'une courbe de bezier.

  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
    Mouais... mais tu vois la différence entre la longueur exacte et la longueur approchée?
    ET si c'est pour un jeu, est-ce que le joueur le verra? C'est ca le point d'approcher, non?

    Et pis pour le facteur, si tu considère que ta spline va prendre disons 20 secondes à être traversée, tu peux augmenter ton interpolation de 1/20 par seconde.

Discussions similaires

  1. Réponses: 3
    Dernier message: 25/10/2012, 09h46
  2. Fermer une courbe de Bezier
    Par cjacquel dans le forum MFC
    Réponses: 2
    Dernier message: 15/05/2007, 12h21
  3. courbe de bezier
    Par widi70 dans le forum C++
    Réponses: 12
    Dernier message: 17/03/2007, 12h52
  4. [vecteurs] dessiner les courbes de Bezier
    Par luta dans le forum Flash
    Réponses: 4
    Dernier message: 03/07/2006, 09h58
  5. Courbes de Beziers
    Par venomelektro dans le forum OpenGL
    Réponses: 10
    Dernier message: 23/12/2004, 00h29

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