I have used box2d quite a bit with Darkbasic and am excited that there is at least a partial implementation for GLBasic. I have virtually no C skills whatsoever so trying to extend the wrapper myself has been a head-banging exercise in futility. So, I do have a couple of questions and hopefully somebody will be kind enough to help me out...
This code was posted in this thread as a replacement for the original b_WorldDebug. It allows the debug drawing to be offset, I was wondering if it were possible to modify it to actually offset the position of the world bodies themselves. DB has a command for something similar to this in it's wrapper called Screen Transform.. I've used it to scroll the world and it has worked really well.
FUNCTION b_WorldDebug: xorg, yorg, scale // added circle radius marker
INLINE
b2Vec2 offset(xorg, yorg);
for(int i=0; i<LEN(bBody); ++i)
{
b2Body* pB = bBody(i);
if(!pB) continue;
for(b2Shape* pShp = pB->GetShapeList(); pShp; pShp = pShp->GetNext())
{
switch(pShp->GetType())
{
case e_circleShape:
{
b2CircleShape* pCirc = (b2CircleShape*)pShp;
const b2Vec2& p1 = pB->GetWorldPoint( pCirc->GetLocalPosition() );
DGInt r = pCirc->GetRadius();
DGInt a = pB->GetAngle() * -180.0 / 3.14159265358979323846;
DGInt ox, oy;
for(DGInt phi=0; phi<=360; phi+=5)
{
DGInt x = scale*p1.x+xorg+SIN(phi)*r, y=scale*p1.y+yorg+COS(phi)*r;
if(phi>0)
DRAWLINE(ox, oy, x, y, RGB(0,255,0));
ox=x; oy=y;
}
DGInt x = scale*p1.x+xorg+SIN(a)*r, y = scale*p1.y+yorg+COS(a)*r; // circle radius marker
DRAWLINE(x, y, scale*p1.x+xorg, scale*p1.y+yorg, RGB(255,255,0)); //
}
break;
case e_polygonShape:
{
b2PolygonShape* pPoly = (b2PolygonShape*)pShp;
for(int j=0; j<pPoly->GetVertexCount(); ++j)
{
int k = (j+1)%pPoly->GetVertexCount();
const b2Vec2& p1 = pB->GetWorldPoint(pPoly->GetVertices()[j]);
const b2Vec2& p2 = pB->GetWorldPoint(pPoly->GetVertices()[k]);
// Bah! Local coordinates!
DRAWLINE(scale*p1.x+xorg, scale*p1.y+yorg, scale*p2.x+xorg, scale*p2.y+yorg, RGB(0,255,0));
}
}
break;
}
}
}
ENDINLINE
ENDFUNCTION
My second question concerns how to read a vector from GLBasic. This function returns vec.x and vec.y but I have no idea how to store and use the information it is returning..
FUNCTION b_GetWorldVector AS Tb_Vec2: body%, localx, localy
INLINE
b2Body* pB = bBody(body);
b2Vec2 vec = pB->GetWorldVector(b2Vec2(localx, localy));
Tb_Vec2 out;
out.x = vec.x; out.y=vec.y; return out;
ENDINLINE
ENDFUNCTION
I have a few more headaches I'm trying to figure out but if somebody could help me out with these, I would very much appreciate it.
Thanks