1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | #ifndef VRVECTOR4F_H |
---|
3 | #define VRVECTOR4F_H |
---|
4 | |
---|
5 | #include <vrmath/Vector3f.h> |
---|
6 | #include <vrmath/Vector4f.h> |
---|
7 | |
---|
8 | class vrMatrix4x4f; |
---|
9 | |
---|
10 | class vrVector4f |
---|
11 | { |
---|
12 | public: |
---|
13 | vrVector4f() : |
---|
14 | x(0.0f), y(0.0f), z(0.0f), w(0.0f) |
---|
15 | {} |
---|
16 | |
---|
17 | vrVector4f(const vrVector4f& v4) : |
---|
18 | x(v4.x), y(v4.y), z(v4.z), w(v4.w) |
---|
19 | {} |
---|
20 | |
---|
21 | vrVector4f(const vrVector3f& v3, float w1) : |
---|
22 | x(v3.x), y(v3.y), z(v3.z), w(w1) |
---|
23 | {} |
---|
24 | |
---|
25 | vrVector4f(float x1, float y1, float z1, float w1) : |
---|
26 | x(x1), y(y1), z(z1), w(w1) |
---|
27 | {} |
---|
28 | |
---|
29 | void set(float x1, float y1, float z1, float w1); |
---|
30 | |
---|
31 | void set(const vrVector3f& v, float w); |
---|
32 | |
---|
33 | void set(const vrVector4f& v4); |
---|
34 | |
---|
35 | void divideByW(); |
---|
36 | |
---|
37 | float dot(const vrVector4f& vec); |
---|
38 | |
---|
39 | void mult(const vrMatrix4x4f& mat, const vrVector4f& vec); |
---|
40 | |
---|
41 | void mult(const vrMatrix4x4f& mat); |
---|
42 | |
---|
43 | void transform(const vrVector4f& v, const vrMatrix4x4f& m); |
---|
44 | |
---|
45 | float x, y, z, w; |
---|
46 | }; |
---|
47 | |
---|
48 | inline void vrVector4f::divideByW() |
---|
49 | { |
---|
50 | if (w != 0) { |
---|
51 | x /= w; y /= w; z /= w; |
---|
52 | w = 1.0f; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | inline void vrVector4f::set(float x1, float y1, float z1, float w1) |
---|
57 | { |
---|
58 | x = x1; |
---|
59 | y = y1; |
---|
60 | z = z1; |
---|
61 | w = w1; |
---|
62 | } |
---|
63 | |
---|
64 | inline void vrVector4f::set(const vrVector4f& v4) |
---|
65 | { |
---|
66 | x = v4.x; |
---|
67 | y = v4.y; |
---|
68 | z = v4.z; |
---|
69 | w = v4.w; |
---|
70 | } |
---|
71 | |
---|
72 | inline void vrVector4f::set(const vrVector3f& v, float w1) |
---|
73 | { |
---|
74 | x = v.x; |
---|
75 | y = v.y; |
---|
76 | z = v.z; |
---|
77 | w = w1; |
---|
78 | } |
---|
79 | |
---|
80 | inline float vrVector4f::dot(const vrVector4f& vec) |
---|
81 | { |
---|
82 | return x * vec.x + y * vec.y + z * vec.z + w * vec.w; |
---|
83 | } |
---|
84 | |
---|
85 | #endif |
---|