; **************************************************************************** ; * By PBFrance : http://www.pbfrance.com/?url=source&cmd=viewer&val=6 ; **************************************************************************** ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// Procedure.f min(a.f,b.f) If ab ProcedureReturn a EndIf ProcedureReturn b EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// Structure sVector2f x.f y.f EndStructure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL.i createVector2f(x.f, y.f) *v.sVector2f = AllocateMemory(SizeOf(sVector2f)) If *v *vx = x *vy = y ProcedureReturn *v EndIf EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL deleteVector2f(*v.sVector2f) If *v *vx = #Null *vy = #Null FreeMemory(*v) EndIf EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL addVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f) *resultx = *ax + *bx *resulty = *ay + *by EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL subVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f) *resultx = *ax - *bx *resulty = *ay - *by EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL mulVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f) *resultx = *ax * *bx *resulty = *ay * *by EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL divVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f) If *bx <> 0 *resultx = *ax / *bx EndIf If *by <> 0 *resulty = *ay / *by EndIf EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL scaleVector2f(*a.sVector2f, value.f) *ax * value *ay * value EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL.f squareLengthVector2f(*v.sVector2f) ProcedureReturn (*vx * *vx) + (*vy * *vy) EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL.f lengthVector2f(*v.sVector2f) ProcedureReturn Sqr((*vx * *vx) + (*vy * *vy)) EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL.f dotProductVector2f(*a.sVector2f, *b.sVector2f) ProcedureReturn (*ax * *bx) + (*ay * *by) EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL normalizeVector2f(*v.sVector2f) l.f = Sqr((*vx * *vx) + (*vy * *vy)) If l > 0 *vx / l *vy / l EndIf EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL middlePointVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f) *resultx = (*ax + *bx) * 0.5 *resulty = (*ay + *by) * 0.5 EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL lerpVector2f(*result.sVector2f, *a.sVector2f, *b.sVector2f, val.f) *resultx = *ax + (*bx - *ax) * val *resulty = *ay + (*by - *ay) * val EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL.f crossProductVector2f(*a.sVector2f, *b.sVector2f) ProcedureReturn *ax * *by - *ay * *bx EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL randomDeviantVector2f(*v.sVector2f, angle.f) angle = angle * Random(angle) * (#PI*2) cosa.f = Cos(angle) sina.f = Cos(angle) *vx = cosa * *vx - sina - *vy *vy = sina * *vx + cosa * *vy EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL perpendicularVector2f(*v.sVector2f) Protected x.f = *vx Protected y.f = *vy *vx = -y *vy = x EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL reflectVector2f(*v.sVector2f, *normal.sVector2f) Protected dot.f = (*vx * *normalx) + (*vy * *normaly) *vx = *vx - ( 2 * dot * *normalx ) *vy = *vy - ( 2 * dot * *normaly ) EndProcedure ;////////////////////////////////////////////////////////////////////////////// ;// ;////////////////////////////////////////////////////////////////////////////// ProcedureDLL.i intersectVector2f(*p1.sVector2f,*p2.sVector2f,*p3.sVector2f,*p4.sVector2f) Protected.f x1 = *p1x, x2 = *p2x, x3 = *p3x, x4 = *p4x; Protected.f y1 = *p1y, y2 = *p2y, y3 = *p3y, y4 = *p4y; Protected.d d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4) If d = 0 ProcedureReturn #Null EndIf Protected.f pre = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4) Protected.f x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d Protected.f y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d If ( x < min(x1, x2) Or x > max(x1, x2) Or x < min(x3, x4) Or x > max(x3, x4) ) ProcedureReturn #Null EndIf If ( y < min(y1, y2) Or y > max(y1, y2) Or y < min(y3, y4) Or y > max(y3, y4) ) ProcedureReturn #Null EndIf ProcedureReturn createVector2f(x,y) EndProcedure