steps to display graphics using debug draw in bullet physics engine












0















I'm looking for an easy way to use debug draw in a very simple bullet physics application to develop my understanding of the interface for DebugDraw. My code, which is basically the code from [Demos/HelloWorld/]1 in bullet3 package, is modified a bit to work with modern c++ stl objects.
I looked up the older post but none are helpful for me. The bullet support for the C++ code has been taken down which doesn't help me either



In the code I do the following:




  1. Declare the properties of the world

  2. Declare a world and initialize it with the properties declared in 1

  3. Declare a DebugDrawer object and initialize the world with this object

  4. Create rigid bodies, initialize their properties and add it to the world

  5. run the simulation (and attempt to run the debugDraw)


The code is a bit lengthy and I've posted only the snippet that gives insight to what I'm trying to do. My version of entire hello world code can be found here



The code snippet looks like this:



int main(int argc, char *argv)
{

std::cout << "attempt to run hello world like program using modern c++ and with GUI debugDrawn";

//create the properties of the world
. . .
. . .

// declare and initialize the world with the above properties
btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(dispatcher, interface, solver, collisonConfig);
world->setGravity(btVector3(0.0, -9.81, 0));

//initialize visualization framework
GLDebugDrawer *debugDraw = new GLDebugDrawer;
debugDraw->setDebugMode(1);
world->setDebugDrawer(debugDraw);


//create placeholder for shapes, some kind of array
std::vector<btCollisionShape*> collisionShapes;

//Create and initialize multiple rigid
//bodies with specific properties
. . .

for(size_t i=0; i<collisionShapes.size(); ++i){

//some more initialization code
. . .
. . .

//adding the rigid bodies to the wold
world->addRigidBody(rbody[i]);
}

//do some simulation
for (size_t i = 0; i < 20; ++i) {
world->stepSimulation(1.f/60.f, 10);

//print positions of all objects
for (int j = 0; j<world->getNumCollisionObjects(); ++j){

btCollisionObject *obj = world->getCollisionObjectArray()[j];
btRigidBody* bdy = btRigidBody::upcast(obj);

if(bdy && bdy->getMotionState()){
btTransform trans;
bdy->getMotionState()->getWorldTransform(trans);

//render the rigid bodies in the world
//DOESN'T WORK
world->debugDrawWorld();

//this works
std::cout << "world pos: " << trans.getOrigin().getX() <<"nY: " << trans.getOrigin().getY() << "nZ:" << trans.getOrigin().getZ() << "n";
}
}

}

releaseResources(collisionShapes, rbody, myMotionstate);

return 0;
}


This code works fine when I run it on bash, and prints the updated positions of the rigid bodies but I don't see any screen that renders the objects in a graphics.



I'm not sure what else I'm missing and where should the line `world->DebugDrawWorld()' be placed. Any help will be really appreciated.



thank you










share|improve this question





























    0















    I'm looking for an easy way to use debug draw in a very simple bullet physics application to develop my understanding of the interface for DebugDraw. My code, which is basically the code from [Demos/HelloWorld/]1 in bullet3 package, is modified a bit to work with modern c++ stl objects.
    I looked up the older post but none are helpful for me. The bullet support for the C++ code has been taken down which doesn't help me either



    In the code I do the following:




    1. Declare the properties of the world

    2. Declare a world and initialize it with the properties declared in 1

    3. Declare a DebugDrawer object and initialize the world with this object

    4. Create rigid bodies, initialize their properties and add it to the world

    5. run the simulation (and attempt to run the debugDraw)


    The code is a bit lengthy and I've posted only the snippet that gives insight to what I'm trying to do. My version of entire hello world code can be found here



    The code snippet looks like this:



    int main(int argc, char *argv)
    {

    std::cout << "attempt to run hello world like program using modern c++ and with GUI debugDrawn";

    //create the properties of the world
    . . .
    . . .

    // declare and initialize the world with the above properties
    btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(dispatcher, interface, solver, collisonConfig);
    world->setGravity(btVector3(0.0, -9.81, 0));

    //initialize visualization framework
    GLDebugDrawer *debugDraw = new GLDebugDrawer;
    debugDraw->setDebugMode(1);
    world->setDebugDrawer(debugDraw);


    //create placeholder for shapes, some kind of array
    std::vector<btCollisionShape*> collisionShapes;

    //Create and initialize multiple rigid
    //bodies with specific properties
    . . .

    for(size_t i=0; i<collisionShapes.size(); ++i){

    //some more initialization code
    . . .
    . . .

    //adding the rigid bodies to the wold
    world->addRigidBody(rbody[i]);
    }

    //do some simulation
    for (size_t i = 0; i < 20; ++i) {
    world->stepSimulation(1.f/60.f, 10);

    //print positions of all objects
    for (int j = 0; j<world->getNumCollisionObjects(); ++j){

    btCollisionObject *obj = world->getCollisionObjectArray()[j];
    btRigidBody* bdy = btRigidBody::upcast(obj);

    if(bdy && bdy->getMotionState()){
    btTransform trans;
    bdy->getMotionState()->getWorldTransform(trans);

    //render the rigid bodies in the world
    //DOESN'T WORK
    world->debugDrawWorld();

    //this works
    std::cout << "world pos: " << trans.getOrigin().getX() <<"nY: " << trans.getOrigin().getY() << "nZ:" << trans.getOrigin().getZ() << "n";
    }
    }

    }

    releaseResources(collisionShapes, rbody, myMotionstate);

    return 0;
    }


    This code works fine when I run it on bash, and prints the updated positions of the rigid bodies but I don't see any screen that renders the objects in a graphics.



    I'm not sure what else I'm missing and where should the line `world->DebugDrawWorld()' be placed. Any help will be really appreciated.



    thank you










    share|improve this question



























      0












      0








      0








      I'm looking for an easy way to use debug draw in a very simple bullet physics application to develop my understanding of the interface for DebugDraw. My code, which is basically the code from [Demos/HelloWorld/]1 in bullet3 package, is modified a bit to work with modern c++ stl objects.
      I looked up the older post but none are helpful for me. The bullet support for the C++ code has been taken down which doesn't help me either



      In the code I do the following:




      1. Declare the properties of the world

      2. Declare a world and initialize it with the properties declared in 1

      3. Declare a DebugDrawer object and initialize the world with this object

      4. Create rigid bodies, initialize their properties and add it to the world

      5. run the simulation (and attempt to run the debugDraw)


      The code is a bit lengthy and I've posted only the snippet that gives insight to what I'm trying to do. My version of entire hello world code can be found here



      The code snippet looks like this:



      int main(int argc, char *argv)
      {

      std::cout << "attempt to run hello world like program using modern c++ and with GUI debugDrawn";

      //create the properties of the world
      . . .
      . . .

      // declare and initialize the world with the above properties
      btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(dispatcher, interface, solver, collisonConfig);
      world->setGravity(btVector3(0.0, -9.81, 0));

      //initialize visualization framework
      GLDebugDrawer *debugDraw = new GLDebugDrawer;
      debugDraw->setDebugMode(1);
      world->setDebugDrawer(debugDraw);


      //create placeholder for shapes, some kind of array
      std::vector<btCollisionShape*> collisionShapes;

      //Create and initialize multiple rigid
      //bodies with specific properties
      . . .

      for(size_t i=0; i<collisionShapes.size(); ++i){

      //some more initialization code
      . . .
      . . .

      //adding the rigid bodies to the wold
      world->addRigidBody(rbody[i]);
      }

      //do some simulation
      for (size_t i = 0; i < 20; ++i) {
      world->stepSimulation(1.f/60.f, 10);

      //print positions of all objects
      for (int j = 0; j<world->getNumCollisionObjects(); ++j){

      btCollisionObject *obj = world->getCollisionObjectArray()[j];
      btRigidBody* bdy = btRigidBody::upcast(obj);

      if(bdy && bdy->getMotionState()){
      btTransform trans;
      bdy->getMotionState()->getWorldTransform(trans);

      //render the rigid bodies in the world
      //DOESN'T WORK
      world->debugDrawWorld();

      //this works
      std::cout << "world pos: " << trans.getOrigin().getX() <<"nY: " << trans.getOrigin().getY() << "nZ:" << trans.getOrigin().getZ() << "n";
      }
      }

      }

      releaseResources(collisionShapes, rbody, myMotionstate);

      return 0;
      }


      This code works fine when I run it on bash, and prints the updated positions of the rigid bodies but I don't see any screen that renders the objects in a graphics.



      I'm not sure what else I'm missing and where should the line `world->DebugDrawWorld()' be placed. Any help will be really appreciated.



      thank you










      share|improve this question
















      I'm looking for an easy way to use debug draw in a very simple bullet physics application to develop my understanding of the interface for DebugDraw. My code, which is basically the code from [Demos/HelloWorld/]1 in bullet3 package, is modified a bit to work with modern c++ stl objects.
      I looked up the older post but none are helpful for me. The bullet support for the C++ code has been taken down which doesn't help me either



      In the code I do the following:




      1. Declare the properties of the world

      2. Declare a world and initialize it with the properties declared in 1

      3. Declare a DebugDrawer object and initialize the world with this object

      4. Create rigid bodies, initialize their properties and add it to the world

      5. run the simulation (and attempt to run the debugDraw)


      The code is a bit lengthy and I've posted only the snippet that gives insight to what I'm trying to do. My version of entire hello world code can be found here



      The code snippet looks like this:



      int main(int argc, char *argv)
      {

      std::cout << "attempt to run hello world like program using modern c++ and with GUI debugDrawn";

      //create the properties of the world
      . . .
      . . .

      // declare and initialize the world with the above properties
      btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(dispatcher, interface, solver, collisonConfig);
      world->setGravity(btVector3(0.0, -9.81, 0));

      //initialize visualization framework
      GLDebugDrawer *debugDraw = new GLDebugDrawer;
      debugDraw->setDebugMode(1);
      world->setDebugDrawer(debugDraw);


      //create placeholder for shapes, some kind of array
      std::vector<btCollisionShape*> collisionShapes;

      //Create and initialize multiple rigid
      //bodies with specific properties
      . . .

      for(size_t i=0; i<collisionShapes.size(); ++i){

      //some more initialization code
      . . .
      . . .

      //adding the rigid bodies to the wold
      world->addRigidBody(rbody[i]);
      }

      //do some simulation
      for (size_t i = 0; i < 20; ++i) {
      world->stepSimulation(1.f/60.f, 10);

      //print positions of all objects
      for (int j = 0; j<world->getNumCollisionObjects(); ++j){

      btCollisionObject *obj = world->getCollisionObjectArray()[j];
      btRigidBody* bdy = btRigidBody::upcast(obj);

      if(bdy && bdy->getMotionState()){
      btTransform trans;
      bdy->getMotionState()->getWorldTransform(trans);

      //render the rigid bodies in the world
      //DOESN'T WORK
      world->debugDrawWorld();

      //this works
      std::cout << "world pos: " << trans.getOrigin().getX() <<"nY: " << trans.getOrigin().getY() << "nZ:" << trans.getOrigin().getZ() << "n";
      }
      }

      }

      releaseResources(collisionShapes, rbody, myMotionstate);

      return 0;
      }


      This code works fine when I run it on bash, and prints the updated positions of the rigid bodies but I don't see any screen that renders the objects in a graphics.



      I'm not sure what else I'm missing and where should the line `world->DebugDrawWorld()' be placed. Any help will be really appreciated.



      thank you







      c++ rendering bullet






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 21:11







      ggulgulia

















      asked Nov 25 '18 at 13:27









      ggulguliaggulgulia

      667915




      667915
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467948%2fsteps-to-display-graphics-using-debug-draw-in-bullet-physics-engine%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467948%2fsteps-to-display-graphics-using-debug-draw-in-bullet-physics-engine%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)