About convexSweepTest() : how to get multiple results?

Verbo
Posts: 39
Joined: Fri May 08, 2009 9:27 pm

About convexSweepTest() : how to get multiple results?

Post by Verbo »

Hi,

I am currently trying to implement a convex sweep test for each wheel of my vehicle in order to improve the wheel reaction to obstacles.
In my case, I want to do my convex sweep from the wheel hardpoint to the wheel maximum contact point (as an analogy to the raycast method).

From what I understand at this point, convexSweepTest() seems to only return one result. But in my situation, I would like to get more than one result in order to evaluate the best hit point for the wheel. This way I would be able to detect if the wheel is hitting a wall AND an obstacle at the same time, and apply proper impulse to the vehicle in order to make it react to the wall, and the usual suspension and friction calculation for the ground hit point.

What would be the best solution here? Should I create a new class derived from ConvexResultCallback that would accumulate the single hit results? Or should I simply recall the convex convexSweepTest() from the last result hit point, and so on, until I reach the wheel maximum contact point?

Any help or hint that could point me in the proper direction? :)

Thanks guys.

Verbo
Ellon
Posts: 10
Joined: Wed Jul 29, 2009 4:04 am
Location: Seoul, Korea

Re: About convexSweepTest() : how to get multiple results?

Post by Ellon »

Hi,

In my case, I implemented by just deriving ConvexResultCallback so to collect single results to buffer (std::vector) along the way it encounters.
Then results could be sorted for its own purpose. (std::sort, std::nth_element, std::partition and so on with various predicates)
Calling convexSweepTest() again slows considerably on my situation.

If some object should be add by result, collecting whole first might better because addRigidBody or addCollisionObject looks like to affect ConvexResultCallback itself.

Thanks
Verbo
Posts: 39
Joined: Fri May 08, 2009 9:27 pm

Re: About convexSweepTest() : how to get multiple results?

Post by Verbo »

Hi,

Thanks for the answer, much appreciated. :) So,if I understand what you`re saying, I should make only one call to ConvexSweep with a class derived ConvexResultCallback that would accumulate the results into an array.

When you mention: "Calling convexSweepTest() again slows considerably on my situation", you mean that you call the ConvexSweep again for a same wheel, but with the same callback, right? Is the slowdown affecting the simulation dramatically or is it still workable?

But I am not sure to understand what you mean by "If some object should be add by result, collecting whole first might better because addRigidBody or addCollisionObject looks like to affect ConvexResultCallback itself". You are speaking about cases where rigid bodies are added dynamically during the simulation? Still, I am not sure of what you mean by that.

But still, thanks for the hint, I will look forward to it.

Verbo

p.s it`s cool to see that Bullet Physics reaches out up to South Korea! I spent a short 6 hours in Seoul 2 years ago during my flight transit, and I enjoyed it! :D
Ellon
Posts: 10
Joined: Wed Jul 29, 2009 4:04 am
Location: Seoul, Korea

Re: About convexSweepTest() : how to get multiple results?

Post by Ellon »

Hi Verbo,

Yeah, if you need 'multiple' contact points, my suggestion is to implement an 'accumulator' by deriving ConvexSweepCallback and call it one time per a wheel. If you have four wheels, then just four invocation should be occur. In one batch, 1) you collect contact points for a wheel and 2) process them and then 3) go to next wheel.

And I mean calling 'ConvexSweep again' for a same wheel, with the same callback.
For the speed concern, it's still workable (slows down not very dramatical but just considerable :) ).
The main consideration for me is that I have some objects to be added dynamically during the callback. It slows down somehow my simulation and even leads to mis-behaviour (re-calculating broadphase I suspect? I hope someone would clarify that or correct if I was wrong.) So I accumulate them first to avoid this problem from the root.

For the vehicle, they recommend using 'btRaycastVehicle' instead of using composed bodies and hinges. Raycast-vehicle has several limitations of its own though, but I could live with it now :). Have you tried it?

Thanks

p.s. it's also cool to see someone in this forum have been in Seoul! I'm afraid that you have some difficulties to grasp my poor english but I'm trying! :wink:
Verbo
Posts: 39
Joined: Fri May 08, 2009 9:27 pm

Re: About convexSweepTest() : how to get multiple results?

Post by Verbo »

Hi,

Ok cool, then we meant the same thing :)

I should not have problem with the object added dynamically for now, since I physicalize everything at start, before the car even start moving.

About the implementation, yes, I have been using btRaycastVehicle, but I followed Erwin suggestion and I duplicated the code to customize it a bit to fit my needs without breaking the bullet physics API (I hate modifying the library and merge the changes when I new version comes out). So I might actually implement a wheel convex sweep solution to replace the raycast. Well, at least, I will try, and I will see how fine I can make it :)

However, I am still considering using "using composed bodies and hinges", but just as a last resort. Our car racing game is more puzzle-oriented, the car don`t go crazy fast and the wheels are most of the time outside the chassis, so it could be an more interesting solution to avoid wheel clipping. But it will all depend if I have time to make it, since I am the only programmer in my team for our little game. :cry:

Ok, back to work!

Thx!

Verbo
Ellon
Posts: 10
Joined: Wed Jul 29, 2009 4:04 am
Location: Seoul, Korea

Re: About convexSweepTest() : how to get multiple results?

Post by Ellon »

Hi,

Good. Now I can catch what's your plan. You're going to make a something like 'btConvexSweepVehicle' based on copy of btRaycastVehicle to prevent problems related to version update. That would be a real cool thing!

Keep the good work and I hope to listen how it works.

Cheers,
Verbo
Posts: 39
Joined: Fri May 08, 2009 9:27 pm

Re: About convexSweepTest() : how to get multiple results?

Post by Verbo »

Hi again,

He!he! Thanks, I hope I can live to the expectation!

Just a last question.

When you said "And I mean calling 'ConvexSweep again' for a same wheel, with the same callback" how do you get a different result on the second call?.

I reimplemented addSingleResult to return 1 so that I could get all the hit result (erwin mentioned that once), but still, I only get one result. Is it because my wheel is on a flat ground or should I get more result even if I am on a flat surface? Otherwise, when you recall ConvexSweep again with the same callback, how do you proceed to gather more result?

Also, when I get my first result, the X coord of my hit point seems very different than the one I had with a normal raycast in the same situation, it makes my car levitate a bit over the ground. Did you experiment that?

Ok, back to my head ache... :roll:

Verbo