-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRagdollLink.cpp
More file actions
127 lines (104 loc) · 3.99 KB
/
Copy pathRagdollLink.cpp
File metadata and controls
127 lines (104 loc) · 3.99 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "RagdollLink.h"
#include "PhysicsMathAdapter.h"
#include <mathematics/transform.hpp>
bool RagdollLink::Initialize(const LinkInfo& linkInfo, RagdollLink* parentLink, physx::PxArticulationReducedCoordinate* pxArtriculation)
{
m_name = linkInfo.boneName;
m_density = linkInfo.density;
m_localTransform = linkInfo.localTransform;
m_parentLink = parentLink;
math::vector3 scale{};
math::quaternion rotation{};
math::vector3 position{};
(void)math::decompose(m_localTransform, scale, rotation, position);
math::matrix4x4 linkTransform = math::compose(
math::vector3::one(), rotation, position);
if (parentLink == nullptr)
{
linkTransform *= math::rotation_z(3.14f);
(void)math::decompose(linkTransform, scale, rotation, position);
const physx::PxTransform pxLocalTransform =
PhysicsMath::ToPxTransform(position, rotation);
m_pxLink = pxArtriculation->createLink(nullptr, pxLocalTransform);
}
else
{
(void)math::decompose(linkTransform, scale, rotation, position);
const physx::PxTransform pxLocalTransform =
PhysicsMath::ToPxTransform(position, rotation);
m_pxLink = pxArtriculation->createLink(parentLink->GetPxLink(), pxLocalTransform);
m_myJoint->Initialize(parentLink, this, linkInfo.jointInfo);
}
m_pxLink->setMaxAngularVelocity(4.0f);
m_pxLink->setMaxLinearVelocity(4.0f);
m_pxLink->setAngularDamping(0.2f);
m_pxLink->setLinearDamping(0.2f);
return true;
}
bool RagdollLink::Update()
{
return m_myJoint->Update(m_parentLink->GetPxLink());
}
physx::PxShape* RagdollLink::CreateShape(physx::PxMaterial* material, const math::vector3& extent, CollisionData* collisionData)
{
const physx::PxVec3 pxExtent = PhysicsMath::ToPx(extent);
physx::PxShape* shape = physx::PxRigidActorExt::createExclusiveShape(*m_pxLink, physx::PxBoxGeometry(pxExtent), *material);
physx::PxRigidBodyExt::updateMassAndInertia(*m_pxLink, m_density);
if (shape == nullptr)
{
Debug->LogError("ragdoll link error [ nema :" + m_name + "] create Shape fail");
return nullptr;
}
shape->userData = collisionData;
shape->setContactOffset(0.002f);
shape->setRestOffset(0.001f);
return shape;
}
physx::PxShape* RagdollLink::CreateShape(physx::PxMaterial* material, const float& radius, const float& halfHeight, CollisionData* collisionData)
{
physx::PxShape* shape = physx::PxRigidActorExt::createExclusiveShape(*m_pxLink, physx::PxCapsuleGeometry(radius, halfHeight), *material);
physx::PxRigidBodyExt::updateMassAndInertia(*m_pxLink, m_density);
if (shape == nullptr)
{
Debug->LogError("ragdoll link error [ nema :" + m_name + "] create Shape fail");
return nullptr;
}
shape->userData = collisionData;
shape->setContactOffset(0.002f);
shape->setRestOffset(0.001f);
return shape;
}
physx::PxShape* RagdollLink::CreateShape(physx::PxMaterial* material, const float& radius, CollisionData* collisionData)
{
physx::PxShape* shape = physx::PxRigidActorExt::createExclusiveShape(*m_pxLink, physx::PxSphereGeometry(radius), *material);
physx::PxRigidBodyExt::updateMassAndInertia(*m_pxLink, m_density);
if (shape == nullptr)
{
Debug->LogError("ragdoll link error [ nema :" + m_name + "] create Shape fail");
return nullptr;
}
shape->userData = collisionData;
shape->setContactOffset(0.002f);
shape->setRestOffset(0.001f);
return shape;
}
bool RagdollLink::ChangeLayerNumber(const physx::PxFilterData& fillterData, CollisionData* collisionData)
{
physx::PxShape* shape;
m_pxLink->getShapes(&shape, 1);
shape->setSimulationFilterData(fillterData);
shape->userData = collisionData;
return true;
}
void RagdollLink::SetWorldTransform(const math::matrix4x4& worldTransform)
{
math::vector3 scale{};
math::quaternion rotation{};
math::vector3 position{};
(void)math::decompose(worldTransform, scale, rotation, position);
const math::matrix4x4 linkTransform =
math::compose(math::vector3::one(), rotation, position) *
math::inverse(m_myJoint->GetLocalTransform());
(void)math::decompose(linkTransform, scale, rotation, position);
m_pxLink->setGlobalPose(PhysicsMath::ToPxTransform(position, rotation));
}