Skip to content

Commit

Permalink
adding chaos physics scalers to constraint drive fill operations now
Browse files Browse the repository at this point in the history
  • Loading branch information
mordentral committed Apr 10, 2024
1 parent 4e88468 commit 7bda72c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "VRBPDatatypes.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(VRBPDatatypes)

#include "VRGlobalSettings.h"
#include "HAL/IConsoleManager.h"
#include "Chaos/ChaosEngineInterface.h"

Expand Down Expand Up @@ -219,3 +220,53 @@ FTransform FBPEuroLowPassFilterTrans::RunFilterSmoothing(const FTransform& InRaw
// Filter passed value
return NewTrans;
}

bool FBPAdvancedPhysicsHandleSettings::FillTo(FBPActorPhysicsHandleInformation* HandleInfo, bool bModifyWithScalers) const
{
if (!HandleInfo)
return false;

float DampingMod = 0.0f;
float StiffnessMod = 0.0f;
float ADampingMod = 0.0f;
float AStiffnessMod = 0.0f;
const UVRGlobalSettings& VRSettings = *GetDefault<UVRGlobalSettings>();

if (VRSettings.bUseChaosTranslationScalers)
{
StiffnessMod = VRSettings.LinearDriveStiffnessScale;
DampingMod = VRSettings.LinearDriveDampingScale;
AStiffnessMod = VRSettings.AngularDriveStiffnessScale;
ADampingMod = VRSettings.AngularDriveDampingScale;
}
else
{
auto CVarLinearDriveStiffnessScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.LinearDriveStiffnessScale"));
auto CVarLinearDriveDampingScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.LinaearDriveDampingScale"));
auto CVarAngularDriveStiffnessScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.AngularDriveStiffnessScale"));
auto CVarAngularDriveDampingScale = IConsoleManager::Get().FindConsoleVariable(TEXT("p.Chaos.JointConstraint.AngularDriveDampingScale"));

StiffnessMod = CVarLinearDriveStiffnessScale->GetFloat();
DampingMod = CVarLinearDriveDampingScale->GetFloat();
AStiffnessMod = CVarAngularDriveStiffnessScale->GetFloat();
ADampingMod = CVarAngularDriveDampingScale->GetFloat();
}

XAxisSettings.FillTo(HandleInfo->LinConstraint.XDrive, DampingMod, StiffnessMod);
YAxisSettings.FillTo(HandleInfo->LinConstraint.YDrive, DampingMod, StiffnessMod);
ZAxisSettings.FillTo(HandleInfo->LinConstraint.ZDrive, DampingMod, StiffnessMod);

if ((SlerpSettings.bEnablePositionDrive || SlerpSettings.bEnableVelocityDrive))
{
HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::SLERP;
SlerpSettings.FillTo(HandleInfo->AngConstraint.SlerpDrive, ADampingMod, AStiffnessMod);
}
else
{
HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::TwistAndSwing;
TwistSettings.FillTo(HandleInfo->AngConstraint.TwistDrive, ADampingMod, AStiffnessMod);
SwingSettings.FillTo(HandleInfo->AngConstraint.SwingDrive, ADampingMod, AStiffnessMod);
}

return true;
}
32 changes: 5 additions & 27 deletions VRExpansionPlugin/Source/VRExpansionPlugin/Public/VRBPDatatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1868,11 +1868,11 @@ struct VREXPANSIONPLUGIN_API FBPAdvancedPhysicsHandleAxisSettings
bEnableVelocityDrive = ConstraintDrive.bEnableVelocityDrive;
}

void FillTo(FConstraintDrive& ConstraintDrive) const
void FillTo(FConstraintDrive& ConstraintDrive, float DampingScaler = 1.0f, float StiffnessScaler = 1.0f) const
{
ConstraintDrive.Damping = Damping;
ConstraintDrive.Stiffness = Stiffness;
ConstraintDrive.MaxForce = MaxForceCoefficient * Stiffness;
ConstraintDrive.Damping = Damping * DampingScaler;
ConstraintDrive.Stiffness = Stiffness * StiffnessScaler;
ConstraintDrive.MaxForce = (float)FMath::Clamp<double>((double)ConstraintDrive.Stiffness * (double)MaxForceCoefficient, 0, (double)MAX_FLT);
ConstraintDrive.bEnablePositionDrive = bEnablePositionDrive;
ConstraintDrive.bEnableVelocityDrive = bEnableVelocityDrive;
}
Expand Down Expand Up @@ -1929,27 +1929,5 @@ struct VREXPANSIONPLUGIN_API FBPAdvancedPhysicsHandleSettings
return true;
}

bool FillTo(FBPActorPhysicsHandleInformation* HandleInfo) const
{
if (!HandleInfo)
return false;

XAxisSettings.FillTo(HandleInfo->LinConstraint.XDrive);
YAxisSettings.FillTo(HandleInfo->LinConstraint.YDrive);
ZAxisSettings.FillTo(HandleInfo->LinConstraint.ZDrive);

if ((SlerpSettings.bEnablePositionDrive || SlerpSettings.bEnableVelocityDrive))
{
HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::SLERP;
SlerpSettings.FillTo(HandleInfo->AngConstraint.SlerpDrive);
}
else
{
HandleInfo->AngConstraint.AngularDriveMode = EAngularDriveMode::TwistAndSwing;
TwistSettings.FillTo(HandleInfo->AngConstraint.TwistDrive);
SwingSettings.FillTo(HandleInfo->AngConstraint.SwingDrive);
}

return true;
}
bool FillTo(FBPActorPhysicsHandleInformation* HandleInfo, bool bModifyWithScalers = true) const;
};

0 comments on commit 7bda72c

Please sign in to comment.