From dc2be1dcb4c8aaccfe56133d12d7b99dc8243e66 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sat, 23 Oct 2021 14:41:59 +0300 Subject: [PATCH] physics: fix a lot of problems --- engine/cmodel.cpp | 2 +- engine/disp.cpp | 4 +-- engine/disp_mapload.cpp | 4 +-- engine/r_areaportal.cpp | 4 +-- game/client/c_steamjet.cpp | 4 +-- game/client/interpolatedvar.h | 2 +- game/client/particle_iterators.h | 4 +-- game/client/tf2/c_obj_mcv_selection_panel.cpp | 2 +- game/client/tf2/c_ragdoll_shadow.cpp | 2 +- game/server/physics.cpp | 28 ++++++++++++++++--- game/server/player.cpp | 2 +- game/server/tf2/order_heal.cpp | 2 +- game/server/tf2/order_helpers.cpp | 2 +- game/server/tf2/order_killmortarguy.cpp | 2 +- game/server/tf2/order_mortar_attack.cpp | 2 +- game/server/tf2/order_repair.cpp | 4 +-- game/server/tf2/tf_obj_barbed_wire.cpp | 2 +- game/server/tf2/tf_playerclass.cpp | 2 +- game/server/tf2/tf_team.h | 2 +- game/shared/physics_shared.cpp | 2 +- inputsystem/inputsystem.h | 2 +- public/bspfile.h | 3 ++ public/disp_common.cpp | 4 +-- public/inputsystem/iinputsystem.h | 2 ++ public/keyframe/keyframe.cpp | 2 +- studiorender/r_studiodraw.cpp | 15 ++++++---- vgui2/vgui_controls/TextEntry.cpp | 3 +- vgui2/vgui_controls/consoledialog.cpp | 5 +++- vphysics/physics_object.cpp | 26 ++++++++++------- vphysics/physics_shadow.cpp | 2 +- vphysics/vcollide_parse.cpp | 16 +++++++++-- 31 files changed, 104 insertions(+), 54 deletions(-) diff --git a/engine/cmodel.cpp b/engine/cmodel.cpp index 4b031bf7..466d4451 100644 --- a/engine/cmodel.cpp +++ b/engine/cmodel.cpp @@ -2788,7 +2788,7 @@ int CFastPointLeafNum::GetLeaf( const Vector &vPos ) m_vCachedPos = vPos; CCollisionBSPData *pBSPData = GetCollisionBSPData(); - m_flDistToExitLeafSqr = 1e16; + m_flDistToExitLeafSqr = 1e24; m_iCachedLeaf = CM_PointLeafnumMinDistSqr_r( pBSPData, vPos, 0, m_flDistToExitLeafSqr ); } diff --git a/engine/disp.cpp b/engine/disp.cpp index adfdbd41..6c9781c1 100644 --- a/engine/disp.cpp +++ b/engine/disp.cpp @@ -102,8 +102,8 @@ inline CVertIndex CDispInfo::IndexToVert( int index ) const void CDispInfo::UpdateBoundingBox() { - m_BBoxMin.Init( 1e16, 1e16, 1e16 ); - m_BBoxMax.Init( -1e16, -1e16, -1e16 ); + m_BBoxMin.Init( 1e24, 1e24, 1e24 ); + m_BBoxMax.Init( -1e24, -1e24, -1e24 ); for( int i=0; i < NumVerts(); i++ ) { diff --git a/engine/disp_mapload.cpp b/engine/disp_mapload.cpp index 744a68b6..11b75e96 100644 --- a/engine/disp_mapload.cpp +++ b/engine/disp_mapload.cpp @@ -793,7 +793,7 @@ CDispInfo::CDispInfo() m_pPowerInfo = NULL; - m_ViewerSphereCenter.Init( 1e16, 1e16, 1e16 ); + m_ViewerSphereCenter.Init( 1e24, 1e24, 1e24 ); m_bInUse = false; @@ -995,7 +995,7 @@ int FindNeighborCornerVert( CCoreDispInfo *pDisp, const Vector &vecPoint ) CDispUtilsHelper *pDispHelper = pDisp; int iClosest = 0; - float flClosest = 1e16; + float flClosest = 1e24; for ( int iCorner = 0; iCorner < 4; ++iCorner ) { diff --git a/engine/r_areaportal.cpp b/engine/r_areaportal.cpp index 2c596b11..4773fc1e 100644 --- a/engine/r_areaportal.cpp +++ b/engine/r_areaportal.cpp @@ -122,8 +122,8 @@ struct portalclip_t static inline bool GetPortalScreenExtents( dareaportal_t *pPortal, portalclip_t * RESTRICT clip, CPortalRect &portalRect , float *pReflectionWaterHeight ) { - portalRect.left = portalRect.bottom = 1e16; - portalRect.right = portalRect.top = -1e16; + portalRect.left = portalRect.bottom = 1e24; + portalRect.right = portalRect.top = -1e24; bool bValidExtents = false; worldbrushdata_t *pBrushData = host_state.worldbrush; diff --git a/game/client/c_steamjet.cpp b/game/client/c_steamjet.cpp index 9608ceda..f36ccc63 100644 --- a/game/client/c_steamjet.cpp +++ b/game/client/c_steamjet.cpp @@ -150,8 +150,8 @@ C_SteamJet::C_SteamJet() m_bFaceLeft = false; m_ParticleEffect.SetAlwaysSimulate( false ); // Don't simulate outside the PVS or frustum. - m_vLastRampUpdatePos.Init( 1e16, 1e16, 1e16 ); - m_vLastRampUpdateAngles.Init( 1e16, 1e16, 1e16 ); + m_vLastRampUpdatePos.Init( 1e24, 1e24, 1e24 ); + m_vLastRampUpdateAngles.Init( 1e24, 1e24, 1e24 ); } diff --git a/game/client/interpolatedvar.h b/game/client/interpolatedvar.h index f0edb585..b5467ad4 100644 --- a/game/client/interpolatedvar.h +++ b/game/client/interpolatedvar.h @@ -283,7 +283,7 @@ struct CInterpolatedVarEntryBase { Assert(maxCount==1); } - Type *NewEntry( const Type *pValue, int maxCount, float time ) + Type *NewEntry( Type *pValue, int maxCount, float time ) { Assert(maxCount==1); changetime = time; diff --git a/game/client/particle_iterators.h b/game/client/particle_iterators.h index ba9ebae1..f38e4c49 100644 --- a/game/client/particle_iterators.h +++ b/game/client/particle_iterators.h @@ -125,8 +125,8 @@ inline CParticleRenderIterator::CParticleRenderIterator() m_bGotFirst = false; m_flPrevZ = 0; m_nParticlesInCurrentBatch = 0; - m_MinZ = 1e16; - m_MaxZ = -1e16; + m_MinZ = 1e24; + m_MaxZ = -1e24; m_nZCoords = 0; } diff --git a/game/client/tf2/c_obj_mcv_selection_panel.cpp b/game/client/tf2/c_obj_mcv_selection_panel.cpp index e5315bc8..1e57f0ba 100644 --- a/game/client/tf2/c_obj_mcv_selection_panel.cpp +++ b/game/client/tf2/c_obj_mcv_selection_panel.cpp @@ -173,7 +173,7 @@ void CMCVMinimapPanel::OnMousePressed( vgui::MouseCode code ) // Find the closest MCV to their mouse press. int iClosest = -1; - float flClosest = 1e16; + float flClosest = 1e24; Vector2D curMousePos( m_LastX, m_LastY ); for ( int i=0; i < pPanel->m_DeployedTeleportStations.Count(); i++ ) diff --git a/game/client/tf2/c_ragdoll_shadow.cpp b/game/client/tf2/c_ragdoll_shadow.cpp index 4e9487bc..efb705b4 100644 --- a/game/client/tf2/c_ragdoll_shadow.cpp +++ b/game/client/tf2/c_ragdoll_shadow.cpp @@ -79,7 +79,7 @@ IPhysicsObject *PhysModelCreateCustom( C_BaseEntity *pEntity, const CPhysCollide solid_t solid; solid.params = g_PhysDefaultObjectParams; solid.params.mass = 85.0f; - solid.params.inertia = 1e16f; + solid.params.inertia = 1e24f; int surfaceProp = -1; if ( props && props[0] ) { diff --git a/game/server/physics.cpp b/game/server/physics.cpp index 7b66a54c..031c7983 100644 --- a/game/server/physics.cpp +++ b/game/server/physics.cpp @@ -74,7 +74,7 @@ static float g_PhysAverageSimTime; CCallQueue g_PostSimulationQueue; -// local routines +// local roeutines static IPhysicsObject *PhysCreateWorld( CBaseEntity *pWorld ); static void PhysFrame( float deltaTime ); static bool IsDebris( int collisionGroup ); @@ -1689,6 +1689,7 @@ void PhysFrame( float deltaTime ) float simRealTime = 0; deltaTime *= phys_timescale.GetFloat(); + // !!!HACKHACK -- hard limit scaled time to avoid spending too much time in here // Limit to 100 ms if ( deltaTime > 0.100f ) @@ -1709,10 +1710,28 @@ void PhysFrame( float deltaTime ) g_Collisions.BufferTouchEvents( true ); #endif - physenv->Simulate( deltaTime ); - int activeCount = physenv->GetActiveObjectCount(); IPhysicsObject **pActiveList = NULL; +#if 0 + if ( activeCount ) + { + pActiveList = (IPhysicsObject **)stackalloc( sizeof(IPhysicsObject *)*activeCount ); + physenv->GetActiveObjects( pActiveList ); + + for ( int i = 0; i < activeCount; i++ ) + { + CBaseEntity *pEntity = reinterpret_cast(pActiveList[i]->GetGameData()); + OutputVPhysicsDebugInfo(pEntity); + } + stackfree( pActiveList ); + } +#endif + + physenv->Simulate( deltaTime ); + + activeCount = physenv->GetActiveObjectCount(); + pActiveList = NULL; + if ( activeCount ) { pActiveList = (IPhysicsObject **)stackalloc( sizeof(IPhysicsObject *)*activeCount ); @@ -1721,6 +1740,7 @@ void PhysFrame( float deltaTime ) for ( int i = 0; i < activeCount; i++ ) { CBaseEntity *pEntity = reinterpret_cast(pActiveList[i]->GetGameData()); +// OutputVPhysicsDebugInfo(pEntity); if ( pEntity ) { if ( pEntity->CollisionProp()->DoesVPhysicsInvalidateSurroundingBox() ) @@ -1948,7 +1968,7 @@ void CCollisionEvent::Friction( IPhysicsObject *pObject, float energy, int surfa if ( pEntity ) { friction_t *pFriction = g_Collisions.FindFriction( pEntity ); - + if ( pFriction && pFriction->pObject) { // in MP mode play sound and effects once every 500 msecs, diff --git a/game/server/player.cpp b/game/server/player.cpp index 745a8242..7dea1f50 100644 --- a/game/server/player.cpp +++ b/game/server/player.cpp @@ -8014,7 +8014,7 @@ void CBasePlayer::SetupVPhysicsShadow( const Vector &vecAbsOrigin, const Vector Q_strncpy( solid.surfaceprop, "player", sizeof(solid.surfaceprop) ); solid.params = g_PhysDefaultObjectParams; solid.params.mass = 85.0f; - solid.params.inertia = 1e16f; + solid.params.inertia = 1e24f; solid.params.enableCollisions = false; //disable drag solid.params.dragCoefficient = 0; diff --git a/game/server/tf2/order_heal.cpp b/game/server/tf2/order_heal.cpp index 768911d5..2e6631b9 100644 --- a/game/server/tf2/order_heal.cpp +++ b/game/server/tf2/order_heal.cpp @@ -74,7 +74,7 @@ bool COrderHeal::CreateOrder( CPlayerClass *pClass ) ORDER_HEAL, pTeam->GetPlayer( sorted[0] ), pClass->GetPlayer(), - 1e16, + 1e24, 60, pOrder ); diff --git a/game/server/tf2/order_helpers.cpp b/game/server/tf2/order_helpers.cpp index 20764a3c..56274ce1 100644 --- a/game/server/tf2/order_helpers.cpp +++ b/game/server/tf2/order_helpers.cpp @@ -157,7 +157,7 @@ bool OrderCreator_ResourceZoneObject( ORDER_BUILD, pClosest, pPlayer, - 1e16, + 1e24, 60, pOrder ); diff --git a/game/server/tf2/order_killmortarguy.cpp b/game/server/tf2/order_killmortarguy.cpp index 88c729ff..ff2bdffe 100644 --- a/game/server/tf2/order_killmortarguy.cpp +++ b/game/server/tf2/order_killmortarguy.cpp @@ -95,7 +95,7 @@ bool COrderKillMortarGuy::CreateOrder( CPlayerClass *pClass ) ORDER_KILL, pBrian, pClass->GetPlayer(), - 1e16, + 1e24, 60, pOrder ); diff --git a/game/server/tf2/order_mortar_attack.cpp b/game/server/tf2/order_mortar_attack.cpp index db0888f0..1f98da36 100644 --- a/game/server/tf2/order_mortar_attack.cpp +++ b/game/server/tf2/order_mortar_attack.cpp @@ -61,7 +61,7 @@ bool COrderMortarAttack::CreateOrder( CPlayerClass *pClass ) ORDER_MORTAR_ATTACK, pEnt, pPlayer, - 1e16, + 1e24, 40, pOrder ); diff --git a/game/server/tf2/order_repair.cpp b/game/server/tf2/order_repair.cpp index 65153dcb..a75f75da 100644 --- a/game/server/tf2/order_repair.cpp +++ b/game/server/tf2/order_repair.cpp @@ -91,7 +91,7 @@ bool COrderRepair::CreateOrder_RepairFriendlyObjects( CPlayerClassDefender *pCla ORDER_REPAIR, pObjToHeal, pPlayer, - 1e16, + 1e24, 60, pOrder ); @@ -130,7 +130,7 @@ bool COrderRepair::CreateOrder_RepairOwnObjects( CPlayerClass *pClass ) ORDER_REPAIR, pObj, info.m_pPlayer, - 1e16, + 1e24, 60, pOrder ); diff --git a/game/server/tf2/tf_obj_barbed_wire.cpp b/game/server/tf2/tf_obj_barbed_wire.cpp index 341338a2..5666d362 100644 --- a/game/server/tf2/tf_obj_barbed_wire.cpp +++ b/game/server/tf2/tf_obj_barbed_wire.cpp @@ -177,7 +177,7 @@ void CObjectBarbedWire::StartPlacement( CBaseTFPlayer *pPlayer ) if ( pPlayer && !m_hConnectedTo ) { // Automatically connect to the nearest barbed wire on our team. - float flClosest = 1e16; + float flClosest = 1e24; CObjectBarbedWire *pClosest = NULL; CBaseEntity *pCur = gEntList.FirstEnt(); diff --git a/game/server/tf2/tf_playerclass.cpp b/game/server/tf2/tf_playerclass.cpp index 675f259a..51134354 100644 --- a/game/server/tf2/tf_playerclass.cpp +++ b/game/server/tf2/tf_playerclass.cpp @@ -1041,7 +1041,7 @@ void CPlayerClass::InitVCollision( void ) solid_t solid; solid.params = g_PhysDefaultObjectParams; solid.params.mass = 85.0f; - solid.params.inertia = 1e16f; + solid.params.inertia = 1e24f; solid.params.enableCollisions = false; //disable drag solid.params.dragCoefficient = 0; diff --git a/game/server/tf2/tf_team.h b/game/server/tf2/tf_team.h index e1e7f48c..1f90b656 100644 --- a/game/server/tf2/tf_team.h +++ b/game/server/tf2/tf_team.h @@ -145,7 +145,7 @@ public: int iOrderType, CBaseEntity *pTarget, CBaseTFPlayer *pPlayer = NULL, - float flDistanceToRemove = 1e16, + float flDistanceToRemove = 1e24, float flLifetime = 60, COrder *pDefaultOrder = NULL // If this is specified, then it is used instead of // asking COrder to allocate an order. diff --git a/game/shared/physics_shared.cpp b/game/shared/physics_shared.cpp index 07851584..53ede911 100644 --- a/game/shared/physics_shared.cpp +++ b/game/shared/physics_shared.cpp @@ -478,7 +478,7 @@ void PhysGetDefaultAABBSolid( solid_t &solid ) { solid.params = g_PhysDefaultObjectParams; solid.params.mass = 85.0f; - solid.params.inertia = 1e16f; + solid.params.inertia = 1e24f; Q_strncpy( solid.surfaceprop, "default", sizeof( solid.surfaceprop ) ); } diff --git a/inputsystem/inputsystem.h b/inputsystem/inputsystem.h index 7ae1e999..0b113061 100644 --- a/inputsystem/inputsystem.h +++ b/inputsystem/inputsystem.h @@ -374,7 +374,7 @@ public: m_bSkipControllerInitialization = bSkip; } - void StartTextInput(); + virtual void StartTextInput(); #if defined( USE_SDL ) void PollInputState_Platform(); diff --git a/public/bspfile.h b/public/bspfile.h index d4c3a059..680137c3 100644 --- a/public/bspfile.h +++ b/public/bspfile.h @@ -794,7 +794,10 @@ struct dfaceid_t #if defined( _X360 ) #pragma bitfield_order( push, lsb_to_msb ) #endif + +#ifdef WIN32 #pragma warning( disable:4201 ) // C4201: nonstandard extension used: nameless struct/union +#endif struct dleaf_version_0_t { DECLARE_BYTESWAP_DATADESC(); diff --git a/public/disp_common.cpp b/public/disp_common.cpp index 3072e742..0c2ac51b 100644 --- a/public/disp_common.cpp +++ b/public/disp_common.cpp @@ -770,8 +770,8 @@ void ClearNeighborData( CCoreDispInfo *pDisp ) void GetDispBox( CCoreDispInfo *pDisp, CDispBox &box ) { // Calculate the bbox for this displacement. - Vector vMin( 1e16, 1e16, 1e16 ); - Vector vMax( -1e16, -1e16, -1e16 ); + Vector vMin( 1e24, 1e24, 1e24 ); + Vector vMax( -1e24, -1e24, -1e24 ); for ( int iVert = 0; iVert < 4; ++iVert ) { diff --git a/public/inputsystem/iinputsystem.h b/public/inputsystem/iinputsystem.h index d53496ea..07bc2fe9 100644 --- a/public/inputsystem/iinputsystem.h +++ b/public/inputsystem/iinputsystem.h @@ -156,6 +156,8 @@ public: void ActivateSteamControllerActionSet( GameActionSet_t eActionSet ) { ActivateSteamControllerActionSetForSlot( 0xffffffffffffffff, eActionSet ); } + + virtual void StartTextInput() = 0; }; diff --git a/public/keyframe/keyframe.cpp b/public/keyframe/keyframe.cpp index 3c12971e..1e08b0a3 100644 --- a/public/keyframe/keyframe.cpp +++ b/public/keyframe/keyframe.cpp @@ -311,7 +311,7 @@ CPositionInterpolator_Rope::CPositionInterpolator_Rope() m_nSegments = 5; for( int i=0; i < 2; i++ ) - m_Delegate.m_CurEndPoints[i] = Vector( 1e16, 1e16, 1e16 ); + m_Delegate.m_CurEndPoints[i] = Vector( 1e24, 1e24, 1e24 ); } void CPositionInterpolator_Rope::Release() diff --git a/studiorender/r_studiodraw.cpp b/studiorender/r_studiodraw.cpp index 4d111ef5..4e6d18cd 100644 --- a/studiorender/r_studiodraw.cpp +++ b/studiorender/r_studiodraw.cpp @@ -1236,12 +1236,13 @@ public: #if !defined( _X360 ) Assert( dstVertex.m_vecUserData.w == -1.0f || dstVertex.m_vecUserData.w == 1.0f ); - // TODO(nillerusr): uncomment when i remove -mfpmath=387 from compiler options - //if ( nHasSIMD ) - //{ - // meshBuilder.FastVertexSSE( dstVertex ); - //} - //else +#if 0 // FIXME(nillerusr): causing a crash, reason: misalign? + if ( nHasSIMD ) + { + meshBuilder.FastVertexSSE( dstVertex ); + } + else +#endif { meshBuilder.FastVertex( dstVertex ); } @@ -1251,11 +1252,13 @@ public: } else { +#if 0 // FIXME(nillerusr): causing a crash, reason: misalign? if ( nHasSIMD ) { meshBuilder.FastVertexSSE( *(ModelVertexDX7_t*)&dstVertex ); } else +#endif { meshBuilder.FastVertex( *(ModelVertexDX7_t*)&dstVertex ); } diff --git a/vgui2/vgui_controls/TextEntry.cpp b/vgui2/vgui_controls/TextEntry.cpp index f98aa4c3..d5fa9179 100644 --- a/vgui2/vgui_controls/TextEntry.cpp +++ b/vgui2/vgui_controls/TextEntry.cpp @@ -1484,7 +1484,8 @@ void TextEntry::OnMousePressed(MouseCode code) return; } - g_pInputSystem->StartTextInput(); + if( IsEnabled() ) + g_pInputSystem->StartTextInput(); // move the cursor to where the mouse was pressed int x, y; diff --git a/vgui2/vgui_controls/consoledialog.cpp b/vgui2/vgui_controls/consoledialog.cpp index d788abc6..908f6aa2 100644 --- a/vgui2/vgui_controls/consoledialog.cpp +++ b/vgui2/vgui_controls/consoledialog.cpp @@ -652,6 +652,9 @@ void CConsolePanel::OnTextChanged(Panel *panel) // see if they've hit the tilde key (which opens & closes the console) int len = Q_strlen(m_szPartialText); + if( !len ) + return; + bool hitTilde = ( m_szPartialText[len - 1] == '~' || m_szPartialText[len - 1] == '`' ) ? true : false; bool altKeyDown = ( vgui::input()->IsKeyDown( KEY_LALT ) || vgui::input()->IsKeyDown( KEY_RALT ) ) ? true : false; @@ -1253,4 +1256,4 @@ void CConsoleDialog::OnKeyCodePressed( vgui::KeyCode code ) { BaseClass::OnKeyCodePressed(code); } -} \ No newline at end of file +} diff --git a/vphysics/physics_object.cpp b/vphysics/physics_object.cpp index 83dedbb2..c5838b9f 100644 --- a/vphysics/physics_object.cpp +++ b/vphysics/physics_object.cpp @@ -592,7 +592,8 @@ void CPhysicsObject::SetMass( float mass ) } Assert( mass > 0 ); - mass = clamp( mass, 0, VPHYSICS_MAX_MASS ); // NOTE: Allow zero procedurally, but not by initialization + + mass = clamp( mass, 1.f, VPHYSICS_MAX_MASS ); m_pObject->change_mass( mass ); SetVolume( m_volume ); RecomputeDragBases(); @@ -633,13 +634,17 @@ Vector CPhysicsObject::GetInvInertia( void ) const } + void CPhysicsObject::SetInertia( const Vector &inertia ) { - IVP_U_Float_Point ri; - ConvertDirectionToIVP( inertia, ri ); + IVP_U_Float_Point ri; ConvertDirectionToIVP( inertia, ri ); ri.k[0] = IVP_Inline_Math::fabsd(ri.k[0]); ri.k[1] = IVP_Inline_Math::fabsd(ri.k[1]); ri.k[2] = IVP_Inline_Math::fabsd(ri.k[2]); + + if( ri.k[0] > 1e14f ) ri.k[0] = 1e14f; if( ri.k[1] > 1e14f ) ri.k[1] = 1e14f; if( ri.k[2] > 1e14f ) ri.k[2] = 1e14f; + if( ri.k[0] <= 0 ) ri.k[0] = 1.f; if( ri.k[1] <= 0 ) ri.k[1] = 1.f; if( ri.k[2] <= 0 ) ri.k[2] = 1.f; + m_pObject->get_core()->set_rotation_inertia( &ri ); } @@ -1358,6 +1363,7 @@ bool CPhysicsObject::IsFluid() const // sets the object to be hinged. Fixed it place, but able to rotate around one axis. void CPhysicsObject::BecomeHinged( int localAxis ) { + if ( IsMoveable() ) { float savedMass = GetMass(); @@ -1370,6 +1376,7 @@ void CPhysicsObject::BecomeHinged( int localAxis ) SetMass( VPHYSICS_MAX_MASS ); IVP_U_Float_Hesse tmp = *iri; + #if 0 for ( i = 0; i < 3; i++ ) tmp.k[i] = savedRI[i]; @@ -1394,10 +1401,10 @@ void CPhysicsObject::RemoveHinged() void CPhysicsObject::OutputDebugInfo() const { Msg("-----------------\nObject: %s\n", m_pObject->get_name()); - Msg("Mass: %.1f (inv %.3f)\n", GetMass(), GetInvMass() ); + Msg("Mass: %.3e (inv %.3e)\n", GetMass(), GetInvMass() ); Vector inertia = GetInertia(); Vector invInertia = GetInvInertia(); - Msg("Inertia: %.2f, %.2f, %.2f (inv %.3f, %.3f, %.3f)\n", inertia.x, inertia.y, inertia.z, invInertia.x, invInertia.y, invInertia.z ); + Msg("Inertia: %.3e, %.3e, %.3e (inv %.3e, %.3e, %.3e)\n", inertia.x, inertia.y, inertia.z, invInertia.x, invInertia.y, invInertia.z ); Vector speed, angSpeed; GetVelocity( &speed, &angSpeed ); @@ -1406,7 +1413,7 @@ void CPhysicsObject::OutputDebugInfo() const float damp, angDamp; GetDamping( &damp, &angDamp ); - Msg("Damping %.2f linear, %.2f angular\n", damp, angDamp ); + Msg("Damping %.3e linear, %.3e angular\n", damp, angDamp ); Msg("Linear Drag: %.2f, %.2f, %.2f (factor %.2f)\n", m_dragBasis.x, m_dragBasis.y, m_dragBasis.z, m_dragCoefficient ); Msg("Angular Drag: %.2f, %.2f, %.2f (factor %.2f)\n", m_angDragBasis.x, m_angDragBasis.y, m_angDragBasis.z, m_angDragCoefficient ); @@ -1462,8 +1469,7 @@ bool CPhysicsObject::IsAttachedToConstraint( bool bExternalOnly ) const static void InitObjectTemplate( IVP_Template_Real_Object &objectTemplate, int materialIndex, objectparams_t *pParams, bool isStatic ) { - objectTemplate.mass = pParams->mass; - objectTemplate.mass = clamp( objectTemplate.mass, VPHYSICS_MIN_MASS, VPHYSICS_MAX_MASS ); + objectTemplate.mass = clamp( pParams->mass, VPHYSICS_MIN_MASS, VPHYSICS_MAX_MASS ); if ( materialIndex >= 0 ) { @@ -1495,8 +1501,8 @@ static void InitObjectTemplate( IVP_Template_Real_Object &objectTemplate, int ma if ( inertia <= 0 ) inertia = 1.0; - if ( inertia > 1e18f ) - inertia = 1e18f; + if ( inertia > 1e14f ) + inertia = 1e14f; objectTemplate.rot_inertia.set(inertia, inertia, inertia); objectTemplate.rot_speed_damp_factor.set(pParams->rotdamping, pParams->rotdamping, pParams->rotdamping); diff --git a/vphysics/physics_shadow.cpp b/vphysics/physics_shadow.cpp index 07c4acf9..fa80cd9c 100644 --- a/vphysics/physics_shadow.cpp +++ b/vphysics/physics_shadow.cpp @@ -1052,7 +1052,7 @@ void CShadowController::AttachObject( void ) if ( !m_allowsRotation ) { - IVP_U_Float_Point ri( 1e15f, 1e15f, 1e15f ); + IVP_U_Float_Point ri( 1e14f, 1e14f, 1e14f ); pCore->set_rotation_inertia( &ri ); } if ( !m_allowsTranslation ) diff --git a/vphysics/vcollide_parse.cpp b/vphysics/vcollide_parse.cpp index aa6f772f..527e1865 100644 --- a/vphysics/vcollide_parse.cpp +++ b/vphysics/vcollide_parse.cpp @@ -174,7 +174,13 @@ void CVPhysicsParse::ParseSolid( solid_t *pSolid, IVPhysicsKeyHandler *unknownKe } else if ( !Q_stricmp( key, "inertia" ) ) { - pSolid->params.inertia = atof(value); + float inertia = atof(value); + if( inertia > 1e14f ) + pSolid->params.inertia = 1e14f; + else if( inertia <= 0 ) + pSolid->params.inertia = 1.f; + else + pSolid->params.inertia = inertia; } else if ( !Q_stricmp( key, "damping" ) ) { @@ -468,7 +474,13 @@ void CVPhysicsParse::ParseVehicleWheel( vehicle_wheelparams_t &wheel ) } else if ( !Q_stricmp( key, "inertia" ) ) { - wheel.inertia = atof( value ); + float inertia = atof(value); + if( inertia > 1e14f ) + wheel.inertia = 1e14f; + else if( inertia <= 0 ) + wheel.inertia = 1.f; + else + wheel.inertia = inertia; } else if ( !Q_stricmp( key, "damping" ) ) {