Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RigidBody Location/Orientation listener ? #5

Open
AlexisDrogoul opened this issue Jun 9, 2021 · 6 comments
Open

RigidBody Location/Orientation listener ? #5

AlexisDrogoul opened this issue Jun 9, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@AlexisDrogoul
Copy link

Hi,

I have begun using (and adapting) Libbulletjme to the GAMA simulation platform (http://gama_platform.org), in order to replace the ageing JBullet implementation we were using. Thank you for the wonderful job you've been doing and for producing a version of the library usable by non-JME users/developers.

I have however a question (or request) : in the previous version of Bullet (and JBullet), the motion state of rigid bodies was receiving setTransform(...) whenever the body was changing its location or orientation in space. This allowed me to notify the corresponding agents in the simulation world of the changes.

I havent been able to find a similar entry point in your library. Does it mean it does not exist (anymore) in Bullet and that the only solution is to browse through all rigid bodies every step to read their motion state ? Or is there some smarter way to implement such a "listener" ?

Thanks in advance !

@stephengold
Copy link
Owner

Perhaps the RigidBodyMotionState class can meet your need.

@AlexisDrogoul
Copy link
Author

But the methods by which this motion state is updated are not exposed in Java, are they ? What I had in mind was to create, like I did with JBullet, a subclass of the motion state in order to capture the messages sent by the engine whenever a change in location/rotation was made for the body (and later propagate this change to the software agent in charge of this physical body).

@stephengold stephengold added the enhancement New feature or request label Jun 9, 2021
@stephengold
Copy link
Owner

You're right that it's currently not exposed. I'll investigate how difficult it might be to expose.

@AlexisDrogoul
Copy link
Author

Actually, any kind of listener to the properties changes (ideally those in the MotionState -- location and rotation --) would be nice. I have changed my strategy: I'm not trying to inherit from Bullet objects (body, motion state, etc. as I did with JBullet) anymore, and I manage the exchanges between the simulation and the engine with a thin layer of wrappers. It works well but the downside is that, with let's say 10000 agents in a scene and only 100 of them actually changing their position or orientation, I have to browse through all of them to verify it (which means I also have to keep somewhere a record of their previous location). Not extremely efficient, and it could be better handled with some listener attached to the bodies.
Thanks anyway for the hard work on this very nice library !

@stephengold
Copy link
Owner

The most straightforward way to add location/rotation listeners for rigid bodies would be to define a new MotionStateListener interface and add an addListener() method to RigidBodyMotionState.

Before introducing a new interface, I'd like to get clearer on the motivation. What's the application? The scene you describe (10000 agents with only 1% moving on any particular tick) sounds like a corner case to me. Do the other 9900 agents ever move at all? I'm also surprised that you don't already have a record each agent's previous location.

@AlexisDrogoul
Copy link
Author

Yep. That's a corner case. You're right. One of the extreme cases I'm using as tests. But actually, we have users on GAMA building very different models (from people evacuating buildings to land-use change under climate changes, from physics to computational sociology) and each of them is a corner case. We cant cover all of them, obviously, but at least try to offer balanced and reasonable performances in different scenarios. Regarding the location+rotation, well, it's actually a bit more complicated than that. Each agent has already a "body" defined as a 2D JTS geometry (+ additional 3D information when we use it). Neither its location or rotation are kept as they are completely encoded into the geometry itself : the location is the center of mass of the of the object, and the rotation is applied to the object immediately. To make a long story short, comparing the new location to the previous one is evidently possible, but it's a long process. And rotation would need to completely change the encoding of geometries...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants