Box2D optimization functions

Ask all of your support questions here

Re: Box2D optimization functions

Postby Ivan » Wed Oct 05, 2011 1:05 pm

The new interface works pretty good and is much lighter on the GC.

A couple of things I noticed is that some functions require passing a b2Vec2:
"local x, y = b2body:GetWorldPointXY ( b2Vec2, x, y )"
Is there a way to get the transformed point without passing a b2Vec2?
Actually, this is not really an issue however since you can keep a b2Vec2 buffer in Lua.

A couple of funcs are missing too although this is a minor gripe:
Code: Select all
b2pulleyjoint:GetGroundAnchor1 ( )
b2pulleyjoint:GetGroundAnchor2 ( )


Lastly, are the"ContactResult" and "ContactPoint" objects (returned by the ContactListener) garbage collected?
I have a feeling that they don't need to be since:
1.You can't call ContactListener functions manually from Lua
2.You shouldn't store references to the returned structures
Ivan
Site Admin
 
Posts: 415
Joined: Thu Dec 27, 2007 9:21 pm

Re: Box2D optimization functions

Postby Phil » Wed Oct 05, 2011 3:13 pm

Body's methods like GetWorldPoint do not update the supplied b2Vec2, but return a new b2Vec2. It is possible to implement new methods that transform the vector in-place, but they won't be standard Box2D.

I missed these, will add them later.

All ContactListener callback args are not GC-ed. Trying to store and access them outside the callback will set your pc on fire :)
Phil
 
Posts: 200
Joined: Fri Dec 28, 2007 12:47 am

Re: Box2D optimization functions

Postby Ivan » Sun Oct 23, 2011 10:45 am

Looks like a couple of box2D functions/objects from "b2Collision.h" were not exported to Lua:
Code: Select all
assert(b2CollideCircles)
assert(b2CollidePolygonAndCircle)
assert(b2CollidePolygons)
assert(b2Manifold)

These functions would be useful for filtering box2d queries since "QueryAABB" returns potentially intersecting shapes.

Also, another nice optimization would be to have:
Code: Select all
b2body->GetXForm ( xf )

Where xf would be a buffer XForm object that would be filled by GetXForm.

PS. I found a simple workaround to filtering the queries: creating a sensor shape and looking at its list of contact points.


Also, I propse a minor change in "b2PolygonDef.vertices"
Right now it's being indexed starring from 0.
This makes it incompatible with IsValidPolygon and leads to some annoyances when programming from Lua since it requires special code for iterating the vertices.
This is not that important though.
Ivan
Site Admin
 
Posts: 415
Joined: Thu Dec 27, 2007 9:21 pm

Re: Box2D optimization functions

Postby Ivan » Thu Oct 27, 2011 8:00 pm

The way "b2PolygonDef.vertices" works needs a bit clarification.
For example:
Code: Select all
def.vertices[1]:Set ( 10, 0 )

local a = def.vertices[1]
-- a is now pointing to a b2Vec with the value of ( 10, 0 )

def.vertices[1] = b2Vec2 ( 4, -3 )
-- a is now ( 4, -3 )

It's important to note that the reference "a" changes when the vertices are changed which is not typical Lua behavior.
Ivan
Site Admin
 
Posts: 415
Joined: Thu Dec 27, 2007 9:21 pm

Previous

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron