I'm trying to build a simple chipmunk project in Linux 32 bit, ArchLinux. And I have a problem with dereferencing pointer in the C Language.
The following code :
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <chipmunk/chipmunk.h>
#include <chipmunk/chipmunk_unsafe.h>
#define DENSITY (1.0/10000.0)
#define GRABBABLE_MASK_BIT (1<<31)
cpShapeFilter GRAB_FILTER = {CP_NO_GROUP, GRABBABLE_MASK_BIT, GRABBABLE_MASK_BIT};
cpShapeFilter NOT_GRABBABLE_FILTER = {CP_NO_GROUP, ~GRABBABLE_MASK_BIT, ~GRABBABLE_MASK_BIT};
static cpShape *shape;
int main ()
{
//ChipmunkDemoMessageString="Hello Chipmunk";
cpSpace *space = cpSpaceNew();
cpSpaceSetIterations(space, 30);
cpSpaceSetGravity(space, cpv(0, -500));
cpSpaceSetSleepTimeThreshold(space, 0.5f);
cpSpaceSetCollisionSlop(space, 0.5f);
cpBody *body, *staticBody = cpSpaceGetStaticBody(space);
// Create segment around the edge of the screen.
shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320, -240), cpv(320, -240), 0.0f));
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER);
cpFloat width = 50.0f;
cpFloat height = 70.0f;
cpFloat mass = width*height*DENSITY;
cpFloat moment = cpMomentForBox(mass, width, height);
body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
shape = cpSpaceAddShape(space, cpBoxShapeNew(body, width, height, 0.0));
cpShapeSetFriction(shape, 0.6f);
for(float time =0.0; time < 3.0; time += 1.0f/60.0f)
{
cpSpaceStep(space, time);
cpVect mV = body->p; // Error | dereferencing pointer to incomplete type ‘cpBody {aka struct cpBody}’
printf("body position %f:x %f:y\n", mV.x, mV.y);
}
//Destroy The Space
cpSpaceFree(space);
return 0;
}