From f56bb35301836e56582a575a75864392a0177875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Mon, 2 Dec 2013 19:31:46 -0800 Subject: Fix line endings. WHAMMY. --- mp/src/game/shared/rope_helpers.cpp | 280 ++++++++++++++++++------------------ 1 file changed, 140 insertions(+), 140 deletions(-) (limited to 'mp/src/game/shared/rope_helpers.cpp') diff --git a/mp/src/game/shared/rope_helpers.cpp b/mp/src/game/shared/rope_helpers.cpp index 4150a74f..07a05f1c 100644 --- a/mp/src/game/shared/rope_helpers.cpp +++ b/mp/src/game/shared/rope_helpers.cpp @@ -1,140 +1,140 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "rope_helpers.h" -#include "basetypes.h" -#include "mathlib/mathlib.h" -#include "rope_shared.h" -#include "rope_physics.h" -#include "networkvar.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -class CHangRope : public CRopePhysics<512> -{ -DECLARE_CLASS( CHangRope, CRopePhysics<512> ); - -// CRopePhysics overrides. -public: - - virtual void GetNodeForces( CSimplePhysics::CNode *pNodes, int iNode, Vector *pAccel ) - { - pAccel->Init( ROPE_GRAVITY ); - } - - - virtual void ApplyConstraints( CSimplePhysics::CNode *pNodes, int nNodes ) - { - // Apply spring forces. - BaseClass::ApplyConstraints( pNodes, nNodes ); - - - // Lock the endpoints. - pNodes[0].m_vPos = m_vEndPoints[0]; - pNodes[nNodes-1].m_vPos = m_vEndPoints[1]; - - - // Calculate how far it is hanging down and adjust if necessary. - float flCurHangDist = 0; - for ( int i=0; i < NumNodes(); i++ ) - { - float hang = fabs( m_flStartZ - GetNode(i)->m_vPos.z ); - if ( hang > flCurHangDist ) - flCurHangDist = hang; - } - - // Adjust our spring length accordingly. - if ( flCurHangDist < m_flWantedHangDist ) - m_flCurSlack += 1; - else - m_flCurSlack -= 1; - - ApplyNewSpringLength(); - } - - -// Helpers. -public: - - void ApplyNewSpringLength() - { - ResetSpringLength( (m_flRopeLength + m_flCurSlack + ROPESLACK_FUDGEFACTOR) / (NumNodes() - 1) ); - } - - -// Variables used to adjust the rope slack. -public: - - Vector m_vEndPoints[2]; - bool m_bAdjustSlack; - - float m_flRopeLength; - float m_flCurSlack; - - float m_flWantedHangDist; - float m_flStartZ; - -}; - - - -void CalcRopeStartingConditions( - const Vector &vStartPos, - const Vector &vEndPos, - int const nNodes, - float const desiredHang, - float *pOutputLength, - float *pOutputSlack - ) -{ - CHangRope rope; - - // Initialize the rope as a straight line with no slack as our first approximation. - // We then relax the rope by adding slack until it hangs to the desired height. - // - // The spring length equation is: - // springLength = (ropeLength + slack + ROPESLACK_FUDGEFACTOR) / (nNodes - 1) - // - // We want our rope to be a straight line, so: - // springLength = ropeLength / (nNodes-1) - // - // Therefore our initial slack is -ROPESLACK_FUDGEFACTOR - rope.m_flCurSlack = -ROPESLACK_FUDGEFACTOR; - - rope.m_vEndPoints[0] = vStartPos; - rope.m_vEndPoints[1] = vEndPos; - - rope.m_flRopeLength = (vEndPos - vStartPos).Length(); - rope.m_flWantedHangDist = desiredHang; - - rope.m_flStartZ = MIN( vStartPos.z, vEndPos.z ); // Calculate hang as the Z distance from the - // lowest endpoint to the bottom of the rope. - - rope.SetNumNodes( nNodes ); - - // Set the node positions. - for ( int i=0; i < rope.NumNodes(); i++ ) - { - CSimplePhysics::CNode *pNode = rope.GetNode( i ); - - float t = (float)i / (rope.NumNodes() - 1); - VectorLerp( vStartPos, vEndPos, t, pNode->m_vPos ); - pNode->m_vPrevPos = pNode->m_vPos; - } - - // Now simulate a little and stretch out to let it hang down. - rope.Restart(); - rope.Simulate( 3 ); - - // Set outputs. - *pOutputLength = rope.m_flRopeLength; - *pOutputSlack = rope.m_flCurSlack; -} - - +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "cbase.h" +#include "rope_helpers.h" +#include "basetypes.h" +#include "mathlib/mathlib.h" +#include "rope_shared.h" +#include "rope_physics.h" +#include "networkvar.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +class CHangRope : public CRopePhysics<512> +{ +DECLARE_CLASS( CHangRope, CRopePhysics<512> ); + +// CRopePhysics overrides. +public: + + virtual void GetNodeForces( CSimplePhysics::CNode *pNodes, int iNode, Vector *pAccel ) + { + pAccel->Init( ROPE_GRAVITY ); + } + + + virtual void ApplyConstraints( CSimplePhysics::CNode *pNodes, int nNodes ) + { + // Apply spring forces. + BaseClass::ApplyConstraints( pNodes, nNodes ); + + + // Lock the endpoints. + pNodes[0].m_vPos = m_vEndPoints[0]; + pNodes[nNodes-1].m_vPos = m_vEndPoints[1]; + + + // Calculate how far it is hanging down and adjust if necessary. + float flCurHangDist = 0; + for ( int i=0; i < NumNodes(); i++ ) + { + float hang = fabs( m_flStartZ - GetNode(i)->m_vPos.z ); + if ( hang > flCurHangDist ) + flCurHangDist = hang; + } + + // Adjust our spring length accordingly. + if ( flCurHangDist < m_flWantedHangDist ) + m_flCurSlack += 1; + else + m_flCurSlack -= 1; + + ApplyNewSpringLength(); + } + + +// Helpers. +public: + + void ApplyNewSpringLength() + { + ResetSpringLength( (m_flRopeLength + m_flCurSlack + ROPESLACK_FUDGEFACTOR) / (NumNodes() - 1) ); + } + + +// Variables used to adjust the rope slack. +public: + + Vector m_vEndPoints[2]; + bool m_bAdjustSlack; + + float m_flRopeLength; + float m_flCurSlack; + + float m_flWantedHangDist; + float m_flStartZ; + +}; + + + +void CalcRopeStartingConditions( + const Vector &vStartPos, + const Vector &vEndPos, + int const nNodes, + float const desiredHang, + float *pOutputLength, + float *pOutputSlack + ) +{ + CHangRope rope; + + // Initialize the rope as a straight line with no slack as our first approximation. + // We then relax the rope by adding slack until it hangs to the desired height. + // + // The spring length equation is: + // springLength = (ropeLength + slack + ROPESLACK_FUDGEFACTOR) / (nNodes - 1) + // + // We want our rope to be a straight line, so: + // springLength = ropeLength / (nNodes-1) + // + // Therefore our initial slack is -ROPESLACK_FUDGEFACTOR + rope.m_flCurSlack = -ROPESLACK_FUDGEFACTOR; + + rope.m_vEndPoints[0] = vStartPos; + rope.m_vEndPoints[1] = vEndPos; + + rope.m_flRopeLength = (vEndPos - vStartPos).Length(); + rope.m_flWantedHangDist = desiredHang; + + rope.m_flStartZ = MIN( vStartPos.z, vEndPos.z ); // Calculate hang as the Z distance from the + // lowest endpoint to the bottom of the rope. + + rope.SetNumNodes( nNodes ); + + // Set the node positions. + for ( int i=0; i < rope.NumNodes(); i++ ) + { + CSimplePhysics::CNode *pNode = rope.GetNode( i ); + + float t = (float)i / (rope.NumNodes() - 1); + VectorLerp( vStartPos, vEndPos, t, pNode->m_vPos ); + pNode->m_vPrevPos = pNode->m_vPos; + } + + // Now simulate a little and stretch out to let it hang down. + rope.Restart(); + rope.Simulate( 3 ); + + // Set outputs. + *pOutputLength = rope.m_flRopeLength; + *pOutputSlack = rope.m_flCurSlack; +} + + -- cgit v1.2.3