34 if (!ConstraintInstance.ConstraintHandle.ConstraintData)
37 PxD6JointDriveFlags JointFlags;
38 if (!bUseForceConstraint)
39 JointFlags = PxD6JointDriveFlag::eACCELERATION;
42 PxD6JointDrive driveVal = ConstraintInstance.ConstraintHandle.ConstraintData->getDrive(PxD6Drive::Enum::eX);
43 driveVal.flags = JointFlags;
44 ConstraintInstance.ConstraintHandle.ConstraintData->setDrive(PxD6Drive::Enum::eX, driveVal);
46 driveVal = ConstraintInstance.ConstraintHandle.ConstraintData->getDrive(PxD6Drive::Enum::eY);
47 driveVal.flags = JointFlags;
48 ConstraintInstance.ConstraintHandle.ConstraintData->setDrive(PxD6Drive::Enum::eY, driveVal);
50 driveVal = ConstraintInstance.ConstraintHandle.ConstraintData->getDrive(PxD6Drive::Enum::eZ);
51 driveVal.flags = JointFlags;
52 ConstraintInstance.ConstraintHandle.ConstraintData->setDrive(PxD6Drive::Enum::eZ, driveVal);
55 if (ConstraintInstance.ProfileInstance.AngularDrive.AngularDriveMode == EAngularDriveMode::SLERP)
57 driveVal = ConstraintInstance.ConstraintHandle.ConstraintData->getDrive(PxD6Drive::Enum::eSLERP);
58 driveVal.flags = JointFlags;
59 ConstraintInstance.ConstraintHandle.ConstraintData->setDrive(PxD6Drive::Enum::eSLERP, driveVal);
63 driveVal = ConstraintInstance.ConstraintHandle.ConstraintData->getDrive(PxD6Drive::Enum::eSWING);
64 driveVal.flags = JointFlags;
65 ConstraintInstance.ConstraintHandle.ConstraintData->setDrive(PxD6Drive::Enum::eSWING, driveVal);
67 driveVal = ConstraintInstance.ConstraintHandle.ConstraintData->getDrive(PxD6Drive::Enum::eTWIST);
68 driveVal.flags = JointFlags;
69 ConstraintInstance.ConstraintHandle.ConstraintData->setDrive(PxD6Drive::Enum::eTWIST, driveVal);
74 if (!ConstraintInstance.ConstraintHandle.IsValid())
77 if (ConstraintInstance.ConstraintHandle->IsType(Chaos::EConstraintType::JointConstraintType))
79 if (Chaos::FJointConstraint* Constraint =
static_cast<Chaos::FJointConstraint*
>(ConstraintInstance.ConstraintHandle.Constraint))
81 Constraint->SetLinearDriveForceMode(bUseForceConstraint ? Chaos::EJointForceMode::Force : Chaos::EJointForceMode::Acceleration);
82 Constraint->SetAngularDriveForceMode(bUseForceConstraint ? Chaos::EJointForceMode::Force : Chaos::EJointForceMode::Acceleration);
91 UFUNCTION(BlueprintCallable, Category =
"VRE Physics Constraint Component")
92 void GetConstraintReferenceFrame(EConstraintFrame::Type Frame, FTransform& RefFrame)
104 return FTransform(ConstraintInstance.PriAxis1, ConstraintInstance.SecAxis1, ConstraintInstance.PriAxis1 ^ ConstraintInstance.SecAxis1, ConstraintInstance.Pos1);
108 return FTransform(ConstraintInstance.PriAxis2, ConstraintInstance.SecAxis2, ConstraintInstance.PriAxis2 ^ ConstraintInstance.SecAxis2, ConstraintInstance.Pos2);
113 return FTransform::Identity;
116 UFUNCTION(BlueprintCallable, Category =
"VRE Physics Constraint Component")
117 void GetGlobalPose(EConstraintFrame::Type ConstraintFrame, FTransform& GlobalPose)
119 if (ConstraintInstance.IsValidConstraintInstance())
121 GlobalPose = FPhysicsInterface::GetGlobalPose(ConstraintInstance.ConstraintHandle, ConstraintFrame);
124 GlobalPose = FTransform::Identity;
131 EConstraintFrame::Type Frame2 = FrameOfReference;
132 EConstraintFrame::Type Frame1 = (FrameOfReference == EConstraintFrame::Frame1) ? EConstraintFrame::Frame2 : EConstraintFrame::Frame1;
134 FTransform Frame1Trans = this->GetBodyTransform(Frame1);
135 FTransform Frame2Trans = this->GetBodyTransform(Frame2);
137 FTransform LocalPose = GetLocalPose(Frame1);
138 FTransform LocalPose2 = GetLocalPose(Frame2);
151 UFUNCTION(BlueprintPure, Category =
"VRE Physics Constraint Component")
152 FRotator GetAngularOffset()
154 return ConstraintInstance.AngularRotationOffset;
158 UFUNCTION(BlueprintCallable, Category=
"VRE Physics Constraint Component")
159 void SetAngularOffset(FRotator NewAngularOffset)
164 if (!ConstraintInstance.IsValidConstraintInstance() || ConstraintInstance.IsBroken())
183 FTransform A2Transform = GetBodyTransform(EConstraintFrame::Frame2);
184 A2Transform.RemoveScaling();
186 FTransform CurrentLocalFrame(ConstraintInstance.PriAxis2, ConstraintInstance.SecAxis2, ConstraintInstance.PriAxis2 ^ ConstraintInstance.SecAxis2, ConstraintInstance.Pos2);
187 FTransform WorldLocalFrame = (CurrentLocalFrame * A2Transform);
189 FVector WPri21 = GetComponentTransform().TransformVectorNoScale(AngRotOffset.GetForwardVector());
190 FVector WOrth21 = GetComponentTransform().TransformVectorNoScale(AngRotOffset.GetRightVector());
192 FTransform OriginalRotOffset(WPri21, WOrth21, WPri21 ^ WOrth21, FVector::ZeroVector);
193 FQuat DeltaRot = WorldLocalFrame.GetRotation() * OriginalRotOffset.GetRotation().Inverse();
194 DeltaRot.Normalize();
196 FVector WPri2 = GetComponentTransform().TransformVectorNoScale(newAngRotOffset.GetForwardVector());
197 FVector WOrth2 = GetComponentTransform().TransformVectorNoScale(newAngRotOffset.GetRightVector());
199 WPri2 = DeltaRot.RotateVector(WPri2);
200 WOrth2 = DeltaRot.RotateVector(WOrth2);
202 ConstraintInstance.PriAxis2 = A2Transform.InverseTransformVectorNoScale(WPri2);
203 ConstraintInstance.SecAxis2 = A2Transform.InverseTransformVectorNoScale(WOrth2);
204 ConstraintInstance.AngularRotationOffset = NewAngularOffset;
206 FPhysicsInterface::ExecuteOnUnbrokenConstraintReadWrite(ConstraintInstance.ConstraintHandle, [&](
const FPhysicsConstraintHandle& InUnbrokenConstraint)
208 FTransform URefTransform = FTransform(ConstraintInstance.PriAxis2, ConstraintInstance.SecAxis2, ConstraintInstance.PriAxis2 ^ ConstraintInstance.SecAxis2, RefPos);
209 FPhysicsInterface::SetLocalPose(InUnbrokenConstraint, URefTransform, EConstraintFrame::Frame2);