Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.7 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Math functions specific to the editor.
  4. //
  5. //===========================================================================//
  6. #ifndef HAMMER_MATHLIB_H
  7. #define HAMMER_MATHLIB_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. typedef unsigned char byte;
  12. #include "mathlib/mathlib.h"
  13. #include "mathlib/vmatrix.h"
  14. #include <math.h>
  15. typedef vec_t vec5_t[5];
  16. enum
  17. {
  18. AXIS_X = 0,
  19. AXIS_Y,
  20. AXIS_Z
  21. };
  22. //
  23. // Matrix functions:
  24. //
  25. void RotateAroundAxis(VMatrix& Matrix, float fDegrees, int nAxis);
  26. void AxisAngleMatrix(VMatrix& Matrix, const Vector &Axis, float fAngle);
  27. float fixang(float a);
  28. float lineangle(float x1, float y1, float x2, float y2);
  29. void polyMake( float x1, float y1, float x2, float y2, int npoints, float start_ang, Vector *pmPoints );
  30. float rint(float) _NOEXCEPT;
  31. inline int fsign( float x) { if(x==0) return 0; else if (x>0) return 1; else return -1; }
  32. inline bool fequal( float value, float target, float delta) { return ( (value<(target+delta))&&(value>(target-delta)) ); }
  33. void RoundVector( Vector2D &v );
  34. bool IsLineInside(const Vector2D &pt1, const Vector2D &pt2, int x1, int y1, int x2, int y2);
  35. bool IsPointInside(const Vector2D &pt, const Vector2D &mins, const Vector2D &maxs );
  36. bool IsValidBox( Vector &mins, Vector &maxs );
  37. bool IsValidBox( const Vector2D &mins, const Vector2D &maxs );
  38. void NormalizeBox( Vector &mins, Vector &maxs );
  39. void NormalizeBox( Vector2D &mins, Vector2D &maxs );
  40. void PointsFromBox( const Vector &mins, const Vector &maxs, Vector *points );
  41. void LimitBox( Vector &mins, Vector &maxs, float limit );
  42. void PointsRevertOrder( Vector *pPoints, int nPoints);
  43. // Is box 1 inside box 2?
  44. bool IsBoxInside( const Vector2D &min1, const Vector2D &max1, const Vector2D &min2, const Vector2D &max2 );
  45. bool IsBoxIntersecting( const Vector2D &min1, const Vector2D &max1, const Vector2D &min2, const Vector2D &max2 );
  46. const Vector &GetNormalFromPoints( const Vector &p1, const Vector &p2, const Vector &p3 );
  47. const Vector &GetNormalFromFace( int nFace );
  48. inline void TransformPoint( const VMatrix& matrix, Vector &point )
  49. {
  50. Vector orgVector = point;
  51. matrix.V3Mul( orgVector, point );
  52. }
  53. // solve equation v0 = x*v1 + y*v2 + z*v3
  54. void GetAxisFromFace( int nFace, Vector& vHorz, Vector &vVert, Vector &vThrd );
  55. bool SolveLinearEquation( const Vector& v0, const Vector& v1, const Vector& v2, const Vector& v3, Vector& vOut);
  56. // test intersection line & AABB, returns -1 if no intersection occurs
  57. float IntersectionLineAABBox( const Vector& mins, const Vector& maxs, const Vector& vStart, const Vector& vEnd, int &nFace );
  58. bool BuildAxesFromNormal( const Vector &vNormal, Vector &vHorz, Vector &vVert );
  59. #endif // HAMMER_MATHLIB_H