Games-Chipmunk

 view release on metacpan or  search on metacpan

inc/cpSpace.xsh  view on Meta::CPAN


void
cpSpaceFree( space )
    cpSpace *space

int
cpSpaceGetIterations( space )
    cpSpace *space

void
cpSpaceSetIterations( space, iterations )
    cpSpace *space
    int iterations

cpVect
cpSpaceGetGravity( space )
    cpSpace *space

void
cpSpaceSetGravity( space, gravity )
    cpSpace *space
    cpVect gravity

t/010_hello_chipmunk.t  view on Meta::CPAN

# Now that it's all set up, we simulate all the objects in the space by
# stepping forward through time in small increments called steps.
# It is *highly* recommended to use a fixed size time step.
my $timeStep = 1.0/60.0;
my $last_y = 0;

# For our tests, we want to check that there was some kind of movement.
# Problem is, there might not be enough acceleration at the start to actually 
# move anything.  We'll just do a few runs to prime the system.
cpSpaceStep($space, $timeStep) for 1 .. 5;
my $iterations = 0;
for(my $time = $timeStep * 5; $time < 2; $time += $timeStep){
    my $pos = cpBodyGetPosition($ballBody);
    my $vel = cpBodyGetVelocity($ballBody);
    diag( sprintf(
        'Time is %5.2f. ballBody is at (%5.2f, %5.2f). Its velocity is (%5.2f, %5.2f)',
        $time, $pos->x, $pos->y, $vel->x, $vel->y
    ) ) if DEBUG;

    cmp_ok( $pos->y, '!=', $last_y, "Y has moved" );
    $last_y = $pos->y;

    cpSpaceStep($space, $timeStep);
    $iterations++;
}

cmp_ok( $iterations, '>', 0, "Iterated over code" );

# Clean up our objects and exit!
cpShapeFree($ballShape);
cpBodyFree($ballBody);
cpShapeFree($ground);
cpSpaceFree($space);

done_testing();

t/020_hello_chipmunk_callback.t  view on Meta::CPAN

    diag( "Body is: $body" ) if DEBUG;
    $vel_callback_count++;
    cpBodyUpdateVelocity( $body, $gravity, 0, $dt );
    return;
};
cpBodySetVelocityUpdateFunc( $ballBody, $vel_callback );
diag( "Set velocity update func" ) if DEBUG;

my $time = $timeStep * 5;
my $prev_time = $time;
diag( "Beginning time iterations" ) if DEBUG;
for(; $time < 2; $time += $timeStep){
    diag( "Time $time, dt $dt, prev time $prev_time" ) if DEBUG;
    my $pos = cpBodyGetPosition($ballBody);
    diag( "Got body position" ) if DEBUG;
    my $vel = cpBodyGetVelocity($ballBody);
    diag( "Got body velocity" ) if DEBUG;
    cpSpaceStep($space, $timeStep);
    diag( "Stepped" ) if DEBUG;
    $dt = $time - $prev_time;
    $prev_time = $time;
}

diag( "Completed time iterations" ) if DEBUG;
cmp_ok( $vel_callback_count, '>', 2,
    "Velocity update callback has been called at least twice" );

# Clean up our objects and exit!
cpShapeFree($ballShape);
cpBodyFree($ballBody);
cpShapeFree($ground);
cpSpaceFree($space);

done_testing();



( run in 2.082 seconds using v1.01-cache-2.11-cpan-71847e10f99 )