Skip to content

Instantly share code, notes, and snippets.

View jblocksom's full-sized avatar

Jonathan Blocksom jblocksom

View GitHub Profile
@jblocksom
jblocksom / 00_setAsRotation.c
Last active December 13, 2015 19:19
3D rotation matrix for arbitrary axis and angle
void setAsRotation(GLfloat m[16], GLfloat angle, GLfloat ax, GLfloat ay, GLfloat az)
{
// Start with something valid
setAsIdentity(m);
// Normalize axis if necessary
GLfloat axisLength = sqrtf(ax*ax + ay*ay + az*az);
if (axisLength == 0.0f) return ;
ax /= axisLength;
ay /= axisLength;
@jblocksom
jblocksom / cube_coords.c
Last active October 9, 2015 12:28
OpenGL sample texture coordinates
// three xyz coordinates, three normal coordinates, two texture coordinates *
// six vertices per face *
// six faces per cube
GLfloat gCubeVertexData[(3 + 3 + 2) * 6 * 6] =
{
// Data layout for each line below is:
// positionX, positionY, positionZ, normalX, normalY, normalZ, texCoord0S, texCoord0T,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
@jblocksom
jblocksom / embeddedJS.m
Created July 25, 2012 19:10
Fix UIWebView chapter JavaScript
- (void)motionBegan:(UIEventSubtype)motion
withEvent:(UIEvent *)event
{
#define STRINGIFY(js) #js
NSString *js = @ STRINGIFY(
var $elements = $('.leftArea_container>div'),
$rand = $elements.not(':first').eq(Math.floor(Math.random() * $elements.length));
$rand.slideUp(500,function(){ $(this).insertBefore($elements.first()); }).slideDown();
);
@jblocksom
jblocksom / pg_241_BNRAVViewController.m
Created May 3, 2012 20:56
AVFoundation Chapter Helpers HBM 4/30/12
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toIO
duration:(NSTimeInterval)duration
{
CGFloat angle = 0;
switch (toIO) {
case UIInterfaceOrientationPortrait:
angle = 0;
break;
case UIInterfaceOrientationPortraitUpsideDown:
angle = M_PI;
@jblocksom
jblocksom / BigViewPageView.m
Created March 1, 2012 20:07
Update to BigViewPageView.m for Leaks chapter
// Replace @synthesize offscreenContext with this code:
-(CGContextRef )offscreenContext
{
return offscreenContext;
}
-(void)setOffscreenContext:(CGContextRef)anotherOffscreenContext
{
if (offscreenContext != anotherOffscreenContext)
@jblocksom
jblocksom / Page 202 BigViewScrollView.m
Created February 29, 2012 20:43
updateResolution method - Advanced iOS Scroll View chapter
- (void)updateResolution {
//LogMethod();
isdblTapZooming = NO;
float zoomScale = [self zoomScale];
CGSize oldContentViewSize = [contentView frame].size;
//zooming properly resets contentsize as it happens.
CGSize newContentSize = [self contentSize];
CGPoint newContentOffset = [self contentOffset];
@jblocksom
jblocksom / newPathForRoundedRect.m
Created February 28, 2012 22:03
newPathForRoundedRect from Chapter 12 of Advanced iOS book
- (CGPathRef)newPathForRoundedRect:(CGRect)rect
radius:(CGFloat)radius
{
CGMutablePathRef result = CGPathCreateMutable();
CGRect innerRect = CGRectInset(rect, radius, radius);
CGFloat inside_right = innerRect.origin.x + innerRect.size.width;
CGFloat outside_right = rect.origin.x + rect.size.width;
CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height;