forked from Source-Python-Dev-Team/Source.Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvecmath_wrap.cpp
More file actions
269 lines (222 loc) · 5.24 KB
/
vecmath_wrap.cpp
File metadata and controls
269 lines (222 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
* =============================================================================
* Source Python
* Copyright (C) 2012 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/
#include "vecmath_wrap.h"
#include "utility/wrap_macros.h"
#include "utility/sp_util.h"
CVector::CVector(float x, float y, float z)
{
m_Vector = Vector(x, y, z);
}
CVector::CVector()
{
m_Vector = Vector();
}
CVector::CVector(Vector vec)
{
m_Vector = vec;
}
CVector::operator Vector()
{
return m_Vector;
}
CVector::operator Vector() const
{
return m_Vector;
}
float CVector::get_x()
{
return m_Vector.x;
}
void CVector::set_x(float fValue)
{
m_Vector.x = fValue;
}
float CVector::get_y()
{
return m_Vector.y;
}
void CVector::set_y(float fValue)
{
m_Vector.y = fValue;
}
float CVector::get_z()
{
return m_Vector.z;
}
void CVector::set_z(float fValue)
{
m_Vector.z = fValue;
}
float CVector::get_item(int iIndex)
{
if (iIndex == 0)
return get_x();
else if (iIndex == 1)
return get_y();
else if (iIndex == 2)
return get_z();
else
BOOST_RAISE_EXCEPTION(PyExc_IndexError, "Index out of range.")
return NULL;
}
void CVector::set_item(int iIndex, float fValue)
{
if (iIndex == 0)
return set_x(fValue);
else if (iIndex == 1)
return set_y(fValue);
else if (iIndex == 2)
return set_z(fValue);
BOOST_RAISE_EXCEPTION(PyExc_IndexError, "Index out of range.")
}
bool CVector::is_valid()
{
return m_Vector.IsValid();
}
void CVector::invalidate()
{
m_Vector.Invalidate();
}
void CVector::random(float fMin, float fMax)
{
m_Vector.Random(fMin, fMax);
}
void CVector::zero()
{
m_Vector.Zero();
}
bool CVector::operator==(CVector* pOther)
{
return m_Vector == *pOther;
}
bool CVector::operator!=(CVector* pOther)
{
return m_Vector != *pOther;
}
CVector* CVector::operator+(object value)
{
if (CheckClassname(value, "CVector"))
{
CVector other = extract<CVector>(value);
return new CVector(m_Vector + other);
}
float fValue = extract<float>(value);
// CS:GO SDK does not define Vector::operator+(float fValue), so we make it easy
// and create a new vector
return new CVector(m_Vector + CVector(fValue, fValue, fValue));
}
CVector* CVector::operator-(object value)
{
if (CheckClassname(value, "CVector"))
{
CVector other = extract<CVector>(value);
return new CVector(m_Vector - other);
}
float fValue = extract<float>(value);
// CS:GO SDK does not define Vector::operator+(float fValue), so we make it easy
// and create a new vector
return new CVector(m_Vector - CVector(fValue, fValue, fValue));
}
CVector* CVector::operator*(object value)
{
if (CheckClassname(value, "CVector"))
{
CVector other = extract<CVector>(value);
return new CVector(m_Vector * other);
}
float fValue = extract<float>(value);
return new CVector(m_Vector * fValue);
}
CVector* CVector::operator/(object value)
{
if (CheckClassname(value, "CVector"))
{
CVector other = extract<CVector>(value);
return new CVector(m_Vector / other);
}
float fValue = extract<float>(value);
return new CVector(m_Vector / fValue);
}
void CVector::negate()
{
m_Vector.Negate();
}
float CVector::get_length()
{
return m_Vector.Length();
}
float CVector::get_length_sqr()
{
return m_Vector.LengthSqr();
}
bool CVector::is_zero(float fTolerance /* = 0.01f */)
{
return m_Vector.IsZero(fTolerance);
}
float CVector::normalize()
{
return m_Vector.NormalizeInPlace();
}
bool CVector::is_within_box(CVector* pMins, CVector* pMaxs)
{
return m_Vector.WithinAABox(*pMins, *pMaxs);
}
float CVector::get_distance(CVector* pOther)
{
return m_Vector.DistTo(*pOther);
}
float CVector::get_distance_sqr(CVector* pOther)
{
return m_Vector.DistToSqr(*pOther);
}
void CVector::mul_add(CVector* pA, CVector* pB, float fScalar)
{
m_Vector.MulAdd(*pA, *pB, fScalar);
}
float CVector::dot(CVector* pOther)
{
return m_Vector.Dot(*pOther);
}
float CVector::get_length_2D()
{
return m_Vector.Length2D();
}
float CVector::get_length_2D_sqr()
{
return m_Vector.Length2DSqr();
}
CVector* CVector::cross(CVector* pOther)
{
return new CVector(m_Vector.Cross(*pOther));
}
CVector* CVector::get_min(CVector* pOther)
{
return new CVector(m_Vector.Min(*pOther));
}
CVector* CVector::get_max(CVector* pOther)
{
return new CVector(m_Vector.Max(*pOther));
}