1 // This may look like C code, but it's really -*- C++ -*-
2 /*
3 * Copyright (C) 2014 Emweb bv, Herent, Belgium.
4 *
5 * See the LICENSE file for terms of use.
6 */
7
8 #include "Wt/WVector4.h"
9
10 #include <cmath>
11
12 using namespace Wt;
13
WVector4()14 WVector4::WVector4()
15 {
16 (*this)(0, 0) = 0;
17 (*this)(1, 0) = 0;
18 (*this)(2, 0) = 0;
19 (*this)(3, 0) = 1;
20 }
21
WVector4(double * d)22 WVector4::WVector4(double *d)
23 : WGenericMatrix<double, 4, 1>(d)
24 {}
25
WVector4(double x,double y,double z,double w)26 WVector4::WVector4(double x, double y, double z, double w)
27 {
28 (*this)(0, 0) = x;
29 (*this)(1, 0) = y;
30 (*this)(2, 0) = z;
31 (*this)(3, 0) = w;
32 }
33
WVector4(const WVector4 & other)34 WVector4::WVector4(const WVector4 &other)
35 : WGenericMatrix<double, 4, 1>(other)
36 {}
37
WVector4(const WGenericMatrix<double,4,1> & other)38 WVector4::WVector4(const WGenericMatrix<double, 4, 1> &other)
39 : WGenericMatrix<double, 4, 1>(other)
40 {}
41
x()42 const double &WVector4::x() const
43 {
44 return (*this)(0, 0);
45 }
46
y()47 const double &WVector4::y() const
48 {
49 return (*this)(1, 0);
50 }
51
z()52 const double &WVector4::z() const
53 {
54 return (*this)(2, 0);
55 }
56
w()57 const double &WVector4::w() const
58 {
59 return (*this)(3, 0);
60 }
61
x()62 double &WVector4::x()
63 {
64 return (*this)(0, 0);
65 }
66
y()67 double &WVector4::y()
68 {
69 return (*this)(1, 0);
70 }
71
z()72 double &WVector4::z()
73 {
74 return (*this)(2, 0);
75 }
76
w()77 double &WVector4::w()
78 {
79 return (*this)(3, 0);
80 }
81
normalize()82 WVector4 WVector4::normalize() const
83 {
84 double norm = length();
85 return WVector4(x() / norm, y() / norm, z() / norm, w() / norm);
86 }
87
length()88 double WVector4::length() const
89 {
90 // If this is a point, it does not make much sense.
91 return std::sqrt(x() * x() + y() * y() + z() * z() + w() * w());
92 }
93