2 * Copyright (C) 2000 Ove Kaaven
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef __WINE_D3DVEC_INL
20 #define __WINE_D3DVEC_INL
24 /*** constructors ***/
26 inline _D3DVECTOR::_D3DVECTOR(D3DVALUE f)
31 inline _D3DVECTOR::_D3DVECTOR(D3DVALUE _x, D3DVALUE _y, D3DVALUE _z)
33 x = _x; y = _y; z = _z;
36 /*** assignment operators ***/
38 inline _D3DVECTOR& _D3DVECTOR::operator += (const _D3DVECTOR& v)
40 x += v.x; y += v.y; z += v.z;
44 inline _D3DVECTOR& _D3DVECTOR::operator -= (const _D3DVECTOR& v)
46 x -= v.x; y -= v.y; z -= v.z;
50 inline _D3DVECTOR& _D3DVECTOR::operator *= (const _D3DVECTOR& v)
52 x *= v.x; y *= v.y; z *= v.z;
56 inline _D3DVECTOR& _D3DVECTOR::operator /= (const _D3DVECTOR& v)
58 x /= v.x; y /= v.y; z /= v.z;
62 inline _D3DVECTOR& _D3DVECTOR::operator *= (D3DVALUE s)
64 x *= s; y *= s; z *= s;
68 inline _D3DVECTOR& _D3DVECTOR::operator /= (D3DVALUE s)
70 x /= s; y /= s; z /= s;
74 /*** unary operators ***/
76 inline _D3DVECTOR operator + (const _D3DVECTOR& v)
81 inline _D3DVECTOR operator - (const _D3DVECTOR& v)
83 return _D3DVECTOR(-v.x, -v.y, -v.z);
86 /*** binary operators ***/
88 inline _D3DVECTOR operator + (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
90 return _D3DVECTOR(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
93 inline _D3DVECTOR operator - (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
95 return _D3DVECTOR(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z);
98 inline _D3DVECTOR operator * (const _D3DVECTOR& v, D3DVALUE s)
100 return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
103 inline _D3DVECTOR operator * (D3DVALUE s, const _D3DVECTOR& v)
105 return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
108 inline _D3DVECTOR operator / (const _D3DVECTOR& v, D3DVALUE s)
110 return _D3DVECTOR(v.x/s, v.y/s, v.z/s);
113 inline D3DVALUE SquareMagnitude(const _D3DVECTOR& v)
115 return v.x*v.x + v.y*v.y + v.z*v.z; /* DotProduct(v, v) */
118 inline D3DVALUE Magnitude(const _D3DVECTOR& v)
120 return sqrt(SquareMagnitude(v));
123 inline _D3DVECTOR Normalize(const _D3DVECTOR& v)
125 return v / Magnitude(v);
128 inline D3DVALUE DotProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
130 return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
133 inline _D3DVECTOR CrossProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
136 /* this is a left-handed cross product, right? */
137 res.x = v1.y * v2.z - v1.z * v2.y;
138 res.y = v1.z * v2.x - v1.x * v2.z;
139 res.z = v1.x * v2.y - v1.y * v2.x;