Team Fortress 2 Source Code as on 22/4/2020
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.

165 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: The implementation of ISourceVirtualReality, which provides utility
  4. // functions for VR including head tracking, window/viewport information,
  5. // rendering information, and distortion
  6. //
  7. //=============================================================================
  8. #ifndef CLIENTVIRTUALREALITY_H
  9. #define CLIENTVIRTUALREALITY_H
  10. #if defined( _WIN32 )
  11. #pragma once
  12. #endif
  13. #include "tier3/tier3.h"
  14. #include "iclientvirtualreality.h"
  15. #include "view_shared.h"
  16. enum HeadtrackMovementMode_t
  17. {
  18. HMM_SHOOTFACE_MOVEFACE = 0, // Shoot from your face, move along your face.
  19. HMM_SHOOTFACE_MOVETORSO, // Shoot from your face, move the direction your torso is facing.
  20. HMM_SHOOTMOUSE_MOVEFACE, // Shoot from the mouse cursor which moves within the HUD, move along your face.
  21. HMM_SHOOTBOUNDEDMOUSE_LOOKFACE_MOVEFACE, // Shoot from the mouse cursor which moves, bounded within the HUD, move along your face.
  22. HMM_SHOOTBOUNDEDMOUSE_LOOKFACE_MOVEMOUSE, // Shoot from the mouse cursor which moves, bounded within the HUD, move along your weapon (the "mouse")
  23. // The following are not intended to be user-selectable modes, they are used by e.g. followcam stuff.
  24. HMM_SHOOTMOVELOOKMOUSEFACE, // Shoot & move & look along the mouse cursor (i.e. original unchanged gameplay), face just looks on top of that.
  25. HMM_SHOOTMOVEMOUSE_LOOKFACE, // Shoot & move along the mouse cursor (i.e. original unchanged gameplay), face just looks.
  26. HMM_SHOOTMOVELOOKMOUSE, // Shoot, move and look along the mouse cursor - HMD orientation is completely ignored!
  27. HMM_LAST,
  28. HMM_NOOVERRIDE = HMM_LAST // Used as a retrun from ShouldOverrideHeadtrackControl(), not an actual mode.
  29. };
  30. //-----------------------------------------------------------------------------
  31. // The implementation
  32. //-----------------------------------------------------------------------------
  33. class CClientVirtualReality: public CTier3AppSystem< IClientVirtualReality >
  34. {
  35. typedef CTier3AppSystem< IClientVirtualReality > BaseClass;
  36. public:
  37. CClientVirtualReality();
  38. ~CClientVirtualReality();
  39. //---------------------------------------------------------
  40. // Initialization and shutdown
  41. //---------------------------------------------------------
  42. //
  43. // IAppSystem
  44. //
  45. virtual bool Connect( CreateInterfaceFn factory );
  46. virtual void Disconnect();
  47. virtual void * QueryInterface( const char *pInterfaceName );
  48. // these will come from the engine
  49. virtual InitReturnVal_t Init();
  50. virtual void Shutdown();
  51. // Called when startup is complete
  52. void StartupComplete();
  53. //---------------------------------------------------------
  54. // IClientVirtualReality implementation
  55. //---------------------------------------------------------
  56. virtual void DrawMainMenu() OVERRIDE;
  57. //---------------------------------------------------------
  58. // VR utilities for use in the client
  59. //---------------------------------------------------------
  60. bool OverrideView ( CViewSetup *pViewMiddle, Vector *pViewModelOrigin, QAngle *pViewModelAngles, HeadtrackMovementMode_t hmmMovementOverride );
  61. bool OverrideStereoView( CViewSetup *pViewMiddle, CViewSetup *pViewLeft, CViewSetup *pViewRight );
  62. bool OverridePlayerMotion( float flInputSampleFrametime, const QAngle &oldAngles, const QAngle &curAngles, const Vector &curMotion, QAngle *pNewAngles, Vector *pNewMotion );
  63. bool OverrideWeaponHudAimVectors ( Vector *pAimOrigin, Vector *pAimDirection );
  64. bool CurrentlyZoomed();
  65. void OverrideTorsoTransform( const Vector & position, const QAngle & angles ) ;
  66. void CancelTorsoTransformOverride( ) ;
  67. bool CanOverlayHudQuad();
  68. void GetHUDBounds( Vector *pViewer, Vector *pUL, Vector *pUR, Vector *pLL, Vector *pLR );
  69. void RenderHUDQuad( bool bBlackout, bool bTranslucent );
  70. float GetZoomedModeMagnification();
  71. bool ProcessCurrentTrackingState( float fGameFOV );
  72. const VMatrix &GetHudProjectionFromWorld();
  73. void GetTorsoRelativeAim( Vector *pPosition, QAngle *pAngles );
  74. float GetHUDDistance();
  75. bool ShouldRenderHUDInWorld();
  76. const VMatrix & GetWorldFromMidEye() const { return m_WorldFromMidEyeNoDebugCam; }
  77. void OverrideViewModelTransform( Vector & vmorigin, QAngle & vmangles, bool bUseLargeOverride );
  78. void AlignTorsoAndViewToWeapon();
  79. void PostProcessFrame( StereoEye_t eEye );
  80. void OverlayHUDQuadWithUndistort( const CViewSetup &view, bool bDoUndistort, bool bBlackout, bool bTranslucent );
  81. //---------------------------------------------------------
  82. // Enter/leave VR mode
  83. //---------------------------------------------------------
  84. void Activate();
  85. void Deactivate();
  86. private:
  87. HeadtrackMovementMode_t m_hmmMovementActual;
  88. // Where the current mideye is relative to the (game)world.
  89. VMatrix m_WorldFromMidEye;
  90. // used for drawing the HUD
  91. float m_fHudHorizontalFov;
  92. VMatrix m_WorldFromHud;
  93. VMatrix m_HudProjectionFromWorld;
  94. float m_fHudHalfWidth;
  95. float m_fHudHalfHeight;
  96. // Where the current mideye is relative to the zero (torso) (currently always the same as m_MideyeZeroFromMideyeCurrent!)
  97. VMatrix m_TorsoFromMideye;
  98. // The debug cam will play with the above, but some things want the non-debug view.
  99. VMatrix m_WorldFromMidEyeNoDebugCam;
  100. // Where the weapon is currently pointing (note the translation will be zero - this is just orientation)
  101. VMatrix m_WorldFromWeapon;
  102. // The player's current torso angles/pos in the world.
  103. QAngle m_PlayerTorsoAngle;
  104. Vector m_PlayerTorsoOrigin;
  105. Vector m_PlayerLastMovement;
  106. // The player's current view angles/pos in the world.
  107. QAngle m_PlayerViewAngle;
  108. Vector m_PlayerViewOrigin;
  109. // The amount of zoom to apply to the view of the world (but NOT to the HUD!). Used for sniper weapons, etc.
  110. float m_WorldZoomScale;
  111. // for overriding torso position in vehicles
  112. QAngle m_OverrideTorsoAngle;
  113. QAngle m_OverrideTorsoOffset;
  114. bool m_bOverrideTorsoAngle;
  115. // While this is >0, we keep forcing the torso (and maybe view) to the weapon.
  116. int m_iAlignTorsoAndViewToWeaponCountdown;
  117. bool m_bMotionUpdated;
  118. RTime32 m_rtLastMotionSample;
  119. // video mode we had before we entered VR mode
  120. bool m_bNonVRWindowed;
  121. int m_nNonVRWidth;
  122. int m_nNonVRHeight;
  123. #if defined( USE_SDL )
  124. int m_nNonVRSDLDisplayIndex;
  125. #endif
  126. bool m_bNonVRRawInput;
  127. };
  128. extern CClientVirtualReality g_ClientVirtualReality;
  129. #endif // CLIENTVIRTUALREALITY_H