-
Notifications
You must be signed in to change notification settings - Fork 267
/
Copy pathplinks.cpp
152 lines (122 loc) · 3.96 KB
/
plinks.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Implementation file for particle links.
*
* Part of the Cyclone physics system.
*
* Copyright (c) Icosagon 2003. All Rights Reserved.
*
* This software is distributed under licence. Use of this software
* implies agreement with all terms and conditions of the accompanying
* software licence.
*/
#include <cyclone/plinks.h>
using namespace cyclone;
real ParticleLink::currentLength() const
{
Vector3 relativePos = particle[0]->getPosition() -
particle[1]->getPosition();
return relativePos.magnitude();
}
unsigned ParticleCable::addContact(ParticleContact *contact,
unsigned limit) const
{
// Find the length of the cable
real length = currentLength();
// Check if we're over-extended
if (length < maxLength)
{
return 0;
}
// Otherwise return the contact
contact->particle[0] = particle[0];
contact->particle[1] = particle[1];
// Calculate the normal
Vector3 normal = particle[1]->getPosition() - particle[0]->getPosition();
normal.normalise();
contact->contactNormal = normal;
contact->penetration = length-maxLength;
contact->restitution = restitution;
return 1;
}
unsigned ParticleRod::addContact(ParticleContact *contact,
unsigned limit) const
{
// Find the length of the rod
real currentLen = currentLength();
// Check if we're over-extended
if (currentLen == length)
{
return 0;
}
// Otherwise return the contact
contact->particle[0] = particle[0];
contact->particle[1] = particle[1];
// Calculate the normal
Vector3 normal = particle[1]->getPosition() - particle[0]->getPosition();
normal.normalise();
// The contact normal depends on whether we're extending or compressing
if (currentLen > length) {
contact->contactNormal = normal;
contact->penetration = currentLen - length;
} else {
contact->contactNormal = normal * -1;
contact->penetration = length - currentLen;
}
// Always use zero restitution (no bounciness)
contact->restitution = 0;
return 1;
}
real ParticleConstraint::currentLength() const
{
Vector3 relativePos = particle->getPosition() - anchor;
return relativePos.magnitude();
}
unsigned ParticleCableConstraint::addContact(ParticleContact *contact,
unsigned limit) const
{
// Find the length of the cable
real length = currentLength();
// Check if we're over-extended
if (length < maxLength)
{
return 0;
}
// Otherwise return the contact
contact->particle[0] = particle;
contact->particle[1] = 0;
// Calculate the normal
Vector3 normal = anchor - particle->getPosition();
normal.normalise();
contact->contactNormal = normal;
contact->penetration = length-maxLength;
contact->restitution = restitution;
return 1;
}
unsigned ParticleRodConstraint::addContact(ParticleContact *contact,
unsigned limit) const
{
// Find the length of the rod
real currentLen = currentLength();
// Check if we're over-extended
if (currentLen == length)
{
return 0;
}
// Otherwise return the contact
contact->particle[0] = particle;
contact->particle[1] = 0;
// Calculate the normal
Vector3 normal = anchor - particle->getPosition();
normal.normalise();
// The contact normal depends on whether we're extending or compressing
if (currentLen > length) {
contact->contactNormal = normal;
contact->penetration = currentLen - length;
} else {
contact->contactNormal = normal * -1;
contact->penetration = length - currentLen;
}
// Always use zero restitution (no bounciness)
contact->restitution = 0;
return 1;
}