FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Source.Python/src/core/modules/mathlib/mathlib.h at Data-Update · srpg/Source.Python · GitHub
srpg
Source.Python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Source.Python
/
src
/
core
/
modules
/
mathlib
/
mathlib.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
200 lines (169 loc) · 5.02 KB
Breadcrumbs
Source.Python
/
src
/
core
/
modules
/
mathlib
/
mathlib.h
Copy path
File metadata and controls
executable file
·
200 lines (169 loc) · 5.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
*
* =============================================================================
* Source Python
* Copyright (C) 2012-2015 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.
*/
#
ifndef
_MATHLIB_H
#
define
_MATHLIB_H
//
-----------------------------------------------------------------------------
//
Includes.
//
-----------------------------------------------------------------------------
#
include
"
mathlib/vector.h
"
//
-----------------------------------------------------------------------------
//
Vector extension class.
//
-----------------------------------------------------------------------------
class
VectorExt
{
public:
static
bool
IsWithinBox
(Vector& point, Vector& corner1, Vector& corner2)
{
return
point.
WithinAABox
(corner1.
Min
(corner2), corner2.
Max
(corner1));
}
static
void
SetLength
(Vector& vec,
float
fLength
)
{
vec.
NormalizeInPlace
();
vec *=
fLength
;
}
static
inline
float
GetLength
(Vector& vec)
{
//
Workaround for https://github.com/Source-Python-Dev-Team/Source.Python/issues/150
#
ifdef
__linux__
return
sqrt
(vec.
LengthSqr
());
#
else
return
vec.
Length
();
#
endif
}
static
inline
float
GetLength2D
(Vector& vec)
{
//
Workaround for https://github.com/Source-Python-Dev-Team/Source.Python/issues/150
#
ifdef
__linux__
return
sqrt
(vec.
Length2DSqr
());
#
else
return
vec.
Length2D
();
#
endif
}
static
str
__repr__
(Vector* pVector)
{
return
str
(
"
Vector
"
+
str
(
tuple
(pVector))); }
static
Vector
Copy
(Vector* pVec)
{
return
*pVec; }
static
Vector
Normalized
(Vector* pVec)
{
Vector copy = *pVec;
copy.
NormalizeInPlace
();
return
copy;
}
static
inline
Vector
__add__
(Vector vecCopy,
float
val)
{
vecCopy += val;
return
vecCopy;
}
static
inline
Vector
__sub__
(Vector vecCopy,
float
val)
{
vecCopy -= val;
return
vecCopy;
}
static
inline
Vector
__neg__
(Vector vecCopy)
{
vecCopy.
Negate
();
return
vecCopy;
}
};
//
-----------------------------------------------------------------------------
//
QAngle extension class.
//
-----------------------------------------------------------------------------
class
QAngleExt
{
public:
static
str
__repr__
(QAngle* pQAngle)
{
return
str
(
"
QAngle
"
+
str
(
tuple
(pQAngle))); }
};
//
-----------------------------------------------------------------------------
//
Quaternion extension class.
//
-----------------------------------------------------------------------------
class
QuaternionExt
{
public:
static
str
__repr__
(Quaternion* pQuaternion)
{
return
str
(
"
Quaternion
"
+
str
(
tuple
(pQuaternion))); }
};
//
-----------------------------------------------------------------------------
//
RadianEuler extension class.
//
-----------------------------------------------------------------------------
class
RadianEulerExt
{
public:
static
str
__repr__
(RadianEuler* pRadianEuler)
{
return
str
(
"
RadianEuler
"
+
str
(
tuple
(pRadianEuler))); }
};
//
-----------------------------------------------------------------------------
//
matrix3x4_t extension class.
//
-----------------------------------------------------------------------------
class
Matrix3x4Row
{
public:
Matrix3x4Row
(
float
* row)
{
m_row = row;
}
float
&
operator
[](
unsigned
int
index)
{
return
m_row[index];
}
str
__repr__
()
{
return
str
(
tuple
(*
this
));
}
public:
float
* m_row;
};
class
matrix3x4_tExt
{
public:
static
Matrix3x4Row*
__getitem__
(
matrix3x4_t
& matrix,
unsigned
int
index)
{
if
(index >=
3
) {
BOOST_RAISE_EXCEPTION
(PyExc_IndexError,
"
Index out of range (%d)
"
, index)
}
return
new
Matrix3x4Row
(matrix[index]);
}
static
str
__repr__
(
matrix3x4_t
& matrix)
{
return
str
(
"
[
"
+
str
(
__getitem__
(matrix,
0
)) +
"
,
\n
"
+
str
(
__getitem__
(matrix,
1
)) +
"
,
\n
"
+
str
(
__getitem__
(matrix,
2
)) +
"
]
"
);
}
static
Vector*
get_position
(
matrix3x4_t
& matrix)
{
Vector* result =
new
Vector
();
MatrixPosition
(matrix, *result);
return
result;
}
static
QAngle*
get_angles
(
matrix3x4_t
& matrix)
{
QAngle* result =
new
QAngle
();
MatrixAngles
(matrix, *result);
return
result;
}
};
#
endif
//
_MATHLIB_H
Back
|
FazBrowse Home
|
New Git URL