From 2910f5cfd48e1d96732df5261290a83752a74a09 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Wed, 1 Feb 2012 16:36:23 +0000 Subject: [PATCH] [Add] More vector work, added some Length and Distance methods. --- src/libUnuk/System/Vec2.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libUnuk/System/Vec2.cpp b/src/libUnuk/System/Vec2.cpp index edfd04e..cabf65b 100644 --- a/src/libUnuk/System/Vec2.cpp +++ b/src/libUnuk/System/Vec2.cpp @@ -22,3 +22,26 @@ Vec2::Vec2(float value) : x(value), y(value) { Vec2::Vec2(const Vec2i ©) : x(copy.x), y(copy.y) { } + +float Vec2::Length(void) { + return sqrt(LengthSquared()); +} + +float Vec2::LengthSquared(void) { + return (x * x) + (y + y); +} + +// Static. +float Vec2::Distance(const Vec2& value1, const Vec2& value2) { + return Vec2(value1 - value2).Length(); +} + + +// Overload some operators.. +Vec2 Vec2::operator-(void) const { + return Vec2::Zero - *this; +} + +Vec2 Vec2::operator-(const Vec2& v) const { + return Vec2(x - v.x, y - v.y); +}