Skip to content

Commit

Permalink
few minor tweaks
Browse files Browse the repository at this point in the history
-made rebuild skeletons the first update call
-moving inline function to cpp code. makes it less complex when integration with this party engines.
-added the self collision option for skeletons. defaulting to not colliding,
in general is batter to make skeleton non collidable and select the bones we want self colliding
  • Loading branch information
JulioJerez committed Dec 24, 2024
1 parent df300a2 commit 1b2d5b2
Show file tree
Hide file tree
Showing 11 changed files with 518 additions and 463 deletions.
16 changes: 8 additions & 8 deletions newton-4.00/applications/ndSandbox/demos/ndBasicJoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,16 +915,16 @@ void ndBasicJoints (ndDemoEntityManager* const scene)
// build a floor
BuildFloorBox(scene, ndGetIdentityMatrix());

//BuildBallSocket(scene, ndVector(0.0f, 0.0f, -7.0f, 1.0f));
BuildBallSocket(scene, ndVector(0.0f, 0.0f, -7.0f, 1.0f));
BuildHinge(scene, ndVector(0.0f, 0.0f, -2.0f, 1.0f), 10.0f, 1.0f);
BuildSlider(scene, ndVector(0.0f, 0.0f, 1.0f, 1.0f), 100.0f, 0.75f);
//BuildGear(scene, ndVector(0.0f, 0.0f, -4.0f, 1.0f), 100.0f, 0.75f);
//BuildDoubleHinge(scene, ndVector(0.0f, 0.0f, 4.0f, 1.0f), 100.0f, 0.75f);
//BuildRoller(scene, ndVector(0.0f, 0.0f, 9.0f, 1.0f), 10.0f, 0.75f);
//BuildCylindrical(scene, ndVector(0.0f, 0.0f, 12.0f, 1.0f), 10.0f, 0.75f);
//BuildFixDistanceJoints(scene, ndVector( 4.0f, 0.0f, -5.0f, 1.0f));
//BuildRollingFriction(scene, ndVector(-4.0f, 0.0f, 0.0f, 1.0f), 10.0f, 0.5f);
//BuildPathFollow(scene, ndVector(40.0f, 0.0f, 0.0f, 1.0f));
BuildGear(scene, ndVector(0.0f, 0.0f, -4.0f, 1.0f), 100.0f, 0.75f);
BuildDoubleHinge(scene, ndVector(0.0f, 0.0f, 4.0f, 1.0f), 100.0f, 0.75f);
BuildRoller(scene, ndVector(0.0f, 0.0f, 9.0f, 1.0f), 10.0f, 0.75f);
BuildCylindrical(scene, ndVector(0.0f, 0.0f, 12.0f, 1.0f), 10.0f, 0.75f);
BuildFixDistanceJoints(scene, ndVector( 4.0f, 0.0f, -5.0f, 1.0f));
BuildRollingFriction(scene, ndVector(-4.0f, 0.0f, 0.0f, 1.0f), 10.0f, 0.5f);
BuildPathFollow(scene, ndVector(40.0f, 0.0f, 0.0f, 1.0f));

ndQuaternion rot;
ndVector origin(-20.0f, 5.0f, 0.0f, 1.0f);
Expand Down
72 changes: 72 additions & 0 deletions newton-4.00/sdk/dCollision/ndBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ndBody::ndBody()
,m_isConstrained(0)
,m_sceneForceUpdate(1)
,m_sceneEquilibrium(0)
,m_skeletonSelfCollision(0)
{
m_uniqueIdCount++;
m_transformIsDirty = 1;
Expand Down Expand Up @@ -96,6 +97,77 @@ ndBody::~ndBody()
}
}

bool ndBody::GetSeletonSelfCollision() const
{
return m_skeletonSelfCollision ? true : false;
}

void ndBody::SetSeletonSelfCollision(bool state)
{
m_skeletonSelfCollision = state ? 1 : 0;
}

ndUnsigned32 ndBody::GetId() const
{
return m_uniqueId;
}

ndBodyNotify* ndBody::GetNotifyCallback() const
{
return m_notifyCallback;
}

ndMatrix ndBody::GetMatrix() const
{
return m_matrix;
}

ndVector ndBody::GetPosition() const
{
return m_matrix.m_posit;
}

ndQuaternion ndBody::GetRotation() const
{
return m_rotation;
}

ndVector ndBody::GetGlobalGetCentreOfMass() const
{
return m_globalCentreOfMass;
}

ndVector ndBody::GetVelocity() const
{
return m_veloc;
}

ndVector ndBody::GetOmega() const
{
return m_omega;
}

void ndBody::GetAABB(ndVector& p0, ndVector& p1) const
{
p0 = m_minAabb;
p1 = m_maxAabb;
}

const ndVector& ndBody::GetCentreOfMass() const
{
return m_localCentreOfMass;
}

ndVector ndBody::GetVelocityAtPoint(const ndVector& point) const
{
return m_veloc + m_omega.CrossProduct(point - m_globalCentreOfMass);
}

ndFloat32 ndBody::GetInvMass() const
{
return ndFloat32(0.0f);
}

void ndBody::SetCentreOfMass(const ndVector& com)
{
m_localCentreOfMass.m_x = com.m_x;
Expand Down
92 changes: 17 additions & 75 deletions newton-4.00/sdk/dCollision/ndBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,26 @@ class ndBody : public ndContainersFreeListAlloc<ndBody>
virtual ndBodyTriggerVolume* GetAsBodyTriggerVolume() { return nullptr; }
virtual ndBodyKinematicBase* GetAsBodyKinematicSpecial() { return nullptr; }

ndUnsigned32 GetId() const;
void GetAABB(ndVector& p0, ndVector& p1) const;
D_COLLISION_API ndUnsigned32 GetId() const;
D_COLLISION_API void GetAABB(ndVector& p0, ndVector& p1) const;

virtual ndFloat32 GetInvMass() const;
virtual bool RayCast(ndRayCastNotify& callback, const ndFastRay& ray, const ndFloat32 maxT) const = 0;
D_COLLISION_API bool GetSeletonSelfCollision() const;
D_COLLISION_API void SetSeletonSelfCollision(bool state);

const ndVector& GetCentreOfMass() const;
D_COLLISION_API virtual ndFloat32 GetInvMass() const;
D_COLLISION_API virtual bool RayCast(ndRayCastNotify& callback, const ndFastRay& ray, const ndFloat32 maxT) const = 0;

D_COLLISION_API const ndVector& GetCentreOfMass() const;
D_COLLISION_API virtual void SetCentreOfMass(const ndVector& com);

ndVector GetOmega() const;
ndMatrix GetMatrix() const;
ndVector GetVelocity() const;
ndVector GetPosition() const;
ndQuaternion GetRotation() const;
ndVector GetGlobalGetCentreOfMass() const;

ndBodyNotify* GetNotifyCallback() const;
D_COLLISION_API ndVector GetOmega() const;
D_COLLISION_API ndMatrix GetMatrix() const;
D_COLLISION_API ndVector GetVelocity() const;
D_COLLISION_API ndVector GetPosition() const;
D_COLLISION_API ndQuaternion GetRotation() const;
D_COLLISION_API ndVector GetGlobalGetCentreOfMass() const;

D_COLLISION_API ndBodyNotify* GetNotifyCallback() const;
D_COLLISION_API virtual void SetNotifyCallback(ndBodyNotify* const notify);
D_COLLISION_API virtual void SetOmega(const ndVector& veloc);
D_COLLISION_API virtual void SetVelocity(const ndVector& veloc);
Expand Down Expand Up @@ -128,6 +131,7 @@ class ndBody : public ndContainersFreeListAlloc<ndBody>
ndUnsigned8 m_isConstrained;
ndUnsigned8 m_sceneForceUpdate;
ndUnsigned8 m_sceneEquilibrium;
ndUnsigned8 m_skeletonSelfCollision;

D_COLLISION_API static ndUnsigned32 m_uniqueIdCount;

Expand All @@ -137,67 +141,5 @@ class ndBody : public ndContainersFreeListAlloc<ndBody>
friend class ndBodyPlayerCapsuleImpulseSolver;
} D_GCC_NEWTON_ALIGN_32;

inline ndUnsigned32 ndBody::GetId() const
{
return m_uniqueId;
}

inline ndBodyNotify* ndBody::GetNotifyCallback() const
{
return m_notifyCallback;
}

inline ndMatrix ndBody::GetMatrix() const
{
return m_matrix;
}

inline ndVector ndBody::GetPosition() const
{
return m_matrix.m_posit;
}

inline ndQuaternion ndBody::GetRotation() const
{
return m_rotation;
}

inline ndVector ndBody::GetGlobalGetCentreOfMass() const
{
return m_globalCentreOfMass;
}

inline ndVector ndBody::GetVelocity() const
{
return m_veloc;
}

inline ndVector ndBody::GetOmega() const
{
return m_omega;
}

inline void ndBody::GetAABB(ndVector& p0, ndVector& p1) const
{
p0 = m_minAabb;
p1 = m_maxAabb;
}

inline const ndVector& ndBody::GetCentreOfMass() const
{
return m_localCentreOfMass;
}

inline ndVector ndBody::GetVelocityAtPoint(const ndVector& point) const
{
return m_veloc + m_omega.CrossProduct(point - m_globalCentreOfMass);
}

inline ndFloat32 ndBody::GetInvMass() const
{
return ndFloat32(0.0f);
}


#endif

Loading

0 comments on commit 1b2d5b2

Please sign in to comment.