source: GTP/trunk/Lib/Illum/GPUObscurancesGT/src/VECTOR2D.cpp @ 930

Revision 930, 1.0 KB checked in by igarcia, 18 years ago (diff)
RevLine 
[930]1//////////////////////////////////////////////////////////////////////////////////////////
2//      VECTOR2D.cpp
3//      Function definitions for 2d vector class
4//      You may use this code however you wish, but if you do, please credit me and
5//      provide a link to my website in a readme file or similar
6//      Downloaded from: www.paulsprojects.net
7//      Created:        8th November 2002
8//////////////////////////////////////////////////////////////////////////////////////////     
9
10#include "Maths.h"
11
12void VECTOR2D::Normalize()
13{
14        float length;
15        float scalefactor;
16        length=GetLength();
17
18        if(length==1 || length==0)                      //return if length is 1 or 0
19                return;
20
21        scalefactor = 1.0f/length;
22        x *= scalefactor;
23        y *= scalefactor;
24}
25
26VECTOR2D VECTOR2D::GetNormalized() const
27{
28        VECTOR2D result(*this);
29
30        result.Normalize();
31
32        return result;
33}
34
35VECTOR2D operator*(float scaleFactor, const VECTOR2D & rhs)
36{
37        return rhs*scaleFactor;
38}
39
40bool VECTOR2D::operator==(const VECTOR2D & rhs) const
41{
42        if(x==rhs.x && y==rhs.y)
43                return true;
44
45        return false;
46}
47
48
49
Note: See TracBrowser for help on using the repository browser.