开发者

error in running a demo called bounce.c in chipmunk

开发者 https://www.devze.com 2022-12-27 10:48 出处:网络
#include <stdlib.h> #include <stdio.h> #include <math.h> #include \"/home/satyajit/Chipmunk-5.2.0/include/chipmunk/chipmunk.h\"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include "/home/satyajit/Chipmunk-5.2.0/include/chipmunk/chipmunk.h"
#include "drawSpace.h"
#include "ChipmunkDemo.h"

cpSpace *space;
cpBody *staticBody;

int i;
static void
update(int ticks)
{
    int steps = 3;
    cpFloat dt = 1.0f/60.0f/(cpFloat)steps;

    for( i=0; i<steps; i++)
    {
        cpSpaceStep(space, dt);
    }
}

static void
add_box()
{
    const cpFloat size = 10.0f;
    const cpFloat mass = 1.0f;

    cpVect verts[] = {
        cpv(-size,-size),
        cpv(-size, size),
        cpv( size, size),
        cpv( size,-size),
    };

    cpFloat radius = cpvlength(cpv(size, size));

    cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForPoly(mass, 4, verts, cpvzero)));
    body->p = cpv(frand()*(640 - 2*radius) - (320 - radius), frand()*(480 - 2*radius) - (240 - radius));
    body->v = cpvmult(cpv(2*frand() - 1, 2*frand() - 1), 200);

    cpShape *shape = cpSpaceAddShape(space, cpPolyShapeNew(body, 4, verts, cpvzero));
    shape->e = 1.0f; shape->u = 0.0f;
}

static cpSpace *
init(void)
{
    staticBody = cpBodyNew(INFINITY, INFINITY);

    cpResetShapeIdCounter();

    space = cpSpaceNew();
    cpSpaceResizeActiveHash(space, 30.0f, 1000);
    space->iterations = 10;

    cpShape *shape;

    // Create segments around the edge of the screen.
    shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
    shape->e = 1.0f; shape->u = 1.0f;
    shape->layers = NOT_GRABABLE_MASK;

    shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
    shape->e = 1.0f; shape->u = 1.0f;
    shape->layers = NOT_GRABABLE_MASK;

    shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
    shape->e = 1.0f; shape->u = 1.0f;
    shape->layers = NOT_GRABABLE_MASK;

    shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,240), cpv(320,240), 0.0f));
    shape->e = 1.0f; shape->u = 1.0f;
    shape->layers = NOT_GRABABLE_MASK;

    for(i=0; i<10; i++)
        add_box();

    cpBody *body = cpSpaceAddBody(space, cpBodyNew(100.0f, 10000.0f));

    shape = cpSpaceAddShape(space, cpSegmentShapeNew(body, cpv(-75,0), cpv(75,0), 5.0f));
    shape->e = 1.0f; shape->u = 1.0f;

    cpSpaceAddConstraint(space, cpPivotJointNew2(body, staticBody, cpvzero, cpvzero));

    return space;
}

static void
destroy(void)
{
    cpBodyFree(staticBody);
    cpSpaceFreeChildren(space);
    cpSpaceFree(space);
}

const chipmunkDemo Bounce = {
    "Bounce",
    NULL,
    init,
    update,
    destroy,
};

This is the code . The error i get when i run it is .

 /usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o: In function `_start':
    (.text+0x18): undefined reference to `main'
    /tmp/ccyG1FXX.o: In function `update':
    Bounce.c:(.text+0x37): undefined reference to `cpSpaceStep'
    /tmp/ccyG1FXX.o: In function `add_box':
    Bounce.c:(.text+0x18f): undefined reference to `cpvlength'
    Bounce.c:(.text+0x1d3): undefined reference to `cpMomentForPoly'
    Bounce.c:(.text+0x1e2): undefined reference to `cpBodyNew'
    Bounce.c:(.text+0x1f4): undefined reference to `cpSpaceAddBody'
    Bounce.c:(开发者_StackOverflow中文版.text+0x368): undefined reference to `cpPolyShapeNew'
    Bounce.c:(.text+0x37a): undefined reference to `cpSpaceAddShape'
    /tmp/ccyG1FXX.o: In function `init':
    Bounce.c:(.text+0x45c): undefined reference to `cpBodyNew'
    Bounce.c:(.text+0x466): undefined reference to `cpResetShapeIdCounter'
    Bounce.c:(.text+0x46b): undefined reference to `cpSpaceNew'
    Bounce.c:(.text+0x48f): undefined reference to `cpSpaceResizeActiveHash'
    Bounce.c:(.text+0x548): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x55a): undefined reference to `cpSpaceAddStaticShape'
    Bounce.c:(.text+0x610): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x622): undefined reference to `cpSpaceAddStaticShape'
    Bounce.c:(.text+0x6cf): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x6e1): undefined reference to `cpSpaceAddStaticShape'
    Bounce.c:(.text+0x78e): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x7a0): undefined reference to `cpSpaceAddStaticShape'
    Bounce.c:(.text+0x7fd): undefined reference to `cpBodyNew'
    Bounce.c:(.text+0x80f): undefined reference to `cpSpaceAddBody'
    Bounce.c:(.text+0x89b): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x8ad): undefined reference to `cpSpaceAddShape'
    Bounce.c:(.text+0x91d): undefined reference to `cpPivotJointNew2'
    Bounce.c:(.text+0x92f): undefined reference to `cpSpaceAddConstraint'
    /tmp/ccyG1FXX.o: In function `destroy':
    Bounce.c:(.text+0x949): undefined reference to `cpBodyFree'
    Bounce.c:(.text+0x956): undefined reference to `cpSpaceFreeChildren'
    Bounce.c:(.text+0x963): undefined reference to `cpSpaceFree'
    collect2: ld returned 1 exit status


You need to update your header search path.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号