MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / _updateContainerForces

Method _updateContainerForces

Engine/source/T3D/physics/physicsShape.cpp:1000–1049  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

998}
999
1000void PhysicsShape::_updateContainerForces()
1001{
1002 PROFILE_SCOPE( PhysicsShape_updateContainerForces );
1003
1004 // If we're not simulating don't update forces.
1005 if ( !mWorld->isEnabled() )
1006 return;
1007
1008 ContainerQueryInfo info;
1009 info.box = getWorldBox();
1010 info.mass = getDataBlock()->mass;
1011
1012 // Find and retreive physics info from intersecting WaterObject(s)
1013 getContainer()->findObjects( getWorldBox(), WaterObjectType|PhysicalZoneObjectType, findRouter, &info );
1014
1015 // Calculate buoyancy and drag
1016 F32 angDrag = getDataBlock()->angularDamping;
1017 F32 linDrag = getDataBlock()->linearDamping;
1018 F32 buoyancy = 0.0f;
1019 Point3F cmass = mPhysicsRep->getCMassPosition();
1020
1021 F32 density = getDataBlock()->buoyancyDensity;
1022 if ( density > 0.0f )
1023 {
1024 if ( info.waterCoverage > 0.0f )
1025 {
1026 F32 waterDragScale = info.waterViscosity * getDataBlock()->waterDampingScale;
1027 F32 powCoverage = mPow( info.waterCoverage, 0.25f );
1028
1029 angDrag = mLerp( angDrag, angDrag * waterDragScale, powCoverage );
1030 linDrag = mLerp( linDrag, linDrag * waterDragScale, powCoverage );
1031 }
1032
1033 buoyancy = ( info.waterDensity / density ) * mPow( info.waterCoverage, 2.0f );
1034
1035 // A little hackery to prevent oscillation
1036 // Based on this blog post:
1037 // (http://reinot.blogspot.com/2005/11/oh-yes-they-float-georgie-they-all.html)
1038 // JCF: disabled!
1039 Point3F buoyancyForce = buoyancy * -mWorld->getGravity() * TickSec * getDataBlock()->mass;
1040 mPhysicsRep->applyImpulse( cmass, buoyancyForce );
1041 }
1042
1043 // Update the dampening as the container might have changed.
1044 mPhysicsRep->setDamping( linDrag, angDrag );
1045
1046 // Apply physical zone forces.
1047 if ( !info.appliedForce.isZero() )
1048 mPhysicsRep->applyImpulse( cmass, info.appliedForce );
1049}
1050
1051void PhysicsShape::prepRenderImage( SceneRenderState *state )
1052{

Callers

nothing calls this directly

Calls 10

mPowFunction · 0.85
mLerpFunction · 0.85
findObjectsMethod · 0.80
getContainerFunction · 0.50
isEnabledMethod · 0.45
getCMassPositionMethod · 0.45
getGravityMethod · 0.45
applyImpulseMethod · 0.45
setDampingMethod · 0.45
isZeroMethod · 0.45

Tested by

no test coverage detected