aboutsummaryrefslogtreecommitdiff
path: root/libcgh.h
diff options
context:
space:
mode:
authorGravatar chirs241097@gmail.com <chirs241097@gmail.com@c17bf020-1265-9734-9302-a83f62007ddb> 2014-03-03 08:52:12 +0000
committerGravatar chirs241097@gmail.com <chirs241097@gmail.com@c17bf020-1265-9734-9302-a83f62007ddb> 2014-03-03 08:52:12 +0000
commita404f537e1f260040063b65461213800c896e15c (patch)
tree82ca588fb7694d20e34732000dd3f0beb2b12c9c /libcgh.h
parenteaa6a19cd0537c0bb8d57d743f894f58c62d378a (diff)
downloadbullet-lab-remix-a404f537e1f260040063b65461213800c896e15c.tar.xz
New levels and laser rewrite. Bring back a level and remove all commented levels.
Diffstat (limited to 'libcgh.h')
-rw-r--r--libcgh.h24
1 files changed, 23 insertions, 1 deletions
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 <hge.h>
#include <hgefont.h>
@@ -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;