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.

96 lines
3.0 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "c_prop_weightedcube.h"
  9. #include "portal_grabcontroller_shared.h"
  10. #include "c_portal_player.h"
  11. IMPLEMENT_CLIENTCLASS_DT( C_PropWeightedCube, DT_PropWeightedCube, CPropWeightedCube )
  12. END_RECV_TABLE()
  13. LINK_ENTITY_TO_CLASS( prop_weighted_cube, C_PropWeightedCube );
  14. CUtlVector<C_PropWeightedCube *> C_PropWeightedCube::s_AllWeightedCubes;
  15. extern void ComputePlayerMatrix( CBasePlayer *pPlayer, matrix3x4_t &out );
  16. QAngle C_PropWeightedCube::PreferredCarryAngles( void )
  17. {
  18. static QAngle s_prefAngles;
  19. s_prefAngles = (m_qPreferredPlayerCarryAngles.x < FLT_MAX) ? m_qPreferredPlayerCarryAngles : vec3_angle;
  20. CBasePlayer *pPlayer = GetPlayerHoldingEntity( this );
  21. if ( pPlayer )
  22. {
  23. Vector vecRight;
  24. AngleVectors( pPlayer->EyeAngles(), NULL, &vecRight, NULL );
  25. Quaternion qRotation;
  26. AxisAngleQuaternion( vecRight, pPlayer->EyeAngles().x, qRotation );
  27. matrix3x4_t tmp;
  28. ComputePlayerMatrix( pPlayer, tmp );
  29. QAngle qTemp = TransformAnglesToWorldSpace( s_prefAngles, tmp );
  30. Quaternion qExisting;
  31. AngleQuaternion( qTemp, qExisting );
  32. Quaternion qFinal;
  33. QuaternionMult( qRotation, qExisting, qFinal );
  34. QuaternionAngles( qFinal, qTemp );
  35. s_prefAngles = TransformAnglesToLocalSpace( qTemp, tmp );
  36. }
  37. return s_prefAngles;
  38. }
  39. const Vector& C_PropWeightedCube::GetRenderOrigin( void )
  40. {
  41. if( GetPredictable() )
  42. {
  43. C_Portal_Player *pPlayer = (C_Portal_Player *)GetPlayerHoldingEntity( this );
  44. if( pPlayer && pPlayer->GetGrabController().GetAttached() == this )
  45. {
  46. //predicted grab controllers will almost never get the prediction correct. Which nukes our interpolation histories, resulting in jittery movement
  47. //workaround this by using the nuke-safe interpolation history directly in the grab controller
  48. return pPlayer->GetGrabController().GetHeldObjectRenderOrigin();
  49. }
  50. }
  51. return BaseClass::GetRenderOrigin();
  52. }
  53. void C_PropWeightedCube::UpdateOnRemove( void )
  54. {
  55. s_AllWeightedCubes.FindAndFastRemove( this );
  56. BaseClass::UpdateOnRemove();
  57. }
  58. void C_PropWeightedCube::Spawn( void )
  59. {
  60. BaseClass::Spawn();
  61. s_AllWeightedCubes.AddToTail( this );
  62. }
  63. //At some point it would be good to generalize this function to handle all MOVETYPE_VPHYSICS entities
  64. //But we're close to cert for Portal 2. So the scope at the moment is kept small.
  65. void MoveUnpredictedPhysicsNearPlayerToNetworkedPosition( CBasePlayer *pPlayer )
  66. {
  67. Vector vPlayerCenter = pPlayer->WorldSpaceCenter();
  68. for( int i = 0; i != C_PropWeightedCube::s_AllWeightedCubes.Count(); ++i )
  69. {
  70. C_PropWeightedCube *pCube = C_PropWeightedCube::s_AllWeightedCubes[i];
  71. if( !pCube->GetPredictable() && ((vPlayerCenter - pCube->WorldSpaceCenter()).LengthSqr() < (512.0f * 512.0f)) )
  72. {
  73. pCube->MoveToLastReceivedPosition();
  74. }
  75. }
  76. }