Skip to content

Instantly share code, notes, and snippets.

View slembcke's full-sized avatar
👣
Gruntled

Scott Lembcke slembcke

👣
Gruntled
View GitHub Profile
#include <stdlib.h>
#include "png.h"
extern long image_memory(int numbytes, void *data_ptr);
extern void throw_error(char *filename, char *error);
#define PNG_SIG_BYTES 8
static void
const NSUInteger testCount = 1000000;
{
GLKMatrix4 m = M; // Initialized from a global to prevent constant folding when inlining.
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
for (NSUInteger i = 0; i < testCount; i++) {
m = GLKMatrix4Multiply(m, m);
}
NSLog(@"time GLKit: %f", CFAbsoluteTimeGetCurrent() - t);
M = m; // Need to save the value of m to avoid it being optimized away
@slembcke
slembcke / _.md
Created September 26, 2013 00:45
mustache phase
@slembcke
slembcke / _.md
Created September 1, 2013 04:54
XOR Triangles
@slembcke
slembcke / _.md
Created August 30, 2013 03:30
xor squares
@slembcke
slembcke / _.md
Created August 30, 2013 01:48
xor circles
@slembcke
slembcke / _.md
Created August 29, 2013 14:14
Lissajous
// Old slice code:
cpVect centroid = cpCentroidForPoly(clippedCount, clipped);
cpFloat mass = cpAreaForPoly(clippedCount, clipped)*DENSITY;
cpFloat moment = cpMomentForPoly(mass, clippedCount, clipped, cpvneg(centroid));
cpBody *new_body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
cpBodySetPos(new_body, centroid);
cpBodySetVel(new_body, cpBodyGetVelAtWorldPoint(body, centroid));
cpBodySetAngVel(new_body, cpBodyGetAngVel(body));
@slembcke
slembcke / multiple.c
Created March 30, 2013 14:08
Returning multiple values in C/C++
// Basically in C you only get a single return value,
// but there are ways around that.
// The first, and more common method is to return things using references.
// Pass pointers to the output variables, and write the output values to them.
// While it's common, a lot of people think it's a really bad practice (self included).
void ReturnMultiple1(int a, int b, int *outX, int *outY)
{
// Write to the output variables.
@slembcke
slembcke / gist:5091122
Created March 5, 2013 15:32
cpvslerp tests
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(1.0), 1.0);
cpVect c = a;
cpVect v = cpvslerp(a, b, 0.0);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);