Skip to content

Instantly share code, notes, and snippets.

View slembcke's full-sized avatar
👣
Gruntled

Scott Lembcke slembcke

👣
Gruntled
View GitHub Profile
@slembcke
slembcke / wildcard_collisions.c
Created April 23, 2012 22:06
Wildcard collision handler musings
static cpBool
PlayerTerrainBegin(cpArbiter *arb, cpSpace *space, void *data)
{
CP_ARBITER_GET_SHAPES(arb, playerShape, terrainShape);
GameObject *player = cpShapeGetUserData(playerShape);
GameObject *terrain = cpShapeGetUserData(terrainShape);
cpBool retvalA = player.collidedWith(terrain);
@slembcke
slembcke / DebugNode.h
Created April 23, 2012 23:00
DebugNode.m
/* Copyright (c) 2007 Scott Lembcke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
@slembcke
slembcke / get.rb
Created May 4, 2012 13:50
SSH get/put
#! /usr/bin/env ruby
system "scp -P 2222 #{ARGV[0]} localhost:#{ARGV[1]}"
#define CP_USE_DOUBLES 1
#if CP_USE_DOUBLES
/// Chipmunk's floating point type.
/// Can be reconfigured at compile time.
typedef double cpFloat;
#define cpfsqrt sqrt
#define cpfsin sin
#define cpfcos cos
#define cpfacos acos
@slembcke
slembcke / cpConvexMoment.c
Created May 17, 2012 14:41
Convex Moment
cpFloat moment = cpMomentForPoly(mass, NUM_VERTS, verts, cpvzero);
body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
shape = cpSpaceAddShape(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero));
/*
So cpPolyShapeNew() now always call cpConvexHull() internally to ensure that you are creating convex shapes. Great! Woo! Whatever.
The issue was that cpMomentForPoly() does not.
* If the vertexes had the correct winding, but were concave, it would give you the correct moment for the concave polygon, but not the convex one used for the collider. This seems like it would be reasonable.
@slembcke
slembcke / cpConvexMoment.c
Created May 17, 2012 15:54 — forked from andykorth/cpConvexMoment.c
Convex Moment
// This is a little annoying:
cpVect *hullVerts = (cpVect *)calloc(NUM_VERTS, sizeof(cpVect));
int hullCount = cpConvexHull(NUM_VERTS, verts, hullVerts, NULL, 0.0);
cpFloat mass = 1.0;
cpFloat moment = cpMomentForPoly(mass, hullCount, hullVerts, cpvzero);
body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
shape = cpSpaceAddShape(space, cpPolyShapeNew(body, hullCount, hullVerts, cpvzero));
@slembcke
slembcke / NotCrappyAssertionHandler.m
Created June 8, 2012 23:01
NotCrappyAssertionHandler
@interface NotCrappyAssertionHandler : NSAssertionHandler @end
@implementation NotCrappyAssertionHandler
-(void)handleFailureInFunction:(NSString *)functionName file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format, ...
{
NSLog(@"*** Assertion failure in %@(), %@:%d", functionName, fileName, line);
va_list args;
va_start(args, format);
NSLogv([@"*** Assertion message: " stringByAppendingString:format], args);
@slembcke
slembcke / pitch.rb
Created June 12, 2012 14:58
Overly simplistic pitch detection
SAMPLE_RATE = 44100
DURATION = 2
def tone(freq, phase, t)
Math.sin(t*freq*2.0*Math::PI + phase)
end
sum = 0.0;
(DURATION*SAMPLE_RATE).to_i.times{|sample|
TILE_SIZE = 10
TILES_WIDE = love.graphics.getWidth()/TILE_SIZE
TILES_HIGH = love.graphics.getHeight()/TILE_SIZE
LENGTH_INCREMENT = 5
TRUD_INCREMENT = 5
ACCUMULATOR = 0
@slembcke
slembcke / ChipmunkCocosBody.m
Created July 2, 2012 15:54
ChipmunkCocosBody
#import "ChipmunkCocosBody.h"
@implementation ChipmunkCocosBody
@synthesize syncedNodes = _syncedNodes;
static void
UpdatePosition(cpBody *body, cpFloat dt)
{