Trying to detect rest-state
-
- Posts: 18
- Joined: Mon Oct 05, 2009 5:24 am
Trying to detect rest-state
What is the best way to generate an event once my object (a 6 sided die I'm sub-classing from Updateable) is more or less inert? Would I need to poll the angular velocity on pitch, yaw, and rotation within some threshold of change within a collision event? The obvious problem is that I'm trying to detect the value of the die. Once I determine that it is at rest, I can determine its value.
Side note: Might there be any plans to generate "lambda events" where the user can detect a particular state?
Thanks!
Side note: Might there be any plans to generate "lambda events" where the user can detect a particular state?
Thanks!
Re: Trying to detect rest-state
The most straightforward way to do this is probably just querying the entity's isActive property each update. If it is true, then it's still bouncing around. If it is false, then it has entered a rest state.
There's nothing specifically planned like that, but I'll definitely take a look when the development cycle works its way around to the event system again.
There's nothing specifically planned like that, but I'll definitely take a look when the development cycle works its way around to the event system again.
-
- Posts: 18
- Joined: Mon Oct 05, 2009 5:24 am
Re: Trying to detect rest-state
Cool, I'll try that. Thanks!
-
- Posts: 18
- Joined: Mon Oct 05, 2009 5:24 am
Re: Trying to detect rest-state
since I'm only sub-classing Updateable, I don't have the isActive member, do I? I searched around and isActive was a part of Entity. Did I misunderstand something about building a class in bEPU?
-
- Posts: 18
- Joined: Mon Oct 05, 2009 5:24 am
Re: Trying to detect rest-state
oh, I spoke too soon...
Re: Trying to detect rest-state
Sorry, yes- it is a member of Entity, not Updateable. Updateable is designed for systems which run at various stages within the engine's execution (such as during force application). It contains nothing to help with actually simulating a die or physics in general.
Entities are physical objects like dice. If you want to simulate a die, you could make a Box (which is a subclass of Entity) and add it to the space. That Box's isActive state would then be polled each update.
Entities are physical objects like dice. If you want to simulate a die, you could make a Box (which is a subclass of Entity) and add it to the space. That Box's isActive state would then be polled each update.
-
- Posts: 18
- Joined: Mon Oct 05, 2009 5:24 am
Re: Trying to detect rest-state
Well, box works for the d6, but not so much for d10, etc. Is Updateable not the way to add entities to bEPU? Do I have to sub-class some a base entity?
Re: Trying to detect rest-state
Correct, Updateable is not the way to add entity types. Technically, you can subclass the Entity class, but generally you will not need to do so.
Instead, consider using the ConvexHull class. It's a very general purpose entity type that can be used to represent a large variety of polygon-sided shapes. To create one, you'll need a set of points that compose your object. For example, a d6 die would have 8 points, one for each corner of the box. For a d10, one option would be 5 coplanar points forming a regular pentagon with one point on each side of that plane to give it volume and 10 sides.
Instead, consider using the ConvexHull class. It's a very general purpose entity type that can be used to represent a large variety of polygon-sided shapes. To create one, you'll need a set of points that compose your object. For example, a d6 die would have 8 points, one for each corner of the box. For a d10, one option would be 5 coplanar points forming a regular pentagon with one point on each side of that plane to give it volume and 10 sides.
-
- Posts: 18
- Joined: Mon Oct 05, 2009 5:24 am
Re: Trying to detect rest-state
Ah, this is highly informative.
Good answer about the d10! I was looking at convex hull, but wasn't sure. I tell ya what, I'm gonna read through some more examples and understand the api a little better. This clears up a great deal, though; Thank you!
Good answer about the d10! I was looking at convex hull, but wasn't sure. I tell ya what, I'm gonna read through some more examples and understand the api a little better. This clears up a great deal, though; Thank you!
-
- Posts: 18
- Joined: Mon Oct 05, 2009 5:24 am
Re: Trying to detect rest-state
:My object won't rest (always isActive):
I'm back to this now and I still haven't discovered a solution. My event handler just won't land in the (!isActive) body. I basically have a d6 that I dropped into my scene where it bounced a bit and then finally came to rest. I've got some debug setup and it basically prints "isActive" as long as I'll sit there and watch it, seemingly never coming to a complete rest. How can I make my objects able to be inert? My first assumption is altering things like friction coefficients, force dampening, etc. Could anyone direct me on this?
I'm back to this now and I still haven't discovered a solution. My event handler just won't land in the (!isActive) body. I basically have a d6 that I dropped into my scene where it bounced a bit and then finally came to rest. I've got some debug setup and it basically prints "isActive" as long as I'll sit there and watch it, seemingly never coming to a complete rest. How can I make my objects able to be inert? My first assumption is altering things like friction coefficients, force dampening, etc. Could anyone direct me on this?
Re: Trying to detect rest-state
Do you observe any minor jiggling when you look at the die? If so, it's usually caused by scaling issues (e.g. the ground is 100+ units across represented by a single entity and your die is only 0.1 unit across). If this is the problem, the best solution is to either re-scale the world, or if that doesn't make sense for your simulation, tessellate the environment mesh so each individual entity that the die interacts with is not excessively scaled.
Having an excessive number of points composing the final convex hull of the die may also make it harder for it to settle down. It still should eventually, but it may take a little longer.
Another possibility is that you are currently using the entity updated event to monitor the isActive state. This won't capture the deactivation since entity updates do not occur on deactivated entities. Instead, the isActive state can be checked from some external per-frame perspective.
If none of these things apply, you can also fiddle with the space.simulationSettings.deactivation clamping settings. These can adjust how willing objects are to go to sleep.
Having an excessive number of points composing the final convex hull of the die may also make it harder for it to settle down. It still should eventually, but it may take a little longer.
Another possibility is that you are currently using the entity updated event to monitor the isActive state. This won't capture the deactivation since entity updates do not occur on deactivated entities. Instead, the isActive state can be checked from some external per-frame perspective.
If none of these things apply, you can also fiddle with the space.simulationSettings.deactivation clamping settings. These can adjust how willing objects are to go to sleep.