Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. void C_BaseEntity::CalcAbsolutePosition( )
  2. {
  3. // There are periods of time where we're gonna have to live with the
  4. // fact that we're in an indeterminant state and abs queries (which
  5. // shouldn't be happening at all; I have assertions for those), will
  6. // just have to accept stale data.
  7. if (!s_bAbsRecomputationEnabled)
  8. return;
  9.  
  10. // FIXME: Recompute absbox!!!
  11. if ((m_iEFlags & EFL_DIRTY_ABSTRANSFORM) == 0)
  12. {
  13. // quick check to make sure we really don't need an update
  14. // Assert( m_pMoveParent || m_vecAbsOrigin == GetLocalOrigin() );
  15. return;
  16. }
  17.  
  18. AUTO_LOCK( m_CalcAbsolutePositionMutex );
  19.  
  20. if ((m_iEFlags & EFL_DIRTY_ABSTRANSFORM) == 0) // need second check in event another thread grabbed mutex and did the calculation
  21. {
  22. return;
  23. }
  24.  
  25. RemoveEFlags( EFL_DIRTY_ABSTRANSFORM );
  26.  
  27. if (!m_pMoveParent)
  28. {
  29. // Construct the entity-to-world matrix
  30. // Start with making an entity-to-parent matrix
  31. AngleMatrix( GetLocalAngles(), GetLocalOrigin(), m_rgflCoordinateFrame );
  32. m_vecAbsOrigin = GetLocalOrigin();
  33. m_angAbsRotation = GetLocalAngles();
  34. NormalizeAngles( m_angAbsRotation );
  35. return;
  36. }
  37.  
  38. if ( IsEffectActive(EF_BONEMERGE) )
  39. {
  40. MoveToAimEnt();
  41. return;
  42. }
  43.  
  44. // Construct the entity-to-world matrix
  45. // Start with making an entity-to-parent matrix
  46. matrix3x4_t matEntityToParent;
  47. AngleMatrix( GetLocalAngles(), matEntityToParent );
  48. MatrixSetColumn( GetLocalOrigin(), 3, matEntityToParent );
  49.  
  50. // concatenate with our parent's transform
  51. matrix3x4_t scratchMatrix;
  52. ConcatTransforms( GetParentToWorldTransform( scratchMatrix ), matEntityToParent, m_rgflCoordinateFrame );
  53.  
  54. // pull our absolute position out of the matrix
  55. MatrixGetColumn( m_rgflCoordinateFrame, 3, m_vecAbsOrigin );
  56.  
  57. // if we have any angles, we have to extract our absolute angles from our matrix
  58. if ( m_angRotation == vec3_angle && m_iParentAttachment == 0 )
  59. {
  60. // just copy our parent's absolute angles
  61. VectorCopy( m_pMoveParent->GetAbsAngles(), m_angAbsRotation );
  62. }
  63. else
  64. {
  65. MatrixAngles( m_rgflCoordinateFrame, m_angAbsRotation );
  66. }
  67.  
  68. // This is necessary because it's possible that our moveparent's CalculateIKLocks will trigger its move children
  69. // (ie: this entity) to call GetAbsOrigin(), and they'll use the moveparent's OLD bone transforms to get their attachments
  70. // since the moveparent is right in the middle of setting up new transforms.
  71. //
  72. // So here, we keep our absorigin invalidated. It means we're returning an origin that is a frame old to CalculateIKLocks,
  73. // but we'll still render with the right origin.
  74. if ( m_iParentAttachment != 0 && (m_pMoveParent->GetEFlags() & EFL_SETTING_UP_BONES) )
  75. {
  76. m_iEFlags |= EFL_DIRTY_ABSTRANSFORM;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement