Skip to content

Instantly share code, notes, and snippets.

@antonijn
Last active December 22, 2015 22:29
Show Gist options
  • Save antonijn/6539942 to your computer and use it in GitHub Desktop.
Save antonijn/6539942 to your computer and use it in GitHub Desktop.
QLcollision
#include "vecf.h"
#include "rectf.h"
#include "circlef.h"
#include <assert.h>
int rect_collision(rectf_t left, rectf_t right)
{
return (left.x + left.width >= right.x
&& left.x <= right.x + right.width
&& left.y + left.height >= right.y
&& left.y <= right.y + right.height);
}
int circ_collision(circlef_t left, circlef_t right)
{
assert(left.radius >= 0.0f);
assert(right.radius >= 0.0f);
float xdelta = left.pos.x - right.pos.x;
float ydelta = left.pos.y - right.pos.y;
float rsum = left.radius + right.radius;
return (xdelta * xdelta + ydelta * ydelta <= rsum * rsum);
}
int p_circ_collision(vec2f_t point, circlef_t circle)
{
float xdelta = (point.x - circle.x);
float ydelta = (point.y - circle.y);
return (xdelta * xdelta + ydelta * ydelta <= circle.radius * circle.radius);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment