Skip to content

Commit

Permalink
constraints: Implemented pulley
Browse files Browse the repository at this point in the history
  • Loading branch information
PiMoNFeeD authored and misyltoad committed Aug 15, 2024
1 parent 8afe4c9 commit 25fa7b3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions vphysics_jolt/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
#include <Jolt/Physics/Constraints/SixDOFConstraint.h>
#include <Jolt/Physics/Constraints/DistanceConstraint.h>
#include <Jolt/Physics/Constraints/SliderConstraint.h>
#include <Jolt/Physics/Constraints/PulleyConstraint.h>
#include <Jolt/Physics/Vehicle/VehicleConstraint.h>
#include <Jolt/Physics/Vehicle/VehicleCollisionTester.h>
#include <Jolt/Physics/Vehicle/WheeledVehicleController.h>
Expand Down
33 changes: 33 additions & 0 deletions vphysics_jolt/vjolt_constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,39 @@ void JoltPhysicsConstraint::InitialiseLength( IPhysicsConstraintGroup *pGroup, c
m_pPhysicsSystem->AddConstraint( m_pConstraint );
}

//-------------------------------------------------------------------------------------------------
// Pulley
//-------------------------------------------------------------------------------------------------

void JoltPhysicsConstraint::InitialisePulley( IPhysicsConstraintGroup *pGroup, const constraint_pulleyparams_t &pulley )
{
SetGroup( pGroup );
m_ConstraintType = CONSTRAINT_PULLEY;

// Get our bodies
JPH::Body* refBody = m_pObjReference->GetBody();
JPH::Body* attBody = m_pObjAttached->GetBody();

JPH::PulleyConstraintSettings settings;
settings.mNumVelocityStepsOverride = vjolt_constraint_velocity_substeps.GetInt();
settings.mNumPositionStepsOverride = vjolt_constraint_position_substeps.GetInt();
settings.mSpace = JPH::EConstraintSpace::LocalToBodyCOM;
settings.mBodyPoint1 = SourceToJolt::Distance( pulley.objectPosition[0] ) - refBody->GetShape()->GetCenterOfMass();
settings.mBodyPoint2 = SourceToJolt::Distance( pulley.objectPosition[1] ) - attBody->GetShape()->GetCenterOfMass();

settings.mFixedPoint1 = SourceToJolt::Distance( pulley.pulleyPosition[0] );
settings.mFixedPoint2 = SourceToJolt::Distance( pulley.pulleyPosition[1] );

settings.mRatio = pulley.gearRatio;

settings.mMaxLength = SourceToJolt::Distance( pulley.totalLength ); // PiMoN: from my testing, it is the same value as Jolt would calculate automatically

m_pConstraint = settings.Create( *refBody, *attBody );
m_pConstraint->SetEnabled( !pGroup && pulley.constraint.isActive );

m_pPhysicsSystem->AddConstraint( m_pConstraint );
}

//-------------------------------------------------------------------------------------------------

void JoltPhysicsConstraint::SaveConstraintSettings( JPH::StateRecorder &recorder )
Expand Down
1 change: 1 addition & 0 deletions vphysics_jolt/vjolt_constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class JoltPhysicsConstraint final : public IPhysicsConstraint, public IJoltObjec
void InitialiseBallsocket( IPhysicsConstraintGroup *pGroup, const constraint_ballsocketparams_t &ballsocket );
void InitialiseFixed( IPhysicsConstraintGroup *pGroup, const constraint_fixedparams_t &fixed );
void InitialiseLength( IPhysicsConstraintGroup *pGroup, const constraint_lengthparams_t &length );
void InitialisePulley( IPhysicsConstraintGroup *pGroup, const constraint_pulleyparams_t &pulley );

void SaveConstraintSettings( JPH::StateRecorder &recorder );

Expand Down
5 changes: 3 additions & 2 deletions vphysics_jolt/vjolt_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,9 @@ IPhysicsConstraint *JoltPhysicsEnvironment::CreateBallsocketConstraint( IPhysics

IPhysicsConstraint *JoltPhysicsEnvironment::CreatePulleyConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_pulleyparams_t &pulley )
{
Log_Stub( LOG_VJolt );
return nullptr;
JoltPhysicsConstraint *pConstraint = new JoltPhysicsConstraint( this, pReferenceObject, pAttachedObject );
pConstraint->InitialisePulley( pGroup, pulley );
return pConstraint;
}

IPhysicsConstraint *JoltPhysicsEnvironment::CreateLengthConstraint( IPhysicsObject *pReferenceObject, IPhysicsObject *pAttachedObject, IPhysicsConstraintGroup *pGroup, const constraint_lengthparams_t &length )
Expand Down

0 comments on commit 25fa7b3

Please sign in to comment.