Skip to content

Instantly share code, notes, and snippets.

@FeepingCreature
Created July 10, 2012 11:53
Show Gist options
  • Save FeepingCreature/3082877 to your computer and use it in GitHub Desktop.
Save FeepingCreature/3082877 to your computer and use it in GitHub Desktop.
WorldObject[auto~] inRect(vec2f a, b) {
auto world-center = vec3f(0), world-radius = 1;
auto center = cam.apply(world-center).xy;
float radius;
using glModelviewMatrix {
cam.unrotate;
auto offset = cam.apply(world-center + world-radius * vec3f.X).xy - center;
radius = |offset|;
}
auto aspect = vec2f(1, 1/cam.aspect);
if (overlaps_rect_circle(a*aspect, b*aspect, center*aspect, radius)) {
WorldObject[auto~] res; res ~= this; return res;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment