Skip to content

Instantly share code, notes, and snippets.

View slembcke's full-sized avatar
👣
Gruntled

Scott Lembcke slembcke

👣
Gruntled
View GitHub Profile
#import <string.h>
#import <objc/objc-runtime.h>
#import <Foundation/Foundation.h>
#import "SimpleTestCase.h"
static void
PrintException(NSException *e)
{
#include "level0_bits.h"
float polyline_verts0_0[] = {1022.000, 37.945, 1008.000, 29.078, 1002.000, 26.508, ..., 57.195, 0.000, 66.867};
polyline polyline0_0 = {
polyline_verts0_0,
473,
false,
};
/////// RopeNode.h
#import "cocos2d.h"
#import "ObjectiveChipmunk.h"
struct RopeNodeParticle;
@interface RopeNode : CCNode {
ChipmunkBody *_body1, *_body2;
cpVect _offset1, _offset2;
@slembcke
slembcke / gist:1078948
Created July 12, 2011 20:48
GetDoubleTime()
#include <mach/mach.h>
#include <mach/mach_time.h>
double GetDoubleTime(void)
{
mach_timebase_info_data_t base;
mach_timebase_info(&base);
return (double)mach_absolute_time()*((double)base.numer/(double)base.denom)*1.0e-9;
}
@slembcke
slembcke / gist:1107240
Created July 26, 2011 17:06
Using blocks with Chipmunk callbacks
// Define this function somewhere
static void CallArbiterBlock(cpBody *body, cpArbiter *arbiter, void (^block)(cpArbiter *arbiter)){block(arbiter);}
// Then you can do this:
// __block makes the variable writable from within a block, otherwise they are read only.
__block cpVect impulseSum = cpvzero;
cpBodyEachArbiter(scaleStaticBody, (cpBodyArbiterIteratorFunc)CallArbiterBlock, ^(cpArbiter *arb){
impulseSum = cpvadd(impulseSum, cpArbiterTotalImpulse(arb));
});
#define CHIPMUNK_ARBITER_GET_SHAPES(arb, a, b) ChipmunkShape *a, *b; { \
cpShape *shapeA, *shapeB; \
cpArbiterGetShapes(arb, &shapeA, &shapeB); \
a = shapeA->data; b = shapeB->data; \
}
#import "ObjectiveChipmunk.h"
void main(){
cpArbiter arb = {};
CHIPMUNK_ARBITER_GET_SHAPES(arb, shapeA, shapeB);
return 0;
}
for(ChipmunkPolyline *line in [[ChipmunkImageSampler samplerWithImageFile:@"TestImage.psd" isMask:TRUE flip:TRUE] marchSoft]){
ChipmunkPolyline *simple = [line simplifyCurves:3];
NSLog(@"count: %lu", simple.count - 1);
for(int i=0; i<simple.count - 1; i++){
cpVect a = simple.verts[i];
cpVect b = simple.verts[i+1];
ChipmunkShape *shape = [space add:[ChipmunkSegmentShape segmentWithBody:space.staticBody from:a to:b radius:2]];
shape.friction = 1.0;
@slembcke
slembcke / ImageDemo.m
Created September 12, 2011 21:37
Chipmunk Pro deformable terrain: ImageDemo.m
#import "ImageDemo.h"
@implementation ImageDemo
@synthesize space;
-(void)marchImage
{
//Create a sampler for a mask image
ChipmunkImageSampler *sampler = [ChipmunkImageSampler samplerWithImageFile:@"TestImage.psd" isMask:TRUE];
@slembcke
slembcke / DeformableDemo.m
Created September 12, 2011 21:38
Chipmunk Pro deformable terrain: DeformableDemo.m
#import "DeformableDemo.h"
// We'll start with a couple octaves of Worley's cellular noise as a base.
static cpFloat
CellularNoise(cpVect pos)
{
static const uint8_t permute[] = {
151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,