qt - Getting a Box2D body created in C++ to collide with Box2D bodies in QML -


i using qml-box2d library. create box2d body fixtures in c++ , use in qml. unfortunately, time create b2body object , create fixtures object app crashes. if use box2dbody object, comes qml-box2d library, doesn't show in qml.

i need box2d body fixtures in c++ collide box2d bodies in qml. proper way this?

pay attention - box2dbody not visual item since derived qobject. adds physical properties target. anyway, think easiest way create physical bodies in qml. if still want in c++ can use code below. suppose, have scene in main.qml qml rect item:

window {     width: 800     height: 600     visible: true      world {}      rectangle {         objectname: "rect"         width: 100         height: 100         x: 350         y: 50         color: "green"     }      rectangle {         id: floor         height: 50         anchors {             left: parent.left             right:  parent.right             bottom: parent.bottom         }         color: "brown"         body {             target: floor             fixtures: box {                 width: floor.width                 height: floor.height                 density: 0.5                 friction: 0.5                 restitution: 0.5             }         }     }      debugdraw {         visible: true         opacity: 0.7     } } 

and want "revive" it:

int main(int argc, char *argv[]) {     qguiapplication app(argc, argv);      box2dplugin plugin;     plugin.registertypes("box2d");      qqmlapplicationengine engine;     engine.load(qurl(qstringliteral("qrc:/main.qml")));      qobject *root = engine.rootobjects()[0];     qquickitem *rect = root->findchild<qquickitem *>("rect");      box2dbody * body = new box2dbody(root);     body->setbodytype(box2dbody::dynamic);     body->settarget(rect);     box2dbox * fixture = new box2dbox(rect);     fixture->setwidth(rect->width());     fixture->setheight(rect->height());     fixture->setdensity(0.8);     fixture->setfriction(0.5);     fixture->setrestitution(0.5);     body->addfixture(fixture);     body->componentcomplete();      return app.exec(); } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -