blob: 6621b9e1e352ce87b1c25b928c065aa31a4d3a32 [file] [log] [blame]
Ove Kaavenfddc3e12000-07-23 14:19:19 +00001#ifndef __WINE_D3DVEC_INL
2#define __WINE_D3DVEC_INL
3
4/*** constructors ***/
5
6inline _D3DVECTOR::_D3DVECTOR(D3DVALUE f)
7{
8 x = y = z = f;
9}
10
11inline _D3DVECTOR::_D3DVECTOR(D3DVALUE _x, D3DVALUE _y, D3DVALUE _z)
12{
13 x = _x; y = _y; z = _z;
14}
15
16/*** assignment operators ***/
17
18inline _D3DVECTOR& _D3DVECTOR::operator += (const _D3DVECTOR& v)
19{
20 x += v.x; y += v.y; z += v.z;
21 return *this;
22}
23
24inline _D3DVECTOR& _D3DVECTOR::operator -= (const _D3DVECTOR& v)
25{
26 x -= v.x; y -= v.y; z -= v.z;
27 return *this;
28}
29
30inline _D3DVECTOR& _D3DVECTOR::operator *= (const _D3DVECTOR& v)
31{
32 x *= v.x; y *= v.y; z *= v.z;
33 return *this;
34}
35
36inline _D3DVECTOR& _D3DVECTOR::operator /= (const _D3DVECTOR& v)
37{
38 x /= v.x; y /= v.y; z /= v.z;
39 return *this;
40}
41
42inline _D3DVECTOR& _D3DVECTOR::operator *= (D3DVALUE s)
43{
44 x *= s; y *= s; z *= s;
45 return *this;
46}
47
48inline _D3DVECTOR& _D3DVECTOR::operator /= (D3DVALUE s)
49{
50 x /= s; y /= s; z /= s;
51 return *this;
52}
53
Ove Kaavena9ea8572001-04-16 19:02:22 +000054/*** unary operators ***/
55
56inline _D3DVECTOR operator + (const _D3DVECTOR& v)
57{
58 return v;
59}
60
61inline _D3DVECTOR operator - (const _D3DVECTOR& v)
62{
63 return _D3DVECTOR(-v.x, -v.y, -v.z);
64}
65
Ove Kaavenfddc3e12000-07-23 14:19:19 +000066/*** binary operators ***/
67
68inline _D3DVECTOR operator + (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
69{
70 return _D3DVECTOR(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
71}
72
73inline _D3DVECTOR operator - (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
74{
75 return _D3DVECTOR(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z);
76}
77
78inline _D3DVECTOR operator * (const _D3DVECTOR& v, D3DVALUE s)
79{
80 return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
81}
82
83inline _D3DVECTOR operator * (D3DVALUE s, const _D3DVECTOR& v)
84{
85 return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
86}
87
88inline _D3DVECTOR operator / (const _D3DVECTOR& v, D3DVALUE s)
89{
90 return _D3DVECTOR(v.x/s, v.y/s, v.z/s);
91}
92
93inline D3DVALUE SquareMagnitude(const _D3DVECTOR& v)
94{
95 return v.x*v.x + v.y*v.y + v.z*v.z; /* DotProduct(v, v) */
96}
97
98inline D3DVALUE Magnitude(const _D3DVECTOR& v)
99{
100 return sqrt(SquareMagnitude(v));
101}
102
103inline _D3DVECTOR Normalize(const _D3DVECTOR& v)
104{
105 return v / Magnitude(v);
106}
107
108inline D3DVALUE DotProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
109{
110 return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
111}
112
113inline _D3DVECTOR CrossProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
114{
115 _D3DVECTOR res;
116 /* this is a left-handed cross product, right? */
117 res.x = v1.y * v2.z - v1.z * v2.y;
118 res.y = v1.z * v2.x - v1.x * v2.z;
119 res.z = v1.x * v2.y - v1.y * v2.x;
120 return res;
121}
122
123#endif