This is a header and library I use in a lot of my games. It used to be larger, but I have cut it down over a few months to the tasks I use the most.
point.h
point.cCode:typedef struct point_ {float x, y;} point; typedef struct vector_ {float th, r;} vector; vector mkvec(float th, float r); point mkpnt(float x, float y); vector pnt2vec(point p); point vec2pnt(vector v); point pntadd(point p, point q); point pntsub(point p, point q); extern point pnt_z;
Code:#include "point.h" #include "math.h" vector mkvec(float th, float r){ vector v; v.th = th; v.r = r; return v; } point mkpnt(float x, float y){ point p; p.x = x; p.y = y; return p; } vector pnt2vec(point p){ return mkvec(atan2(p.y, p.x), sqrt(p.x * p.x + p.y * p.y)); } point vec2pnt(vector v){ return mkpnt(v.r * cos(v.th), v.r * sin(v.th)); } point pntadd(point p, point q){ p.x += q.x; p.y += q.y; return p; } point pntsub(point p, point q){ p.x -= q.x; p.y -= q.y; return p; } point pnt_z = {0.0,0.0};
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks