This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "DeformableBitmapDemo.h" | |
@implementation DeformableBitmapDemo | |
@synthesize space; | |
#define PIXEL_SIZE 4 | |
#define TILE_SIZE 128 | |
- (id) init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.0 -> 0.0 | |
0.9 -> 1/19 | |
0.8 -> 1/9 | |
0.7 -> 3/17 | |
0.6 -> 1/4 | |
0.5 -> 1/3 | |
0.4 -> 3/7 | |
0.3 -> 7/13 | |
0.2 -> 2/3 | |
0.1 -> 9/11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) draw; | |
{ | |
glDisableClientState(GL_COLOR_ARRAY); | |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |
glDisable(GL_TEXTURE_2D); | |
glPushMatrix(); { | |
glScalef(CC_CONTENT_SCALE_FACTOR(), CC_CONTENT_SCALE_FACTOR(), 1.0); | |
glLineWidth(1.0f); | |
cpSpaceEachShape(space.space, drawShape, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if __has_feature(objc_arc) | |
typedef __strong id CCARRAY_ID; | |
#define CCARRAY_RETAIN(obj) obj | |
#define CCARRAY_RELEASE(obj) (void)obj | |
#else | |
typedef id CCARRAY_ID; | |
#define CCARRAY_RETAIN(obj) [obj retain] | |
#define CCARRAY_RELEASE(obj) [obj release] | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpVect a, b; // segment endpoints | |
cpVect p; // point you are testing | |
cpVect delta = cpvsub(b, a); | |
cpFloat closest_t = cpvdot(delta, cpvsub(p, a))/cpvlengthsq(delta); | |
cpVect closest = cpvlerp(a, b, cpfclamp01(closest_t)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#extension GL_OES_standard_derivatives : enable | |
varying lowp vec4 frag_color; | |
varying lowp vec2 frag_texcoord; | |
void main() | |
{ | |
#if GL_OES_standard_derivatives == 1 | |
gl_FragColor = frag_color*smoothstep(0.0, length(fwidth(frag_texcoord)), 1.0 - length(frag_texcoord)); | |
#else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If 'self' is assigned to obj.delegate and I don't explicitly copy the block | |
// it crashes with an EXC_BAD_ACCESS in objc_msgSend() calling 'retain' on | |
NSArray *constructors = [NSArray arrayWithObjects: | |
[^(cpVect pos){ | |
GameObject *obj = ...; | |
obj.delegate = self; | |
return obj; | |
} copy], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Some old PNG screenshot code that I used in a Ruby binding. | |
static VALUE | |
rbas_screen_shot(VALUE self, VALUE filename) | |
{ | |
int bytes = AS_SCREEN_W * AS_SCREEN_H * 3; | |
GLubyte pixels[bytes]; | |
glReadPixels(0, 0, AS_SCREEN_W, AS_SCREEN_H, GL_RGB, GL_UNSIGNED_BYTE, pixels); | |
char *name = StringValuePtr(filename); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct Person { | |
char *name; | |
int age; | |
}; | |
struct Employee { | |
// You can cast a pointer to an Employee struct to | |
// a Person struct because you put a person struct in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ** (vanilla) Point Queries: | |
// For the shape specific function, you give it a point and it returns true/false if the point is inside: | |
cpBool cpShapePointQuery(cpShape *shape, cpVect p); | |
// The "easy" space query function takes a point and some filter parmeters and returns the shape at the point or NULL: | |
cpShape *cpSpacePointQueryFirst(cpSpace *space, cpVect point, cpLayers layers, cpGroup group); | |
// The callback based iterator version looks like this: | |
typedef void (*cpSpacePointQueryFunc)(cpShape *shape, void *data); |