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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __WINE_D3DVEC_INL
20 #define __WINE_D3DVEC_INL
22 /*** constructors ***/
24 inline _D3DVECTOR::_D3DVECTOR(D3DVALUE f)
29 inline _D3DVECTOR::_D3DVECTOR(D3DVALUE _x, D3DVALUE _y, D3DVALUE _z)
31 x = _x; y = _y; z = _z;
34 /*** assignment operators ***/
36 inline _D3DVECTOR& _D3DVECTOR::operator += (const _D3DVECTOR& v)
38 x += v.x; y += v.y; z += v.z;
42 inline _D3DVECTOR& _D3DVECTOR::operator -= (const _D3DVECTOR& v)
44 x -= v.x; y -= v.y; z -= v.z;
48 inline _D3DVECTOR& _D3DVECTOR::operator *= (const _D3DVECTOR& v)
50 x *= v.x; y *= v.y; z *= v.z;
54 inline _D3DVECTOR& _D3DVECTOR::operator /= (const _D3DVECTOR& v)
56 x /= v.x; y /= v.y; z /= v.z;
60 inline _D3DVECTOR& _D3DVECTOR::operator *= (D3DVALUE s)
62 x *= s; y *= s; z *= s;
66 inline _D3DVECTOR& _D3DVECTOR::operator /= (D3DVALUE s)
68 x /= s; y /= s; z /= s;
72 /*** unary operators ***/
74 inline _D3DVECTOR operator + (const _D3DVECTOR& v)
79 inline _D3DVECTOR operator - (const _D3DVECTOR& v)
81 return _D3DVECTOR(-v.x, -v.y, -v.z);
84 /*** binary operators ***/
86 inline _D3DVECTOR operator + (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
88 return _D3DVECTOR(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
91 inline _D3DVECTOR operator - (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
93 return _D3DVECTOR(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z);
96 inline _D3DVECTOR operator * (const _D3DVECTOR& v, D3DVALUE s)
98 return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
101 inline _D3DVECTOR operator * (D3DVALUE s, const _D3DVECTOR& v)
103 return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
106 inline _D3DVECTOR operator / (const _D3DVECTOR& v, D3DVALUE s)
108 return _D3DVECTOR(v.x/s, v.y/s, v.z/s);
111 inline D3DVALUE SquareMagnitude(const _D3DVECTOR& v)
113 return v.x*v.x + v.y*v.y + v.z*v.z; /* DotProduct(v, v) */
116 inline D3DVALUE Magnitude(const _D3DVECTOR& v)
118 return sqrt(SquareMagnitude(v));
121 inline _D3DVECTOR Normalize(const _D3DVECTOR& v)
123 return v / Magnitude(v);
126 inline D3DVALUE DotProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
128 return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
131 inline _D3DVECTOR CrossProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
134 /* this is a left-handed cross product, right? */
135 res.x = v1.y * v2.z - v1.z * v2.y;
136 res.y = v1.z * v2.x - v1.x * v2.z;
137 res.z = v1.x * v2.y - v1.y * v2.x;