2 #include "oxygine-include.h" 3 #include "ScalarMath.h" 25 void set(T x_, T y_) {x = x_; y = y_;}
26 void setZero() {x = 0; y = 0;}
29 VectorT2 operator * (R s)
const {
VectorT2 r(*
this); r.x = type(r.x * s); r.y = type(r.y * s);
return r;}
31 VectorT2 operator / (R s)
const {
VectorT2 r(*
this); r.x /= s; r.y /= s;
return r;}
34 VectorT2 operator *= (R s) {x *= s; y *= s;
return (*
this);}
36 VectorT2 operator /= (R s) {x /= s; y /= s;
return (*
this);}
41 operator VectorT2<float> ()
const {
return this->cast< VectorT2<float> >();}
47 typedef typename R::type vec2type;
48 return vec2(vec2type(x), vec2type(y));
52 bool operator == (
const VectorT2& r)
const;
53 bool operator != (
const VectorT2& r)
const;
58 T length()
const {
return (T)scalar::sqrt(x * x + y * y);}
59 T sqlength()
const {
return dot(*
this);}
61 void normalize() { normalize(*
this, *
this); }
62 void normalizeTo(T len) { normalize(); *
this *= len; }
65 float distance(
const VectorT2& v)
const {
return VectorT2(x - v.x, y - v.y).length();}
66 T dot(
const VectorT2& vr)
const {
return dot(*
this, vr);}
88 if (x == r.x && y == r.y)
94 bool VectorT2<T>::operator != (
const VectorT2<T>& r)
const 96 if (x != r.x || y != r.y)
102 VectorT2<T>::VectorT2(): x(0), y(0)
106 VectorT2<T>::VectorT2(T X, T Y):
112 VectorT2<T>& VectorT2<T>::operator+=(
const VectorT2& v)
114 x += v.x; y += v.y;
return (*
this);
118 VectorT2<T>& VectorT2<T>::operator-=(
const VectorT2& v)
120 x -= v.x; y -= v.y;
return (*
this);
124 VectorT2<T> VectorT2<T>::operator + (
const VectorT2& v)
const 126 return VectorT2(x + v.x, y + v.y);
130 VectorT2<T> VectorT2<T>::operator - (
const VectorT2& v)
const 132 return VectorT2(x - v.x, y - v.y);
136 VectorT2<T> VectorT2<T>::operator - ()
const 138 return VectorT2<T>(-x, -y);
142 inline T VectorT2<T>::dot(
const VectorT2& v1,
const VectorT2& v2)
144 return v1.x * v2.x + v1.y * v2.y;
148 inline VectorT2<T>& VectorT2<T>::normalize(VectorT2<T>& out,
const VectorT2<T>& v)
150 T norm = T(1.0) / scalar::sqrt(v.x * v.x + v.y * v.y);
165 typedef VectorT2<float> Vector2;
166 typedef VectorT2<double> VectorD2;
167 typedef VectorT2<int> Point;
168 typedef VectorT2<short> PointS;
–oxgl-end–!
Definition: Actor.h:14