Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sleeping 3D Physics problems?

Author
Message
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 31st Mar 2017 20:27
Another problem with 3D Physics.

If I set the SetObject3DPhysicsCanSleep() property of objects to 1, my jointed physics objects rest in position instead of wobbling around when I rig them - good.

When I want to apply some force to my ragdoll, I need to "wake up" the objects by setting SetObject3DPhysicsCanSleep() to 0 so they participate again.

However, if I then switch SetObject3DPhysicsCanSleep() to 1 again so they can rest after that effect has finished, they never sleep, even though there's no movement.
I checked the default sleep thresholds (which are 1 for angular and 32 for linear) and set these to silly low values and still my objects refuse to sleep.

There's no checking ability for sleep "state" but they are definitely set to SetObject3DPhysicsCanSleep()=1

Is there any other way I can reactivate a slept object? Is there something wrong that I need to "reactivate" it again anyway? It looks like a sleeping object can't become active again until I make it sleepless and then it just stays awake for ever.
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 31st Mar 2017 21:38
All objects by default are able to be put to sleep by the physics engine.
So by default they are set to SetObject3DPhysicsCanSleep ( objId, 1 )

If an object has been put to sleep by the physics engine it can be woke up
another dynamic object passing within a certain distance.

If an object is asleep it must be woke up before you can apply a force to it.
Call SetObject3DPhysicsCanSleep ( objId, 0 ).

If you want it to be put back to sleep by the engine after it meets the sleeping thresholds.
Call SetObject3DPhysicsCanSleep ( objId, 1 ) right after applying the force.

The coffee is lovely dark and deep,and I have code to write before I sleep.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 31st Mar 2017 23:53 Edited at: 31st Mar 2017 23:55
Yep, that's exactly what I'm doing and they don't go back to sleep again after the force is applied.

So I am doing the right thing by waking up a sleeping object, but I have my suspicions about the situation here.
I'll go an collect the linear and angular velocities and report them, but I've even set the sleep thresholds stupid low or even 0 with no effect.

OK, well the angular and linear movement values on the object are still flicking around, but at < 0.001 in all directions (not actually visible, but there is movement) - some positive and negative. The thresholds don't seem to be making anything change, although reading the values for them shows they are set.

My debug shows me that where I change the threshold on those objects, the SetObject3DPhysicsCanSleep(objId,1) is being executed, but not having any effect. I've tried it directly after applying the force and also where I originally had it, when I've detected contact with the ground.

If I start off with cansleep enabled (and don't switch it off) it works, but in a nutshell - on, off then on again doesn't work.
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 1st Apr 2017 00:15
It is working for me.
Can you make a small runnable example that shows it happening?
If it is an error in the code I'll spot it but if not and it is a real bug Paul will need a example to
prove it.
The coffee is lovely dark and deep,and I have code to write before I sleep.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 1st Apr 2017 16:15
It might be something weird because they were jointed, then they weren't etc.
I'll put together an example.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 1st Apr 2017 22:12
Unfortunately, when I make a simplified example with a couple of cubes, it works just fine.

To reproduce exactly what's going on, I'd have to reproduce the whole complex thing with all the joints (and models).

One interesting thing: I have 6 jointed objects which are all slept in position.

Previously, I set SetObject3DPhysicsCanSleep(objId,0) on all 6 objects when I applied the impulse to the head part and all 6 fail to sleep even thought they were switched back to sleepable mode as previously mentioned.

If I only set SetObject3DPhysicsCanSleep(objId,0) on the head part where I apply impulse, the other 5 jointed objects come alive and get pulled along with the impulse and when I disconnect the model (delete the joints) the other 5 do go to sleep properly as expected and just the head stays awake!
This indicates that setting sleep off means switching it on again doesn't work in this situation.

I also made a separate routine which deletes and recreates the physics objects and sleep behaviour of course is working properly again.


nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 1st Apr 2017 22:32 Edited at: 1st Apr 2017 22:34
Something else to consider:

The objects I'm using here are clones from (AGK) autocreated child objects from a loaded animation.

Is it safe to use 3DPhysics on cloned objects?
[edit] and scalePermanent() objects?

I'm not making this any easier am I..

nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 2nd Apr 2017 16:23 Edited at: 2nd Apr 2017 16:33
OK, I now have a working example.

It appears that there is a different default value for SetObject3DPhysicsCanSleep() on a freshly generated physics object.
The first and second buttons rig the jointed object up with and without the setting and you can observe different behaviour.

Also, you can see the never going to sleep after the impulse and dejointing occurs.

[edit - fixed small bug in example]
In fact, just the impulse without doing the joints shows it..

nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 8th Apr 2017 17:39
How do I get this acknowledged as a bug?
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 8th Apr 2017 18:09
Quote: "How do I get this acknowledged as a bug?"


I seriously doubt that TGC will spend anytime on determining if there are bugs in 3D physics or fixing them.
The coffee is lovely dark and deep,and I have code to write before I sleep.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 8th Apr 2017 18:50
That would be deeply worrying for anyone investing time in anything more than just tinkering.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 11th Apr 2017 02:19
There is a section of code in the Bullet physics engine that specifically prevents an object enabling sleep if it has previously disabled sleeping. I'll force it to change for the next version, but without knowing why they put it there it may not behave as you expect.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 11th Apr 2017 20:39
Thanks Paul. Doesn't make any sense at this point, but I'll take it
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 12th Apr 2017 01:37
Quote: "There is a section of code in the Bullet physics engine that specifically prevents an object enabling sleep if it has previously disabled sleeping. I'll force it to change for the next version, but without knowing why they put it there it may not behave as you expect."


Where exactly in the Bullet source id this code?
This could seriously break Bullet for everyone with out proper testing.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 12th Apr 2017 13:43
Quote: "Where exactly in the Bullet source id this code?"

In btCollisionObject.cpp line 51, setActivationState(int newState)

Quote: "This could seriously break Bullet for everyone with out proper testing."

I haven't changed the Bullet code, I've changed your code to call forceActivationState(int newState) instead when enabling sleeping. So if there are any side effects it should only affect this command.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 12th Apr 2017 19:18
Also, I noted a difference in the initial state. A GetObject3DPhysicsCanSleep() would be useful.

In the default (unset) state, objects at rest go straight to sleep - setting sleep on manually has a little delay while the resting object goes to sleep (or the other way around)
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 12th Apr 2017 19:36 Edited at: 12th Apr 2017 19:46
nz0

Have you tried your demo since the change? For me I can no longer apply the angular velocity to the cube.
So now the command does not work at all. What I would have suggested is that the tier1 user could have either set the mass to Zero or
deleted and recreated the objects once they fell below a certain threshold for sleeping.


P.S. forceActivationState() is used in the Bullet demos with static bodies only and takes a different parameter of #define ACTIVE_TAG 1
This is what I meant by breaking it for all users.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 13th Apr 2017 14:57
I've change your code to use ACTIVE_TAG instead of WANTS_DEACTIVATION and it seems to work now
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 13th Apr 2017 23:50
Hmm - I might have run into something there - I have moved my code along now to instancing and it's not working I'll restore a backup and check....

nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 14th Apr 2017 12:03
Yep, it broken.
Now I can't apply velocity to anything. In my cube demo, it seems to show a faint amount of movement but it's quickly zero'd - like it's ultra damped.

Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 16th Apr 2017 02:04
Wonder how long it will be left broken?
The coffee is lovely dark and deep,and I have code to write before I sleep.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 16th Apr 2017 13:15
I'd rather it was back how it was before - I could work around it.

I'd be happy to wait a bit longer then for a more permanent and accurate fix.

Login to post a reply

Server time is: 2024-05-08 16:41:52
Your offset time is: 2024-05-08 16:41:52