How to apply Bullet physics to drawn Opengl 3d shapes

后端 未结 4 1697
情话喂你
情话喂你 2020-12-30 13:55

I was just wondering whether there is a way to apply bullet physics to opengl drawn objects (created using glVertex3f or triangle mesh with glVertexAttribPointer). I am curr

4条回答
  •  抹茶落季
    2020-12-30 14:51

    After you downloaded Bullet Physics SDK, look the file GL_ShapeDrawer.cpp,you will find some interresting functions such like drawSphere, drawCylinder,drawOpenGl.. the last one i mentionned lets you draw any type of suported shape :

    • CUSTOM_CONVEX_SHAPE_TYPE
    • BOX_SHAPE_PROXYTYPE
    • UNIFORM_SCALING_SHAPE_PROXYTYPE
    • COMPOUND_SHAPE_PROXYTYPE
    • BOX_SHAPE_PROXYTYPE
    • SPHERE_SHAPE_PROXYTYPE

    Each type of shape from shape->getShapeType() has its own dedicated function for rendering with opengl

    But my method involves to

    • 1 - Load the 3D model with a mesh loader
    • 2 - Create the graphics shape with opengl functions using the previous mesh loader
    • 3 - Create bullet shapes from the vertices used by the mesh loader
    • 4 - Implement the Bullet Motion State (when a shape is going to be rotated or translated or just "transformed", you syncronize the "btTransform" of your bullet shape with the transformation matrix of the graphic shape, then update the graphics vertices)

    Personnaly, i'm using Irrlicht because Irrlicht is the "write less,do more" solution of opengl :p

提交回复
热议问题