Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constraints: Implemented pulley #214

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ It is not meant to be a bash on anyone elses work however, the Bullet VPhysics p
| Feature | VPhysics | Volt (VPhysics Jolt) | Bullet VPhysics |
|:--------------|:--------:|:-------------:|:---------------:|
| Constraints (except Pulleys) | ✔️ | ✔️ | ✔️ |
| Pulleys | ✔️ | | ❌ |
| Pulleys | ✔️ | ✔️ | ❌ |
| Breakable constraints | ✔️ | ❌ | ❌ |
| Motors (Motion Controllers) | ✔️ | ✔️ | ✔️ |
| Motors (Constraint) | ✔️ | ✔️ | ❌ |
Expand Down
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 @@ -631,8 +631,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
Loading