Repository navigation
Expand file tree
/
Copy pathplinks.h
More file actions
183 lines (158 loc) · 5.59 KB
/
Copy pathplinks.h
File metadata and controls
183 lines (158 loc) · 5.59 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* @file plinks.h
* @brief Links connect two particles together, generating a contact if
* they violate the constraints of their link. It is used as a
* base class for cables and rods, and could be used as a base
* class for springs with a limit to their extension.
*/
#pragma once
#include <Gorgon/Physics/particle.h>
#include <Gorgon/Physics/pcontacts.h>
#include <Gorgon/Geometry/Point3D.h>
namespace Gorgon
{
namespace Physics
{
/**
* Links interface
*/
class ParticleLinks : public ParticleContactGenerator
{
public:
/**
* Holds pair of particles that are connected by this link
*/
Particle *particle[2];
/**
* Fills the given contact structure with the contact needed
* to keep the link from violating its constraint. The contact
* pointer should point to the first available contact in a
* contact array, where @param limit is the maximum number of
* contacts in the array that can be written to. The method
* returns the number of contacts that have been written. This
* format is common to contact-generating functions, but this
* class can only generate a single contact, so the
* pointer can be a pointer to a single element. The limit
* parameter is assumed to be at least one (zero isn’t valid),
* and the return value is either 0, if the cable wasn’t
* overextended, or one if a contact was needed.
*/
virtual unsigned AddContact(ParticleContact *contact, unsigned limit) const = 0;
protected:
/**
* Returns the current length of the link
*/
inline double CurrentLength() const;
};
/**
* Cables links a pair of particles and generates
* a contact if they stray too far.
*/
class CableLink : public ParticleLinks
{
public:
/**
* Holds the maximum length of a cable
*/
double maxLength;
/**
* Holds the restitution for the cable
*/
double restitution;
public:
/**
* Fills the given contact structure with the contact needed
* to keep the cable from over-extending.
*/
virtual unsigned AddContact(ParticleContact *contact, unsigned limit) const;
};
/**
* Rods links a pair of particles and generates
* a contact if they stray too far.
*/
class RodLink : public ParticleLinks
{
public:
/**
* Holds the length of the rod
*/
double length;
public:
/**
* Fills the given contact structure with the contact needed
* to keep the rod from extending or compressing.
*/
virtual unsigned AddContact(ParticleContact *contact, unsigned limit) const;
};
/**
* Constraints are just like links, except they connect a particle to
* an immovable anchor point.
*
* This class will act as interface for
* links' constraints (cable and rods constraints)
*/
class Constraint : public ParticleContactGenerator
{
protected:
/**
* Returns the current length of the link
*/
double CurrentLength() const;
public:
/**
* Holds the particle that are connected to the
* anchor point
*/
Particle *particle;
/**
* Holds the anchor point dimisions
*/
Point3D anchor;
/**
* Fills the given contact structure with the generated
* contact. The contact pointer should point to the first
* available contact in a contact array, where limit is the
* maximum number of contacts in the array that can be written
* to. The method returns the number of contacts that have
* been written.
*/
virtual unsigned AddContact(ParticleContact *contact, unsigned limit) const = 0;
};
/**
* Cables link a particle to an anchor point, generating a contact if they
* stray too far apart.
*/
class CableConstraints : public Constraint
{
public:
/**
* Holds the maximum length of the cable.
*/
double maxLength;
/**
* Holds the restitution (bounciness) of the cable.
*/
double restitution;
/**
* Fills the given contact structure with the contact needed
* to keep the cable from over-extending.
*/
virtual unsigned AddContact(ParticleContact *contact,
unsigned limit) const;
};
/**
* Rods link a particle to an anchor point, generating a contact if they
* stray too far apart or too close.
*/
class RodConstraints : public Constraint
{
public:
/**
* Holds the fixed length of the rod
*/
double length;
virtual unsigned AddContact(ParticleContact *contact,
unsigned limit) const;
};
};
}