This project has moved and is read-only. For the latest updates, please go here.

Problem with polygon shapes

Topics: User Forum
Jan 15, 2009 at 2:56 PM
Edited Jan 15, 2009 at 3:27 PM
I am currently doing some (static) polygon shape tests, and running into serious performance problems: if I create a collision shape like this:

f = 0.01
Begin vertices
    vertex( f * -450.0, f * -271.0 )
    vertex( f * -226.0, f * -254.0 )
    vertex( f * -450.0, f * -319.0 )
End vertices

The code executes allmost instantly.
But if I change f to something like 1 or even 10, it takes up to 20 seconds (or even more) until this code is executed!

I've downloaded a trial version of VTune, and it showed some (at least to me) weird results:
It appears that, the bigger the shape, the more instructions it takes.
(I must admit I have now idea if I measured right, but it's the same scene.)

f = 10.01
Name                       Clockticks events        Instructions Retired events
Normalize                 12,537,000,000            4,452,000,000
GetNearestFeature     8,880,000,000            3,462,000,000
Subtract                     4,152,000,000            2,286,000,000
Subtract                     3,651,000,000            3,201,000,000
NextIndex                  3,090,000,000            3,255,000,000
GetEdge                     2,790,000,000            945,000,000
Dot                            2,688,000,000            831,000,000
GetEdge                     2,661,000,000            2,403,000,000
GetVertexNormal       2,457,000,000            687,000,000
GetEdgeNormal          2,094,000,000            897,000,000
GetNearestDistance    1,194,000,000            615,000,000
f = 0.01        
Name                     Clockticks events        Instructions Retired events
Normalize                  18,000,000                3,000,000
Subtract                     12,000,000                3,000,000
Dot                             6,000,000                0
GetVertexNormal        6,000,000                0
Length                         3,000,000                0
GetNearestFeature      3,000,000                6,000,000
Subtract                      3,000,000                3,000,000
GetEdge                     3,000,000                3,000,000
NextIndex                        0                        9,000,000

Does anybody have a clue what could cause this?
The CollisionGridCellSize and generally all the other properties are set to default.
Maybe that's the problem? On the other hand, I've read in some thread that scale doesn't matter... ?
I am really clueless and thankful for any input!

Edit: if the whole thing is a scale/sizing issue, what's the recommendation for something like 1 meter?
1.0, 100 or can it really be any custom unit, e.g. like 1 unit = 2cm (UnrealEngine units)

Jan 15, 2009 at 8:04 PM
Are you able to send the test to me?

If you are creating geometries, the calculation of the distance grid (used by narrow phase collision system) is the one causing this. It calculation of the grid takes some time to calculate and if you have a large geometry, it will take a lot of time.

Also, if your vertices are actual vertices, and not just test data. They should be relative to 0, 0.
Jan 16, 2009 at 9:54 AM
Shame, shame on me!

In my test, I didn't change the collisionGridCellSize in the CreatePolygonGeom function, I simply tried to modify it via the property (after it has already been created).
I now changed it to 32, and now it works perfect (and fast ;) )

Thanks for the input!
Jan 16, 2009 at 12:14 PM
Edited Jan 16, 2009 at 12:31 PM
That's great. Even though you did not find a bug, you provided us with a test case. I'll make sure to test for that scenario in the future. Thanks.

Edit: As for the scale, we have the ConvertUnits class to help with unit conversion. The default ratio is 50. You can change it to whatever you like.