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

ODE Discussion :

simple rebond de balle


Sujet :

ODE

  1. #1
    Candidat au Club
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Points : 2
    Points
    2
    Par défaut simple rebond de balle
    bonjour tout le monde,
    je débute avec ode (opengl aussi) ,et pas moyen de faire une simple balle qui tombe sur une plaque et rebondit,je me sers de code::blocks + opengl+glut.

    pour l'instant j'y suis presque mais le probléme c'est qu'aprés le 1er rebond la balle par a l'infini vers le haut et retombe pas ...

    si quelqun as une idée

    merci a vous

    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
    #include <GL/glut.h>
    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <ode/ode.h>
     
    int LightPos[4] = {0,3,5,1};
     
    static dWorldID world;
    static dSpaceID space;
    static dGeomID sol;
    static dJointGroupID contactgroup;
    dGeomID geom_sphere;
    dBodyID body_sphere;
     
    void set_transf(const dReal *pos,const dReal *R)
    {
        GLfloat local_matrix[16];
        local_matrix[0] = R[0];
        local_matrix[1] = R[4];
        local_matrix[2] = R[8];
        local_matrix[3] = 0;
        local_matrix[4] = R[1];
        local_matrix[5] = R[5];
        local_matrix[6] = R[9];
        local_matrix[7] = 0;
        local_matrix[8] = R[2];
        local_matrix[9] = R[6];
        local_matrix[10] = R[10];
        local_matrix[11] = 0;
        local_matrix[12] = pos[0];
        local_matrix[13] = pos[1];
        local_matrix[14] = pos[2];
        local_matrix[15] = 1;
        glMultMatrixf(local_matrix);
    }
     
     
    static void nearCallback(void *data, dGeomID o1, dGeomID o2)
    {
    int i;
    // exit without doing anything if the two bodies are connected by a joint
    dBodyID b1 = dGeomGetBody(o1);
    dBodyID b2 = dGeomGetBody(o2);
    if (b1 && b2 && dAreConnected (b1,b2)) return;
     
    dContact contact[3]; // up to 3 contacts per box
    for (i=0; i<3; i++)
        {
            contact[i].surface.mode = dContactBounce | dContactSoftCFM;
            contact[i].surface.mu = 50;
            contact[i].surface.soft_cfm = 0.01;
        }
     
    if (int numc = dCollide (o1,o2,3,&contact[0].geom,sizeof(dContact)))
        {
            for (i=0; i<numc; i++)
            {
                dJointID c = dJointCreateContact (world,contactgroup,contact+i);
                dJointAttach (c,b1,b2);
            }
        }
    }
    void ode_loop()
    {
        dSpaceCollide(space,0,&nearCallback);
        dWorldQuickStep(world,0.01);
     
    }
     
    void ode_init()
     {
        world = dWorldCreate();
        space = dHashSpaceCreate(0);
        dWorldSetGravity(world,0,-0.2,0);
        sol = dCreatePlane (space,0,1,0,0);
        contactgroup = dJointGroupCreate (0);
     
        dMass m;
     
        dMassSetSphere(&m,1,1);
        dMassAdjust(&m,1);
        body_sphere = dBodyCreate(world);
        dBodySetMass(body_sphere,&m);
        geom_sphere = dCreateSphere(space,0.5);
        dGeomSetBody(geom_sphere,body_sphere);
        dBodySetPosition(body_sphere,0,2,0);
     
     }
     
     
     
    void terrain()
    {
        glPushMatrix();
        glBegin(GL_QUADS);
        glColor3d(0,0,1);
        glVertex3i(-1,0,-1);
        glVertex3i(-1,0,1);
        glVertex3i(1,0,1);
        glVertex3i(1,0,-1);
        glEnd();
        glPopMatrix();
    }
     
    void balle()
    {
        glPushMatrix();
        glColor3d(0,1,0);
        set_transf(dBodyGetPosition(body_sphere),dBodyGetRotation(body_sphere));
        glutSolidSphere(0.2,25,25);
        glPushMatrix();
    }
     
     
     
    void InitGL()
    {
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_DEPTH_TEST);
      	glEnable(GL_LIGHTING);
      	glEnable(GL_LIGHT0);
    }
    void Draw()
    {
        glClear(GL_COLOR_BUFFER_BIT);
     	glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
        glMateriali(GL_FRONT_AND_BACK,GL_SHININESS,100);
        glLightiv(GL_LIGHT0,GL_POSITION,LightPos);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(3,2,3,0,1,0,0,1,0);
        ode_loop();
        terrain();
        balle();
        glutSwapBuffers();
        glutPostRedisplay();
    }
     
    void Reshape(int width, int height)
    {
      	glViewport(0,0,width,height);
      	glMatrixMode(GL_PROJECTION);
      	glLoadIdentity();
      	gluPerspective(45,float(width)/float(height),0.1,100);
      	glMatrixMode(GL_MODELVIEW);
     
    }
     
     
     
     
    int main(int argc, char *argv[])
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
        glutInitWindowSize(1024,768);
        glutCreateWindow("test ODE");
        glutReshapeFunc(Reshape);
        glutDisplayFunc(Draw);
        InitGL();
        ode_init();
        glutMainLoop();
     
        dWorldDestroy(world);
        dSpaceDestroy(space);
        dCloseODE();
        return 0;
    }

  2. #2
    Candidat au Club
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    bonjour,
    personne pour m'éclairer un petit peu? ,j'ai rajouté une dCreateBox sur le (sol) et sa le fait pas trop mal,sauf que si recupere la position de la box elle est en mouvement aprés l'impact,j'ai lu que pour créer un objet fixe ,faut juste le geom ...

    mais si je mets que le geom de la box ,je me retrouve au point de depart


    merci

  3. #3
    Candidat au Club
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    enfin trouvé ,il me manquait dJointGroupEmpty(contactgroup); dans le loop ...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. rebond d'une balle aux bords de l'écran
    Par The_Duck dans le forum Algorithmes et structures de données
    Réponses: 5
    Dernier message: 11/05/2006, 22h47
  2. Rebond d'une balle sur un sol incliné
    Par franco01 dans le forum Algorithmes et structures de données
    Réponses: 18
    Dernier message: 05/02/2006, 01h20
  3. Rebond simple d'une balle
    Par Fiquet dans le forum Algorithmes et structures de données
    Réponses: 21
    Dernier message: 11/10/2005, 16h48
  4. Réponses: 2
    Dernier message: 05/08/2005, 09h21
  5. rebond balle plan
    Par Mat 74 dans le forum Algorithmes et structures de données
    Réponses: 4
    Dernier message: 30/05/2005, 22h41

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