Slot Car Game

Discuss any questions about BEPUphysics or problems encountered.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Slot Car Game

Post by Norbo »

Which are the params which affect the Barrow phase, for tuning?
The narrow phase does not any real significant general tuning factors, especially since triangle-convex is a special case. Some of the more esoteric things like MPR depth refinement iteration limits could help, but you aren't going to get a significant speed up from that (maybe 10% at the cost of worse behavior).
Reducing the size of the AABB Arras, should consume more memory but should reduce the number of triangles to test. Or not?
I'm not entirely sure what you mean here, but there's no way to reduce the number of triangles to test within a given pruned volume without reducing the actual number of triangles in that volume. (The engine is not using a uniform grid for the mesh acceleration structure, if that's what you're wondering; it uses a bounding volume hierarchy.)
Using a squished cylinder works a lot better. But not enough.
How long does it take? The Xbox360 is definitely slow, but it can handle 1000 boxes smashing together in orbit or 100 boxes all bunched up in a wall; it should be able to handle a couple of reasonably built cars without any issue.

If it's still taking something like 15 milliseconds per time step, something is likely going wrong that I can't divine directly from the information provided.

If it's more like 7 milliseconds and you just want to get it down below 5.5 ms so that it can run at 180hz, then that's a little closer to expecations. Still a bit on the slow side though, even for the Xbox360, but a combination of environmental details like excessive geometry density could conceivably slow it down that much.

With so few objects, multithreading is probably not helping at all. It has a small fixed cost due to the overhead of forking and joining repeatedly; disabling it could save a tiny bit of time. Maybe somewhere between 0 and 2 milliseconds on the Xbox.

Edit for edit:
I know the size of the paddle, so that it isn't necessary that the AABB area is greater than the surface of the paddle, isn't it?
An AABB will always have greater volume than the object it contains, unless the object it contains is an AABB. AABBs are used because they fit very well into efficient acceleration structures. Direct use of a paddle shape or other tighter volumes make hierarchy traversal and pruning more expensive.

The library computes the tightest possible AABB for a shape. However, velocity-based expansion of an AABB is required for CCD and some query consistency, so the bounding box includes the swept motion from the current time step to the next time step.
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

Re: Slot Car Game

Post by -=Magic=- »

Some more informations:
- I've enabled PositionUpdateMode.Continuous for the Paddle.
- With the paddle as squished cylinder, the Narrow Phase goes from 0.6 to 7-8ms but with some spikes to 15ms in certain circumstances.

This is an example of a turn, so you may see the density of the tasselation (I don't think it is so high...) :
Image
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Slot Car Game

Post by Norbo »

That is some pretty high density, especially considering the upper polygon will be split into many triangles. That mesh appears to be 432 triangles; there could easily be more than 100 triangles in the paddle's AABB at high speeds if I'm interpreting the scale right. Most of those triangles will also be tested with the rest of the car, multiplying the number of triangle-convex tests by 4 or 5.

15 ms still seems high for the narrow phase alone, even given hundreds of triangle-convex tests on the xbox360. What happens if you simplify the car down further so that it's just a box with a paddle, without wheels? If it drops to 2/3 or 1/3 the cost in the worst case, then it was likely just the hundreds of triangle tests. If the time doesn't change much, then there's likely something else going on.
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

Re: Slot Car Game

Post by -=Magic=- »

Maybe I found the issue.... for better joint stability, during some previous test I added a static capsule under the paddle. So that the paddle rotate around Y axis, and at the same origin, there's a static capsule (with a radius < of the minimum radius of the paddle) joined to the car's box to form a compund body.

I forgot this! :)

Now I removed the capsule, and all seems works fine. NarrowPhase at around 4-5ms. Just sometimes there's some spikes..

I'll do some more tests :)

Thanks for the help Norbo !!
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

Re: Slot Car Game

Post by -=Magic=- »

I saw that on a previous version of the BEPU, there was a ConvexCastRayWheel. why have you removed it from the engine?

From a performance point of view, it would be better to use a raycasted wheel, or a constraint/entity wheel (like a cylinder)? (ex. is better a vehicleinput approach or a cuspensioncar like ?)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Slot Car Game

Post by Norbo »

I saw that on a previous version of the BEPU, there was a ConvexCastRayWheel. why have you removed it from the engine?
The vehicle was rewritten quite a while ago. The convex cast wheel wasn't particularly valuable and it's relatively easy to add back for someone who truly needs it (copy-paste the RayCastWheelShape and replace the ray casts with convex casts).
From a performance point of view, it would be better to use a raycasted wheel, or a constraint/entity wheel (like a cylinder)? (ex. is better a vehicleinput approach or a cuspensioncar like ?)
Using the Vehicle class would likely be marginally faster than a constraint-entity vehicle.
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

Re: Slot Car Game

Post by -=Magic=- »

mmm I'm trying to use a convex cast.. I did what you wrote, creating a new class by copy/paste of the RayCastWheelShape.

then I used collidable.ConvexCast(_shape, ref startingTransform, ref sweep, out hit) instead of the collidable.RayCast(new Ray(base.wheel.Suspension.WorldAttachmentPoint, base.wheel.Suspension.WorldDirection), base.wheel.Suspension.RestLength, out hit)

_shape is a cylindershape


Vector3 wheelAxis = Vector3.Cross(base.wheel.Suspension.WorldDirection, Vector3.Forward);

RigidTransform startingTransform = new RigidTransform();
// where the center of the wheel is
startingTransform.Position = base.wheel.Suspension.WorldAttachmentPoint + base.wheel.Suspension.WorldDirection * base.wheel.Suspension.RestLength;
// Rotate the cylinder, matching the wheel axis
startingTransform.Orientation = Quaternion.CreateFromAxisAngle(wheelAxis, MathHelper.PiOver2);
// Direction of the cast ray
Vector3 sweep = base.wheel.Suspension.WorldDirection;

but the final result, is wrong.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Slot Car Game

Post by Norbo »

I should note that ray casts will be slightly faster than convex casts and there usually is no perceptible difference in behavior between the two. I would recommend sticking with ray cast wheels just for ease of use if possible.

As for convex casts, the starting transform should not include the rest length, or else the wheel will begin at the furthest possible state and then cast even further beyond.

Also, I left out a few details in my previous summary of creating convex cast wheels. Convex casts have volume, so you have to adjust the sweep length and cast origin accordingly. Otherwise, you get early hits and related issues.
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

Re: Slot Car Game

Post by -=Magic=- »

Norbo wrote:I should note that ray casts will be slightly faster than convex casts and there usually is no perceptible difference in behavior between the two. I would recommend sticking with ray cast wheels just for ease of use if possible.
I cannot use raycast wheel, because the presence of the slot. which cause the wheel to fall under the track.
I have a good entity/constraint model that works. now I'm trying the other one (raycasting model).
I will create a combo wheel (ray+convex) and I will change the ray model depends of the situations.
the front wheel should be alwasy a raycast wheel, since the front wheels never go over a slot (but if the paddle goes out of the slot, I switch the front wheel to use raycast instead)
fo the rear wheel, I should use raycast or convexcast depending from how far the center of the rear axis is near/far the center of the lane (slot).

is there anyway to draw the raycasts?

Norbo wrote:IAs for convex casts, the starting transform should not include the rest length, or else the wheel will begin at the furthest possible state and then cast even further beyond.

Also, I left out a few details in my previous summary of creating convex cast wheels. Convex casts have volume, so you have to adjust the sweep length and cast origin accordingly. Otherwise, you get early hits and related issues.
do you mean something like:
Vector3 sweep = base.wheel.Suspension.WorldDirection * base.wheel.Suspension.RestLength;
?

--------

I've not found any information about how convexcast works.
I suppose that the RigidTransform parameter should contain the position in a world space of the center of the shape, and its orientation (since the default cylinder shape rotates around his Y axis, I've to rotate it).
The sweep parameter should contain the direction (normalized) of the rays.

With such assumptions, I tryed:

// Rotation axe of the wheel
Vector3 wheelAxis = Vector3.Cross(base.wheel.Suspension.WorldDirection, Vector3.Forward);

RigidTransform startingTransform = new RigidTransform();
// where the center of the wheel is
startingTransform.Position = base.wheel.Suspension.WorldAttachmentPoint + base.wheel.Suspension.WorldDirection * base.wheel.Suspension.RestLength;
// Rotate the cylinder, matching the wheel axis
startingTransform.Orientation = Quaternion.CreateFromAxisAngle(wheelAxis, MathHelper.PiOver2);
// Direction of the cast ray
Vector3 sweep = base.wheel.Suspension.WorldDirection;


I've tried other kind of transformations... without any success.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Slot Car Game

Post by Norbo »

I will create a combo wheel (ray+convex) and I will change the ray model depends of the situations.
the front wheel should be alwasy a raycast wheel, since the front wheels never go over a slot (but if the paddle goes out of the slot, I switch the front wheel to use raycast instead)
fo the rear wheel, I should use raycast or convexcast depending from how far the center of the rear axis is near/far the center of the lane (slot).
I would not recommend introducing that type of complexity; it's almost certainly not worth it. Only do it if actual tests dictate its necessity.
is there anyway to draw the raycasts?
Not built into the debug drawer.
I've tried other kind of transformations... without any success.
I went ahead and added a CylinderCastWheelShape to the development fork: http://bepuphysics.codeplex.com/SourceC ... evelopment

Check the modified VehicleInput for an example of its usage.
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

Re: Slot Car Game

Post by -=Magic=- »

Great!
Post Reply