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
- (IBAction)showHideView:(id)sender | |
{ | |
// Fade out the view right away | |
[UIView animateWithDuration:1.0 | |
delay: 0.0 | |
options: UIViewAnimationOptionCurveEaseIn | |
animations:^{ | |
thirdView.alpha = 0.0; | |
} | |
completion:^(BOOL finished){ |
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
NSArray *stringsArray = @[ @"string 1", | |
@"String 21", | |
@"string 12", | |
@"String 11", | |
@"String 02" ]; | |
static NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | | |
NSWidthInsensitiveSearch | NSForcedOrderingSearch; | |
NSLocale *currentLocale = [NSLocale currentLocale]; | |
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
int multiplier = 7; | |
int (^myBlock)(int) = ^(int num) { | |
return num * multiplier; | |
}; | |
printf("%d", myBlock(3)); // prints "21" |
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
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) { | |
int i, j, c = 0; | |
for (i = 0, j = nvert-1; i < nvert; j = i++) { | |
if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) | |
c = !c; | |
} | |
return c; | |
} |
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
polygon a = Polygon(4, v(0,0),v(0,3),v(3,3),v(3,0)), b = Polygon(4, v(4,4),v(4,6),v(6,6),v(6,4)); | |
printf("%d\n", sat(a,b)); // false | |
a = Polygon(4, v(0,0),v(0,5),v(5,4),v(3,0)); b = Polygon(4, v(4,4),v(4,6),v(6,6),v(6,4)); | |
printf("%d\n", sat(a,b)); // true |
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
a = polygon{v(0,0),v(0,5),v(5,4),v(3,0)} | |
b = polygon{v(4,4),v(4,6),v(6,6),v(6,4)} | |
print(sat(a,b)) -- true |
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
int sat(polygon a, polygon b){ | |
int i; | |
for (i=0;i<a.n;i++){ | |
vec axis = a.edges[i].dir; // Get the direction vector | |
axis = perp(axis); // Get the normal of the vector (90 degrees) | |
float *a_ = project(a,axis), *b_ = project(b,axis); // Find the projection of a and b onto axis | |
if (!overlap(a_,b_)) return 0; // If they do not overlap, then no collision | |
} | |
for (i=0;i<b.n;i++){ // repeat for b |
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
function sat(a, b) | |
for i,v in ipairs(a.edges) do | |
local axis = perp(v) | |
local a_, b_ = project(a, axis), project(b, axis) | |
if not overlap(a_, b_) then return false end | |
end | |
for i,v in ipairs(b.edges) do | |
local axis = perp(v) | |
local a_, b_ = project(a, axis), project(b, axis) | |
if not overlap(a_, b_) then return false end |
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
float* project(polygon a, vec axis){ | |
axis = normalize(axis); | |
int i; | |
float min = dot(a.vertices[0],axis); float max = min; // min and max are the start and finish points | |
for (i=0;i<a.n;i++){ | |
float proj = dot(a.vertices[i],axis); // find the projection of every point on the polygon onto the line. | |
if (proj < min) min = proj; if (proj > max) max = proj; | |
} | |
float* arr = (float*)malloc(2*sizeof(float)); | |
arr[0] = min; arr[1] = max; |
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
-- We keep a running range (min and max) values of the projection, and then use that as our shadow | |
function project(a, axis) | |
axis = normalize(axis) | |
local min = dot(a.vertices[1],axis) | |
local max = min | |
for i,v in ipairs(a.vertices) do | |
local proj = dot(v, axis) -- projection | |
if proj < min then min = proj end | |
if proj > max then max = proj end |