2929// -----------------------------------------------------------------------------
3030#include " modules/export_main.h"
3131#include " mathlib/vector.h"
32+ #include " mathlib/mathlib.h"
33+ #include " utility/sp_util.h"
3234
3335
3436// -----------------------------------------------------------------------------
3537// Exposes the mathlib_c module.
3638// -----------------------------------------------------------------------------
3739void export_vector ();
40+ void export_qangle ();
41+ void export_quaternion ();
42+ void export_cplane_t ();
3843
3944DECLARE_SP_MODULE (mathlib_c)
4045{
4146 export_vector ();
47+ export_qangle ();
48+ export_quaternion ();
49+ export_cplane_t ();
4250}
4351
4452// -----------------------------------------------------------------------------
@@ -47,11 +55,6 @@ DECLARE_SP_MODULE(mathlib_c)
4755class VectorExt
4856{
4957public:
50- static void SetItem (Vector pVec, int iIndex, float fValue )
51- {
52- pVec[iIndex] = fValue ;
53- }
54-
5558 static Vector* CreateNullVector ()
5659 {
5760 return new Vector (0 , 0 , 0 );
@@ -98,7 +101,7 @@ void export_vector()
98101 )
99102
100103 .def (" __setitem__" ,
101- &VectorExt::SetItem
104+ &SetItemIndexer<Vector, float >
102105 )
103106
104107 .def (" as_vector_2D" ,
@@ -225,4 +228,201 @@ void export_vector()
225228 " Returns a new vector containing the biggest values of both vectors."
226229 )
227230 ;
231+ }
232+
233+ // -----------------------------------------------------------------------------
234+ // Exposes QAngle
235+ // -----------------------------------------------------------------------------
236+ void export_qangle ()
237+ {
238+ // TODO: Documentation
239+ class_<QAngle>(" QAngle" )
240+ .def (init<float , float , float >())
241+
242+ .def_readwrite (" x" ,
243+ &QAngle::x
244+ )
245+
246+ .def_readwrite (" y" ,
247+ &QAngle::y
248+ )
249+
250+ .def_readwrite (" z" ,
251+ &QAngle::z
252+ )
253+
254+ .def (" init" ,
255+ &QAngle::Init,
256+ " Initializes the QAngle instance with the given values." ,
257+ args (" x" , " y" , " z" )
258+ )
259+
260+ .def (" random" ,
261+ &QAngle::Random
262+ )
263+
264+ .def (" is_valid" ,
265+ &QAngle::IsValid
266+ )
267+
268+ .def (" invalidate" ,
269+ &QAngle::Invalidate
270+ )
271+
272+ .def (" __getitem__" ,
273+ static_cast < float (QAngle::*)( int ) const >(&QAngle::operator [])
274+ )
275+
276+ .def (" __setitem__" ,
277+ SetItemIndexer<QAngle, float >
278+ )
279+
280+ .def (self == self)
281+ .def (self != self)
282+
283+ .def (self += self)
284+ .def (self -= self)
285+ .def (self *= other<float >())
286+ .def (self /= other<float >())
287+
288+ .def (" get_length" ,
289+ &QAngle::Length
290+ )
291+
292+ .def (" get_length_sqr" ,
293+ &QAngle::LengthSqr
294+ )
295+
296+ .def (self + self)
297+ .def (self - self)
298+ .def (self * other<float >())
299+ .def (self / other<float >())
300+ ;
301+ }
302+
303+ // -----------------------------------------------------------------------------
304+ // Exposes Quaternion
305+ // -----------------------------------------------------------------------------
306+ void export_quaternion ()
307+ {
308+ // TODO: Documentation
309+ class_<Quaternion>(" Quaternion" )
310+ .def (init<float , float , float , float >())
311+ .def (init<RadianEuler>())
312+
313+ .def (" init" ,
314+ &Quaternion::Init
315+ )
316+
317+ .def (" is_valid" ,
318+ &Quaternion::IsValid
319+ )
320+
321+ .def (" invalidate" ,
322+ &Quaternion::Invalidate
323+ )
324+
325+ .def (self == self)
326+ .def (self != self)
327+
328+ .def (" __getitem__" ,
329+ static_cast < float (Quaternion::*)( int ) const >(&Quaternion::operator [])
330+ )
331+
332+ .def (" __setitem__" ,
333+ &SetItemIndexer<Quaternion, float >
334+ )
335+
336+ .def_readwrite (" x" ,
337+ &Quaternion::x
338+ )
339+
340+ .def_readwrite (" y" ,
341+ &Quaternion::y
342+ )
343+
344+ .def_readwrite (" z" ,
345+ &Quaternion::z
346+ )
347+
348+ .def_readwrite (" w" ,
349+ &Quaternion::w
350+ )
351+ ;
352+ }
353+
354+ // -----------------------------------------------------------------------------
355+ // Exposes cplane_t
356+ // -----------------------------------------------------------------------------
357+ void export_cplane_t ()
358+ {
359+ // TODO: Documentation
360+ class_<cplane_t >(" cplane" )
361+ .def_readwrite (" normal" ,
362+ &cplane_t ::normal
363+ )
364+
365+ .def_readwrite (" dist" ,
366+ &cplane_t ::dist
367+ )
368+
369+ .def_readwrite (" type" ,
370+ &cplane_t ::type
371+ )
372+
373+ .def_readwrite (" signbits" ,
374+ &cplane_t ::signbits
375+ )
376+
377+ // TODO: byte pad[2];
378+ ;
379+ }
380+
381+ // -----------------------------------------------------------------------------
382+ // Exposes RadianEuler
383+ // -----------------------------------------------------------------------------
384+ void export_radian_euler ()
385+ {
386+ // TODO: Documentation
387+ class_<RadianEuler>(" RadianEuler" )
388+ .def (init<float , float , float >())
389+ .def (init<Quaternion>())
390+ .def (init<QAngle>())
391+
392+ .def (" init" ,
393+ &RadianEuler::Init
394+ )
395+
396+ .def (" to_qangle" ,
397+ &RadianEuler::ToQAngle
398+ )
399+
400+ .def (" is_valid" ,
401+ &RadianEuler::IsValid
402+ )
403+
404+ .def (" invalidate" ,
405+ &RadianEuler::Invalidate
406+ )
407+
408+ .def (" __getitem__" ,
409+ static_cast < float (RadianEuler::*)( int ) const >(&RadianEuler::operator [])
410+ )
411+
412+ .def (" __setitem__" ,
413+ &SetItemIndexer<RadianEuler, float >
414+ )
415+
416+ .def_readwrite (" x" ,
417+ &RadianEuler::x
418+ )
419+
420+ .def_readwrite (" y" ,
421+ &RadianEuler::y
422+ )
423+
424+ .def_readwrite (" z" ,
425+ &RadianEuler::z
426+ )
427+ ;
228428}
0 commit comments