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

Revision 930, 2.0 KB checked in by igarcia, 18 years ago (diff)
RevLine 
[930]1//////////////////////////////////////////////////////////////////////////////////////////
2//      VECTOR4D.cpp
3//      Function definitions for 4d 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:        20th July 2002
8//      Modified:       15th August 2002        -       prevent divide by zero in operator VECTOR3D()
9//      Modified:       8th November 2002       -       Changed Constructor layout
10//                                                                      -       Some speed Improvements
11//                                                                      -       Corrected Lerp
12//////////////////////////////////////////////////////////////////////////////////////////     
13
14#include "Maths.h"
15
16void VECTOR4D::RotateX(double angle)
17{
18        (*this)=GetRotatedX(angle);
19}
20
21VECTOR4D VECTOR4D::GetRotatedX(double angle) const
22{
23        VECTOR3D v3d(x, y, z);
24
25        v3d.RotateX(angle);
26
27        return VECTOR4D(v3d.x, v3d.y, v3d.z, w);
28}
29
30void VECTOR4D::RotateY(double angle)
31{
32        (*this)=GetRotatedY(angle);
33}
34
35VECTOR4D VECTOR4D::GetRotatedY(double angle) const
36{
37        VECTOR3D v3d(x, y, z);
38
39        v3d.RotateY(angle);
40
41        return VECTOR4D(v3d.x, v3d.y, v3d.z, w);
42}
43
44void VECTOR4D::RotateZ(double angle)
45{
46        (*this)=GetRotatedZ(angle);
47}
48
49VECTOR4D VECTOR4D::GetRotatedZ(double angle) const
50{
51        VECTOR3D v3d(x, y, z);
52
53        v3d.RotateZ(angle);
54
55        return VECTOR4D(v3d.x, v3d.y, v3d.z, w);
56}
57
58void VECTOR4D::RotateAxis(double angle, const VECTOR3D & axis)
59{
60        (*this)=GetRotatedAxis(angle, axis);
61}
62
63VECTOR4D VECTOR4D::GetRotatedAxis(double angle, const VECTOR3D & axis) const
64{
65        VECTOR3D v3d(x, y, z);
66
67        v3d.RotateAxis(angle, axis);
68
69        return VECTOR4D(v3d.x, v3d.y, v3d.z, w);
70}
71
72
73VECTOR4D operator*(float scaleFactor, const VECTOR4D & rhs)
74{
75        return rhs*scaleFactor;
76}
77
78bool VECTOR4D::operator==(const VECTOR4D & rhs) const
79{
80        if(x==rhs.x && y==rhs.y && z==rhs.z && w==rhs.w)
81                return true;
82
83        return false;
84}
85
86VECTOR4D::operator VECTOR3D()
87{
88        if(w==0.0f || w==1.0f)
89                return VECTOR3D(x, y, z);
90        else
91                return VECTOR3D(x/w, y/w, z/w);
92}
Note: See TracBrowser for help on using the repository browser.