I'm not concerned about immediate take up, but without anyones comments it's hard to judge if it is of any use at all. Particularly when there are design decisions still to be made.
C++ Buoyancy
General DiscussionI was under the impression that only Buoyancy was there (topic title). But looking at the code I see all controllers? I wasn't that interested in the Buoyancy, but the TensorDamping is great.
Boris, just in case you need confirmation about the work you're doing, this Buoyancy code (and your concept of controllers in general) are of great interest to me - it's just that for my game, I'm knee-deep in other physics-y things yet, so I'm not ready to spend time looking at controllers or buoyancy. I very much look forward to being able to, though 😀
I really like this concept of controllers. A while back, I even suggested something similar (http://www.box2d.org/forum/viewtopic.php?f=4&t=734) .. just never had the time to implement anything.
I'd love to see some Steering Behavior controllers! With an extendible controller architecture like this, it wouldn't be to difficult to add some.
I'd love to see some Steering Behavior controllers! With an extendible controller architecture like this, it wouldn't be to difficult to add some.
Yes, that post undoubtedly influenced me. I am not going to implement any more controllers, or am not likely to. The whole point (to me) is that by making a more modular framework, everyone can contribute their own. Which is why I'm keen to establish demand, resolve any complaints, and check the code into the repository.
I'm working on a small project that uses Box2D. I was about two implement a small feature myself that has to do with variable gravity, but then I decided to give b2GravityController.
I'm using the latest SVN revision 192 with controllers and their hooks included...
I'm initializing the controller (in an otherwise perfectly working simulation...) this way:
b2GravityControllerDef gDef;
gDef.G=1.0f;
gDef.invSqr=true;
...
b2Controller * aGravityController=aWorld->CreateController(&gDef);
aGravityController->AddBody(aBody1);
aGravityController->AddBody(aBody2);
The result:
all the bodies attached to the controller (independent of their number, mass, position) immediately disappear from the scene.
Boundary listener's Violate is called for all of them.
When I look up the positions they show up as NaNs... Pretty weird, nothing like that has happened before. Bodies normally freeze when leaving the world with proper positions intact.
Ideas? at first I thought I was doing something horribly wrong while initializing the controller, but it rather seems like an issue with momentarily propelling the bodies ad infinitum
ivanhoe1982
I'm using the latest SVN revision 192 with controllers and their hooks included...
I'm initializing the controller (in an otherwise perfectly working simulation...) this way:
b2GravityControllerDef gDef;
gDef.G=1.0f;
gDef.invSqr=true;
...
b2Controller * aGravityController=aWorld->CreateController(&gDef);
aGravityController->AddBody(aBody1);
aGravityController->AddBody(aBody2);
The result:
all the bodies attached to the controller (independent of their number, mass, position) immediately disappear from the scene.
Boundary listener's Violate is called for all of them.
When I look up the positions they show up as NaNs... Pretty weird, nothing like that has happened before. Bodies normally freeze when leaving the world with proper positions intact.
Ideas? at first I thought I was doing something horribly wrong while initializing the controller, but it rather seems like an issue with momentarily propelling the bodies ad infinitum
ivanhoe1982
I attempted to create a little gravity test and had similar results as you, but didn't look much further into it.
But I just rechecked it, and it would appear that the gravity controller has a small bug in it that's causing this behavior.
Lines 37 and 49 are:
but should be:
But I just rechecked it, and it would appear that the gravity controller has a small bug in it that's causing this behavior.
Lines 37 and 49 are:
Code:
b2Vec2 d = body1->GetWorldCenter() - body1->GetWorldCenter();
but should be:
Code:
b2Vec2 d = body2->GetWorldCenter() - body1->GetWorldCenter();
Ok, I should not have let that one slip past, sorry. Fixed now, and actually tested a bit.
I'm still having the same issue despite correcting the apparent bug in the controller (funny how the most obvious things slip when you're looking in all the wrong places...).
I'm gonna do some more testing in my code once I have a moment and post findings (if any).
Thanks
I'm gonna do some more testing in my code once I have a moment and post findings (if any).
Thanks
Ok, part of the mystery solved.
In my world, during the initialization, I actually had a bunch of bodies with the exact same X,Y position. I never paid attention to it, since Box2D pushes them away from each other in the first couple of frames, and I was testing some other aspects of the sim.
Anyhow, as easy to predict this piece (the f vector) computed to NaN (division by zero). I temporarily fixed it by putting the whole piece in an IF based on r2>0
As much as my putting the bodies in the exact same place may have been a bit foolish, it's not really a behaviour you can discount - given a certain combination of collision masks, static and dynamic bodies etc. it is entirely conceivable, that bodies may have the exact same position every once in a while.
I'm not sure whether a simple IF is the way to fix it for good, there may be a case in which this is undesirable either...
In my world, during the initialization, I actually had a bunch of bodies with the exact same X,Y position. I never paid attention to it, since Box2D pushes them away from each other in the first couple of frames, and I was testing some other aspects of the sim.
Anyhow, as easy to predict this piece (the f vector) computed to NaN (division by zero). I temporarily fixed it by putting the whole piece in an IF based on r2>0
Code:
b2Vec2 d = body1->GetWorldCenter() - body2->GetWorldCenter();
float32 r2 = d.LengthSquared();
b2Vec2 f = G / r2 / sqrt(r2) * body1->GetMass() * body2->GetMass() * d;
body1->ApplyForce(f , body1->GetWorldCenter());
float32 r2 = d.LengthSquared();
b2Vec2 f = G / r2 / sqrt(r2) * body1->GetMass() * body2->GetMass() * d;
body1->ApplyForce(f , body1->GetWorldCenter());
As much as my putting the bodies in the exact same place may have been a bit foolish, it's not really a behaviour you can discount - given a certain combination of collision masks, static and dynamic bodies etc. it is entirely conceivable, that bodies may have the exact same position every once in a while.
I'm not sure whether a simple IF is the way to fix it for good, there may be a case in which this is undesirable either...
Original thread: https://box2d.org/forum/viewtopic.php?t=1664