I am trying to learn Chipmunk. I have a circular object which falls (under gravity) until it hits the ground. Unfortunately, this never occurs as the ground is falling, too! I am not using graphics, just printf's. Could someone point out where I go wrong?
Code: Select all
#include "chipmunk.h"
#include <stdio.h>
#define STEPS 150
#define TDELTA 0.1
#define GRAVITY -9.8
int main(int argc, char **argv)
{
cpInitChipmunk();
cpSpace *space = cpSpaceNew();
space->gravity = cpv(0.0, GRAVITY);
cpBody *body = cpBodyNew(2, INFINITY);
body->p = cpv(0,0);
cpSpaceAddBody(space,body);
cpShape *shape = cpCircleShapeNew(body, 3, cpvzero);
shape->e = 0.5;
shape->u = 0.8;
shape->data = 0;
shape->collision_type = 1;
cpSpaceAddShape(space,shape);
cpBody *botB = cpBodyNew(INFINITY,INFINITY);
botB->p = cpv(0,-50);
cpSpaceAddBody(space,botB);
cpShape *botS = cpSegmentShapeNew(botB,cpv(-50,0),cpv(50,0),1);
botS->e = 0.5; botS->u = 0.1; botS->collision_type = 0;
cpSpaceAddStaticShape(space,botS);
for (int i = 0; i < STEPS; i++) {
cpSpaceStep(space, TDELTA);
printf("(%g,%g)\t(%g,%g)\n",
body->p.x, body->p.y,
botB->p.x, botB->p.y);
}
}
I get the following warnings:
Code: Select all
main.c: In function ‘main’:
main.c:16: warning: floating constant exceeds range of ‘double’
main.c:27: warning: floating constant exceeds range of ‘double’
main.c:27: warning: floating constant exceeds range of ‘double’
Could someone please point out my error? I have a suspicion it involves my use of INFINITY. If it at all matters, I am using a 64 bit machine.
Thank you,
Kevin