source: Daodan/MSYS2/mingw32/i686-w64-mingw32/include/d3dvec.inl

Last change on this file was 1166, checked in by rossy, 3 years ago

Daodan: Replace MinGW build env with an up-to-date MSYS2 env

File size: 3.2 KB
RevLine 
[1166]1/*
2 * Copyright (C) 2000 Ove Kaaven
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef __WINE_D3DVEC_INL
20#define __WINE_D3DVEC_INL
21
22#include <math.h>
23
24/*** constructors ***/
25
26inline _D3DVECTOR::_D3DVECTOR(D3DVALUE f)
27{
28 x = y = z = f;
29}
30
31inline _D3DVECTOR::_D3DVECTOR(D3DVALUE _x, D3DVALUE _y, D3DVALUE _z)
32{
33 x = _x; y = _y; z = _z;
34}
35
36/*** assignment operators ***/
37
38inline _D3DVECTOR& _D3DVECTOR::operator += (const _D3DVECTOR& v)
39{
40 x += v.x; y += v.y; z += v.z;
41 return *this;
42}
43
44inline _D3DVECTOR& _D3DVECTOR::operator -= (const _D3DVECTOR& v)
45{
46 x -= v.x; y -= v.y; z -= v.z;
47 return *this;
48}
49
50inline _D3DVECTOR& _D3DVECTOR::operator *= (const _D3DVECTOR& v)
51{
52 x *= v.x; y *= v.y; z *= v.z;
53 return *this;
54}
55
56inline _D3DVECTOR& _D3DVECTOR::operator /= (const _D3DVECTOR& v)
57{
58 x /= v.x; y /= v.y; z /= v.z;
59 return *this;
60}
61
62inline _D3DVECTOR& _D3DVECTOR::operator *= (D3DVALUE s)
63{
64 x *= s; y *= s; z *= s;
65 return *this;
66}
67
68inline _D3DVECTOR& _D3DVECTOR::operator /= (D3DVALUE s)
69{
70 x /= s; y /= s; z /= s;
71 return *this;
72}
73
74/*** unary operators ***/
75
76inline _D3DVECTOR operator + (const _D3DVECTOR& v)
77{
78 return v;
79}
80
81inline _D3DVECTOR operator - (const _D3DVECTOR& v)
82{
83 return _D3DVECTOR(-v.x, -v.y, -v.z);
84}
85
86/*** binary operators ***/
87
88inline _D3DVECTOR operator + (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
89{
90 return _D3DVECTOR(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
91}
92
93inline _D3DVECTOR operator - (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
94{
95 return _D3DVECTOR(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z);
96}
97
98inline _D3DVECTOR operator * (const _D3DVECTOR& v, D3DVALUE s)
99{
100 return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
101}
102
103inline _D3DVECTOR operator * (D3DVALUE s, const _D3DVECTOR& v)
104{
105 return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
106}
107
108inline _D3DVECTOR operator / (const _D3DVECTOR& v, D3DVALUE s)
109{
110 return _D3DVECTOR(v.x/s, v.y/s, v.z/s);
111}
112
113inline D3DVALUE SquareMagnitude(const _D3DVECTOR& v)
114{
115 return v.x*v.x + v.y*v.y + v.z*v.z; /* DotProduct(v, v) */
116}
117
118inline D3DVALUE Magnitude(const _D3DVECTOR& v)
119{
120 return sqrt(SquareMagnitude(v));
121}
122
123inline _D3DVECTOR Normalize(const _D3DVECTOR& v)
124{
125 return v / Magnitude(v);
126}
127
128inline D3DVALUE DotProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
129{
130 return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
131}
132
133inline _D3DVECTOR CrossProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
134{
135 _D3DVECTOR res;
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;
140 return res;
141}
142
143#endif
Note: See TracBrowser for help on using the repository browser.