View Single Post
Posts: 25 | Thanked: 1 time | Joined on Feb 2010
#1
Hi group,

I am now trying to develop an app both with ODE and OpenGL ES2.0 libraries, which aims to build dynamic simulations on mobile devices.

While the very first problem is how to translate the attributes of ODE object such like a cube, to be represented by vertex, coordinates and normals arrays, which would be necessary for rendering with OpenGL ES 2.0 shading language.

I've got a sample code for explaination, for creating a cube in ODE world
Code:
Cube::Cube(dWorldID world, dSpaceID space, dReal width, dReal
height, dReal depth, dReal mass)
{
    body = dBodyCreate(world);
    geom = dCreateBox(space, width, height, depth);

    dMass m;
    dMassSetBox(&m, 1.0f, width, height, depth);
    dMassAdjust(&m, mass);
    dBodySetMass(body, &m);

    dGeomSetBody(geom, body);

}

... ...

Cube *cube = new Cube(world, space, 0.3, 0.3, 0.3, 1);
For rendering an object in OpenGL ES 2.0
Code:
glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,m_uiTexture);

    GLfloat afVertices[]= //todo...vertex arrays
    glVertexAttribPointer(vertexAttr2, 3, GL_FLOAT, GL_FALSE, 0, afVertices);
    glEnableVertexAttribArray(vertexAttr2);

    GLfloat afTexCoord[]=//todo...coordinates arrays
    glVertexAttribPointer(texCoordAttr2, 3, GL_FLOAT, GL_FALSE, 0, afTexCoord);
    glEnableVertexAttribArray(texCoordAttr2);

    GLfloat afNormals[]=//todo...normal arrays
    glVertexAttribPointer(normalAttr2, 3, GL_FLOAT, GL_FALSE, 0, afNormals);
    glEnableVertexAttribArray(normalAttr2);

    glUniform1i(textureUniform2, 0); //use texture unit 0

    glDrawArrays(GL_TRIANGLES, 0, 36);

    glDisableVertexAttribArray(vertexAttr2);
    glDisableVertexAttribArray(normalAttr2);
    glDisableVertexAttribArray(texCoordAttr2);
I think the point is how to complete the "todo..." in the code.

Thank you.

Last edited by pta0007; 2010-08-09 at 11:11.