cpBody function no const cpBody *
Posted: Sun Aug 29, 2010 2:12 pm
Hey, I donno if this would be considered a bug, but its a little annoying to have to cast const cpBody pointers to do stuff like cpBodyLocal2World. Is there any reason why things that are read only like getters and functions where theres no modification to the body not in const form?
It's not really just in the cpBody functions where i've ran into this, like some of the polyshape functions take const but others don't and basically don't modify anything.
Or maybe this is by design to discourage pointers?
Just thought I'd bring this up since i run into it pretty often
Code: Select all
// Convert body local to world coordinates
static inline cpVect
cpBodyLocal2World(cpBody *body, cpVect v)
{
return cpvadd(body->p, cpvrotate(v, body->rot));
}
// Convert world to body local coordinates
static inline cpVect
cpBodyWorld2Local(cpBody *body, cpVect v)
{
return cpvunrotate(cpvsub(v, body->p), body->rot);
}
Code: Select all
// Returns the minimum distance of the polygon to the axis.
static inline cpFloat
cpPolyShapeValueOnAxis(const cpPolyShape *poly, const cpVect n, const cpFloat d)
{
cpVect *verts = poly->tVerts;
cpFloat min = cpvdot(n, verts[0]);
int i;
for(i=1; i<poly->numVerts; i++)
min = cpfmin(min, cpvdot(n, verts[i]));
return min - d;
}
// Returns true if the polygon contains the vertex.
static inline int
cpPolyShapeContainsVert(cpPolyShape *poly, cpVect v)
{
cpPolyShapeAxis *axes = poly->tAxes;
int i;
for(i=0; i<poly->numVerts; i++){
cpFloat dist = cpvdot(axes[i].n, v) - axes[i].d;
if(dist > 0.0f) return 0;
}
return 1;
}
Or maybe this is by design to discourage pointers?
Just thought I'd bring this up since i run into it pretty often