From a404f537e1f260040063b65461213800c896e15c Mon Sep 17 00:00:00 2001 From: "chirs241097@gmail.com" Date: Mon, 3 Mar 2014 08:52:12 +0000 Subject: New levels and laser rewrite. Bring back a level and remove all commented levels. --- libcgh.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'libcgh.h') diff --git a/libcgh.h b/libcgh.h index 54c1209..15a6979 100644 --- a/libcgh.h +++ b/libcgh.h @@ -1,7 +1,7 @@ //Chrisoft Bullet Lab Remix HGE //Chrisoft Game Helper header //Copyright Chrisoft 2014 -//libcgh version 0003 +//libcgh version 0004 //^Modify that when big change is made^ #include #include @@ -33,6 +33,18 @@ struct vector2d { return vector2d(a.x+b.x,a.y+b.y); } + friend double operator |(vector2d a,vector2d b)//dot product + { + return a.x*b.x+a.y*b.y; + } + friend double operator *(vector2d a,vector2d b)//length of cross product + { + return a.x*b.y-b.x*a.y; + } + friend vector2d operator *(double a,vector2d b) + { + return vector2d(b.x*a,b.y*a); + } }; inline vector2d ToUnitCircle(vector2d input) { @@ -45,6 +57,16 @@ inline double GetDist(const vector2d a,const vector2d b) { return sqrtf((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } +inline double GetDistSeg(const vector2d a,const vector2d b,const vector2d c) +{ + double l2=GetDist(a,b)*GetDist(a,b); + if (l2==0.0)return GetDist(c,a); + double t=((c-a)|(b-a))/l2; + if (t<0)return GetDist(c,a); + else if (t>1)return GetDist(c,b); + vector2d projection=a+t*(b-a); + return GetDist(c,projection); +} inline double normalizerad(double a) { while (a<0)a+=2*pi; -- cgit v1.2.3