michael.zhang Posted February 17, 2011 Share Posted February 17, 2011 Hi. Trying to do this: void contact_callback(){ log.message("callback."); } // ... bodyRigid.setContactCallback("contact_callback"); // ... But, I get this: Removing that setContactCallback line gets rid of the error. Link to comment
frustum Posted February 23, 2011 Share Posted February 23, 2011 We can't reproduce the problem. samples/physics/callbacks_02 sample works normally without callback arguments. Link to comment
michael.zhang Posted February 23, 2011 Author Share Posted February 23, 2011 We can't reproduce the problem. samples/physics/callbacks_02 sample works normally without callback arguments. Yes, it works normally when I use it in a World loaded by the provided main_x64.exe, for example. But when loading the world with that script in my custom application, the error occurs. Since you are able to access the source code, could you take a look at the source of the assertion to see what might cause the error message? Everything else has worked fine in the my custom application, so not sure why setting a contact callback would fail only for my application, and not in the provided applications. Link to comment
michael.zhang Posted February 23, 2011 Author Share Posted February 23, 2011 A question regarding how contacts work. Do contacts only occur if two shapes collide as a result of a physics update? As in, gravity causes one shape to hit another, contact occurs. But if I call setTransform, such that the shapes collide, no contact occurs? If this is the case, how can I detect collisions as a result of a setTransform movement? Link to comment
manguste Posted March 11, 2011 Share Posted March 11, 2011 Basically, physics is updated each tick in the following way: All physics functions called manually from the world script are executed. This means, new body transformations are set, callbacks for collisions (if there will be any) are registered etc. Physics is simulated. That is, collisions between the bodies are calculated, joints are solved (with specified number of iterations), callbacks are triggered. Flush. This is when rendered objects are synchronized with their physical bodies: if there is a change in position, object coordinates are updated. Link to comment
michael.zhang Posted March 11, 2011 Author Share Posted March 11, 2011 Hi Manguste, Thank you for the response. I have been waiting some time for this. To clarify: Step 1: world script update() : user control Step 2: physics simulation Step 3: worldscript flush() : user reacts to updated physics I would like to use a BodyRigid to simulate a sword which is attached to the corresponding mesh. I should, instead of setting the transform of the mesh (which is the default in the Character system for attachments), I need to set the transform of the Body during step 1! This allows the physics to react to the body's collision, which should be physically resolved (moved out of collision) prior to Step 3? Allowing me to react to the solved physics state in Step 3, the flush? For example, setting up my IK to reach the physically solved position/orientation. Thanks for this explanation, I will give this approach a shot. Though, the setContactCallback crash may still occur. I'll let you know how it goes. Please let me know if my reasoning above is correct. Link to comment
manguste Posted March 14, 2011 Share Posted March 14, 2011 Hope you got your questions answered :) To sum it up about callbacks: 1. You can set callbacks anywhere: within init(), update() or flush(). 2. When physics is simulated, callbacks are triggered by contacts, but it only means they are placed in a queue. 3. Callbacks are actually executed first thing next frame or (if there are some more physics iterations following) in the next iteration before physics is simulated one more time. Link to comment
michael.zhang Posted May 20, 2011 Author Share Posted May 20, 2011 The issue disappeared when we created small test cases for the ragdoll. However, now that I am integrating the code into my main application framework, the problem arises again. Basically, if you call setContactCallback() in a method that is called from C++ interface. Crash occurs. Attached is the error message. Unigine::Engine::get()->runWorld("testRagdoll"); This line will cause the attached error message. I’m guessing this has something to do with setting a callback, which causes the engine to search for the function by exploring the call stack. However, calling from C++ causes that search to end prematurely. I hope you can include the fix for this in the next release. Link to comment
ulf.schroeter Posted May 20, 2011 Share Posted May 20, 2011 Unigine::Engine::get()->runWorld("testRagdoll"); Just to be sure, this c++ call is properly wrapped by Unigine::Engine::get()->pushWorld()/popWorld() calls, right ? Link to comment
michael.zhang Posted May 22, 2011 Author Share Posted May 22, 2011 Just to be sure, this c++ call is properly wrapped by Unigine::Engine::get()->pushWorld()/popWorld() calls, right ? Actually, I did not. As my understanding of push/pop was that it is to be used when passing extern class variables to and from script. Whereas as simple function call does not require it. However, I can see how push/popping world context might be required in namespace resolution. I will give this a try. Good idea, Ulf! Link to comment
Recommended Posts