-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRagdollJoint.cpp
More file actions
106 lines (89 loc) · 4.11 KB
/
Copy pathRagdollJoint.cpp
File metadata and controls
106 lines (89 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "RagdollJoint.h"
#include "PhysicsMathAdapter.h"
#include <mathematics/transform.hpp>
bool RagdollJoint::Initialize(RagdollLink* paranthLink,RagdollLink* ownerLink, const JointInfo& info)
{
m_parentLink = paranthLink;
m_OwnerLink = ownerLink;
m_localTransform = info.localTransform;
m_xLimit.high = info.xAxisInfo.limitHigh;
m_xLimit.low = info.xAxisInfo.limitlow;
m_yLimit.high = info.yAxisInfo.limitHigh;
m_yLimit.low = info.yAxisInfo.limitlow;
m_zLimit.high = info.zAxisInfo.limitHigh;
m_zLimit.low = info.zAxisInfo.limitlow;
m_drive.damping = info.damping;
m_drive.maxForce = info.maxForce;
m_drive.stiffness = info.stiffness;
m_drive.driveType = physx::PxArticulationDriveType::eFORCE;
m_pxJoint = ownerLink->GetPxLink()->getInboundJoint();
m_pxJoint->setMaxJointVelocity(5.0f);
m_pxJoint->setFrictionCoefficient(0.1f);
math::vector3 scale{};
math::quaternion rotation{};
math::vector3 position{};
(void)math::decompose(m_localTransform, scale, rotation, position);
m_localTransform = math::compose(scale, rotation, position);
const physx::PxTransform pxLocalTransform =
PhysicsMath::ToPxTransform(position, rotation);
m_pxJoint->setChildPose(pxLocalTransform);
m_pxJoint->setParentPose(pxLocalTransform);
if (info.xAxisInfo.motion == EArticulationMotion::LOCKED && info.yAxisInfo.motion==EArticulationMotion::LOCKED&&info.zAxisInfo.motion==EArticulationMotion::LOCKED)
{
m_pxJoint->setJointType(physx::PxArticulationJointType::eFIX);
}
else {
m_pxJoint->setJointType(physx::PxArticulationJointType::eSPHERICAL);
}
m_pxJoint->setMotion(physx::PxArticulationAxis::eSWING1, (physx::PxArticulationMotion::Enum)info.xAxisInfo.motion);
m_pxJoint->setMotion(physx::PxArticulationAxis::eSWING2, (physx::PxArticulationMotion::Enum)info.yAxisInfo.motion);
m_pxJoint->setMotion(physx::PxArticulationAxis::eTWIST, (physx::PxArticulationMotion::Enum)info.zAxisInfo.motion);
physx::PxArticulationLimit pxXlimit(m_xLimit.low * CircularMeasure, m_xLimit.high * CircularMeasure);
physx::PxArticulationLimit pxYlimit(m_yLimit.low * CircularMeasure, m_yLimit.high * CircularMeasure);
physx::PxArticulationLimit pxZlimit(m_zLimit.low * CircularMeasure, m_zLimit.high * CircularMeasure);
m_pxJoint->setLimitParams(physx::PxArticulationAxis::eSWING1, pxXlimit);
m_pxJoint->setLimitParams(physx::PxArticulationAxis::eSWING2, pxYlimit);
m_pxJoint->setLimitParams(physx::PxArticulationAxis::eTWIST, pxZlimit);
m_pxJoint->setDriveParams(physx::PxArticulationAxis::eSWING1, m_drive);
m_pxJoint->setDriveParams(physx::PxArticulationAxis::eSWING2, m_drive);
m_pxJoint->setDriveParams(physx::PxArticulationAxis::eTWIST, m_drive);
return true;
}
bool RagdollJoint::Update(const physx::PxArticulationLink* paranthLink)
{
if (!m_pxJoint)
{
return true;
}
physx::PxArticulationLink& childLink = m_pxJoint->getChildArticulationLink();
physx::PxTransform parentJointLocalPoseInChild;
if (paranthLink->getInboundJoint())
{
parentJointLocalPoseInChild = paranthLink->getInboundJoint()->getChildPose();
}
else
{
parentJointLocalPoseInChild = physx::PxTransform(physx::PxIdentity);
}
const physx::PxTransform parentGlobalPose = paranthLink->getGlobalPose();
const physx::PxTransform childGlobalPose = childLink.getGlobalPose();
const physx::PxTransform jointLocalPoseInChild = m_pxJoint->getChildPose();
const physx::PxTransform parentJointGlobalPose =
parentGlobalPose * parentJointLocalPoseInChild;
const physx::PxTransform jointGlobalPose =
childGlobalPose * jointLocalPoseInChild;
math::vector3 parentPosition{};
math::quaternion parentRotation{};
PhysicsMath::FromPxTransform(
parentJointGlobalPose, parentPosition, parentRotation);
const math::matrix4x4 parentJointGlobalTransform = math::compose(
math::vector3::one(), parentRotation, parentPosition);
math::vector3 childPosition{};
math::quaternion childRotation{};
PhysicsMath::FromPxTransform(jointGlobalPose, childPosition, childRotation);
const math::matrix4x4 childJointGlobalTransform = math::compose(
math::vector3::one(), childRotation, childPosition);
m_simulLocalTransform =
childJointGlobalTransform * math::inverse(parentJointGlobalTransform);
return true;
}