kbrodie Posted July 10, 2017 Share Posted July 10, 2017 I am trying to get a vehicle to interact with a physical trigger in the world, but the objects don't interact and no callback is ever called. For creating the physical trigger I use the following code: //Create a box-shaped trigger, with size 0. m_physical = Unigine::PhysicalTrigger::create(3, Unigine::Math::vec3()); m_physical->setVisible(true); m_physical->setEnabled(true); m_physical->setCollisionMask(-1); m_physical->setPhysicalMask(-1); m_physical->setExclusionMask(0); m_physical->setEnterCallback(new cHitCallback(this)); Elsewhere in the code, the size, location and rotation is set. To make sure that the trigger is at the expected place, I draw it on screen with with the following code: Unigine::Visualizer::get()->renderSolidBox(m_physical->getSize(), m_physical->getWorldTransform(), m_color); The vehicle has a body and shape created like this: Unigine::ObjectPtr body = Unigine::Object::cast (m_body_node->getReference()) ; m_rigidBody = Unigine::BodyRigid::create(); m_boxShape = Unigine::ShapeBox::create(Unigine::Math::vec3(4.78, 2.52, 3.10)); m_boxShape->setCollisionMask(-1); m_boxShape->setExclusionMask(0); m_boxShape->setEnabled(1); m_rigidBody->addShape(m_boxShape->getShape()); m_rigidBody->setPhysicalMask(-1); m_rigidBody->setEnabled(1); body->setBody(m_rigidBody->getBody()); For testing purposes, I used the following line to visualize the shape of my vehicle: Unigine::Visualizer::get()->renderBox(m_boxShape->getSize(), m_rigidBody->getTransform(), Unigine::Math::vec4(0, 0, 1.0, 1.0)); I have placed a break point in the callbackmethod "void run(Unigine::Ptr<Unigine::Body> body)" of the cHitCallback class, to make sure that the callback is infact called. The break point is never triggered. Did I miss something here? Please help me out. Link to comment
silent Posted July 10, 2017 Share Posted July 10, 2017 Which SDK version are you currently using? How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
alexander Posted July 11, 2017 Share Posted July 11, 2017 Hi, kbrodie! I checked your code on my system. No problems were found. How you define the class cHitCallback? I attached my version to the post. You should see the message "cHitCallback()::run(): called!" in the console when you compile and run it. Best regards, Alexander AppWorldLogic.h AppWorldLogic.cpp Link to comment
kbrodie Posted July 11, 2017 Author Share Posted July 11, 2017 Hi, Alexander, Thank you for the test application, I compiled it and the log message did indeed appear. I wonder why it doesn't work in my code? The cHitCallback looks like this: class cBarrier::cHitCallback: public Unigine::CallbackBase1<Unigine::BodyPtr> { public: cHitCallback(cBarrier* parent) : m_parent(parent) { assert(parent != nullptr); } void run(Unigine::BodyPtr body) override { m_parent->testConditions(); } private: cBarrier* m_parent; }; Not much different from what you did. Maybe there's a global setting (or something in the Unigine.cfg file) with which to disable callbacks (or collision detection), unfortunately the project this is part of is very large and I have no idea where to start looking. Up until this point we had no need for collisions and nobody around here knows if it's disabled. Any idea where I might start looking for options that could've been used to disable colissions? Link to comment
kbrodie Posted July 11, 2017 Author Share Posted July 11, 2017 Okay, small update: Going with Alexanders example, I altered my original test (see first post) and changed the second example there to the following code: //Unigine::ObjectPtr body = Unigine::Object::cast (m_body_node->getReference()) ; m_testDummy = Unigine::ObjectDummy::create(); m_rigidBody = Unigine::BodyRigid::create(); m_boxShape = Unigine::ShapeBox::create(Unigine::Math::vec3(4.78, 2.52, 3.10)); m_boxShape->setCollisionMask(-1); m_boxShape->setExclusionMask(0); m_boxShape->setEnabled(1); m_rigidBody->addShape(m_boxShape->getShape()); m_rigidBody->setPhysicalMask(-1); m_rigidBody->setEnabled(1); //body->setBody(m_rigidBody->getBody()); m_testDummy->setBody(m_rigidBody->getBody()); The object m_testDummy is a completely seperate entity from the vehicle and not connected to it in any way. Whenever the vehicle moves however, it also moves m_testDummy to its own location (by calling setWorldTransform on m_testDummy). Using these changes, it still doesn't work... This leads me to conclude that my problem is most likely a global setting. So, does anyone know a way to globally disable collisions? Thanks. Link to comment
silent Posted July 11, 2017 Share Posted July 11, 2017 Do you have surface_base property assigned to the surfaces of the mesh? It will enable collision detection for that surface. A small test scene will be very helpful in that case. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
kbrodie Posted July 12, 2017 Author Share Posted July 12, 2017 All meshes used in our vehicle have the property surface_base assigned to them. We do seem to use our version of surface_base, which has the following definition in a file called unigine.prop: <property name="surface_base" editable="0"> <!-- parameters --> <parameter collision="1" name="friction" type="float" min="0.0" max="4.0" flags="max_expand">0.5</parameter> <parameter collision="1" name="restitution" type="float" min="0.0" max="1.0">0.5</parameter> <parameter intersection="1" name="occlusion" type="float" min="0.0" max="1.0">0.5</parameter> </property> Link to comment
silent Posted July 12, 2017 Share Posted July 12, 2017 A small test scene will be very nice to check. Could you please provide a small example to us? Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
kbrodie Posted July 12, 2017 Author Share Posted July 12, 2017 I'm sorry, it would be very hard to create a small test scene, due to our integration of Unigine in a larger C++ project. If I wanted to created a small test scene, I would also have to include large sections of our code, just to get it up and running. My apologies for not being able to help here. Link to comment
kbrodie Posted July 12, 2017 Author Share Posted July 12, 2017 Final update: After digging through the code of the application with a coworker, we discovered that one of my predesessors disabled the physics engine (at the time it wasn't needed). Enabling the engine, solved the issue and the callbacks now work. Sorry for any inconvenience this might have caused. Link to comment
Recommended Posts