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.

116 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Class to control 'aim-down-sights' aka "IronSight" weapon functionality
  4. //
  5. //=====================================================================================//
  6. #ifndef WEAPON_IRONSIGHTCONTROLLER_H
  7. #define WEAPON_IRONSIGHTCONTROLLER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cs_shareddefs.h"
  12. #ifdef IRONSIGHT
  13. #ifdef CLIENT_DLL
  14. #define IRONSIGHT_ANGLE_AVERAGE_SIZE 8
  15. #define IRONSIGHT_ANGLE_AVERAGE_DIVIDE ( 1.0f / IRONSIGHT_ANGLE_AVERAGE_SIZE )
  16. #define IRONSIGHT_HIDE_CROSSHAIR_THRESHOLD 0.5f
  17. #endif
  18. enum CSIronSightMode
  19. {
  20. IronSight_should_approach_unsighted = 0,
  21. IronSight_should_approach_sighted,
  22. IronSight_viewmodel_is_deploying,
  23. IronSight_weapon_is_dropped
  24. };
  25. // class to keep track of and update iron sight values and state information
  26. class CIronSightController
  27. {
  28. public:
  29. CIronSightController();
  30. bool Init( CWeaponCSBase *pWeaponToMonitor );
  31. inline bool IsInitializedAndAvailable( void ) { return m_bIronSightAvailable; }
  32. void UpdateIronSightAmount( void );
  33. float GetIronSightFOV( float flDefaultFOV, bool bUseBiasedValue = false );
  34. inline float GetIronSightAmount( void ) { return m_flIronSightAmount; }
  35. inline float GetIronSightAmountGained( void ) { return m_flIronSightAmountGained; }
  36. inline float GetIronSightAmountBiased( void ) { return m_flIronSightAmountBiased; }
  37. inline float GetIronSightIdealFOV( void ) { return m_flIronSightFOV; }
  38. inline float GetIronSightPullUpDuration( void ) { return (m_flIronSightPullUpSpeed > 0) ? (1.0f / m_flIronSightPullUpSpeed) : 0.0f; } // pull up duration is how long the pull up would take in seconds, not the speed
  39. inline float GetIronSightPutDownDuration( void ) { return (m_flIronSightPutDownSpeed > 0) ? (1.0f / m_flIronSightPutDownSpeed) : 0.0f; } // put down duration is how long the put down would take in seconds, not the speed
  40. inline bool IsApproachingSighted( void ); //still true when weapon is 100% ironsighted
  41. inline bool IsApproachingUnSighted( void ); //still true when weapon is 0% ironsighted
  42. inline bool IsDeploying( void ); //is still playing deploy animation
  43. inline bool IsDropped( void ); //is dropped loose in the world with no player owner
  44. bool IsInIronSight( void ); //true if the weapon is ironsighted any positive amount
  45. void SetState( CSIronSightMode newState );
  46. #ifdef CLIENT_DLL
  47. void ApplyIronSightPositioning( Vector &vecCleanEyePosition, QAngle &angCleanEyeAngle, const Vector &vecBobbedEyePosition, const QAngle &angBobbedEyeAngle );
  48. void IncreaseDotBlur(float flAmount);
  49. float GetDotBlur(void);
  50. float GetDotWidth(void);
  51. Vector2D GetDotCoords(void);
  52. const char *GetDotMaterial(void);
  53. bool ShouldHideCrossHair( void );
  54. bool PrepareScopeEffect( int x, int y, int w, int h, CViewSetup *pViewSetup );
  55. void RenderScopeEffect( int x, int y, int w, int h, CViewSetup *pViewSetup );
  56. #endif
  57. private:
  58. bool m_bIronSightAvailable; //only true if members are initialized, valid, and ready to use
  59. QAngle m_angPivotAngle;
  60. Vector m_vecEyePos;
  61. float m_flIronSightAmount; //0.0 (not ironsighted at all) to 1.0 (fully looking down the sights)
  62. float m_flIronSightAmountGained;
  63. float m_flIronSightAmountBiased;
  64. float m_flIronSightPullUpSpeed; //speed to pull the weapon up to the eye
  65. float m_flIronSightPutDownSpeed; //speed to put the weapon back down into normal viewmodel position
  66. float m_flIronSightPivotForward;
  67. float m_flIronSightFOV;
  68. float m_flIronSightLooseness; //how rigidly the viewmodel reacts to changes in m_vecViewDeltaVelocity
  69. CWeaponCSBase *m_pAttachedWeapon;
  70. #ifdef CLIENT_DLL
  71. void AddToAngleAverage( QAngle newAngle );
  72. QAngle GetAngleAverage( void );
  73. QAngle m_angDeltaAverage[IRONSIGHT_ANGLE_AVERAGE_SIZE];
  74. QAngle QAngleDiff( QAngle &angTarget, QAngle &angSrc );
  75. QAngle m_angViewLast;
  76. Vector2D m_vecDotCoords;
  77. float m_flDotBlur;
  78. float m_flSpeedRatio;
  79. #endif
  80. };
  81. #endif //IRONSIGHT
  82. #endif // WEAPON_IRONSIGHTCONTROLLER_H