RavEngine
Loading...
Searching...
No Matches
DySolverConstraint1D.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef DY_SOLVER_CONSTRAINT_1D_H
30#define DY_SOLVER_CONSTRAINT_1D_H
31
32#include "foundation/PxVec3.h"
33#include "PxvConfig.h"
34#include "DyArticulationUtils.h"
35#include "DySolverConstraintTypes.h"
36#include "DySolverBody.h"
37#include "PxConstraintDesc.h"
38#include "DySolverConstraintDesc.h"
39
40namespace physx
41{
42
43namespace Dy
44{
45
46// dsequeira: we should probably fork these structures for constraints and extended constraints,
47// since there's a few things that are used for one but not the other
48
50{
51 PxU8 type; // enum SolverConstraintType - must be first byte
52 PxU8 count; // count of following 1D constraints
53 PxU8 dominance;
54 PxU8 breakable; // indicate whether this constraint is breakable or not
55
56 PxReal linBreakImpulse;
57 PxReal angBreakImpulse;
58 PxReal invMass0D0;
59 PxVec3 body0WorldOffset;
60 PxReal invMass1D1;
61 PxReal linearInvMassScale0; // only used by articulations
62 PxReal angularInvMassScale0; // only used by articulations
63 PxReal linearInvMassScale1; // only used by articulations
64 PxReal angularInvMassScale1; // only used by articulations
65};
66
68
69PX_ALIGN_PREFIX(16)
71{
72public:
74 PxReal constant;
75
78
81
84
86 PxU32 pad;
87
88 PxReal minImpulse;
89 PxReal maxImpulse;
90 PxReal appliedForce;
91 PxU32 flags;
92} PX_ALIGN_SUFFIX(16);
93
95
96
98{
99public:
100 Cm::SpatialVectorV deltaVA;
101 Cm::SpatialVectorV deltaVB;
102};
103
105
106
108 PxU8 count,
109 bool isExtended,
110 const PxConstraintInvMassScale& ims)
111{
112 h.type = PxU8(isExtended ? DY_SC_TYPE_EXT_1D : DY_SC_TYPE_RB_1D);
113 h.count = count;
114 h.dominance = 0;
115 h.linearInvMassScale0 = ims.linear0;
116 h.angularInvMassScale0 = ims.angular0;
117 h.linearInvMassScale1 = -ims.linear1;
118 h.angularInvMassScale1 = -ims.angular1;
119}
120
121PX_FORCE_INLINE void init(SolverConstraint1D& c,
122 const PxVec3& _linear0, const PxVec3& _linear1,
123 const PxVec3& _angular0, const PxVec3& _angular1,
124 PxReal _minImpulse, PxReal _maxImpulse)
125{
126 PX_ASSERT(_linear0.isFinite());
127 PX_ASSERT(_linear1.isFinite());
128 c.lin0 = _linear0;
129 c.lin1 = _linear1;
130 c.ang0 = _angular0;
131 c.ang1 = _angular1;
132 c.minImpulse = _minImpulse;
133 c.maxImpulse = _maxImpulse;
134 c.flags = 0;
135 c.appliedForce = 0;
136}
137
138PX_FORCE_INLINE bool needsNormalVel(const Px1DConstraint &c)
139{
140 return c.flags & Px1DConstraintFlag::eRESTITUTION
142}
143
144PX_FORCE_INLINE void setSolverConstants(PxReal& constant,
145 PxReal& unbiasedConstant,
146 PxReal& velMultiplier,
147 PxReal& impulseMultiplier,
148 const Px1DConstraint& c,
149 PxReal normalVel,
150 PxReal unitResponse,
151 PxReal minRowResponse,
152 PxReal erp,
153 PxReal dt,
154 PxReal recipdt)
155{
156 PX_ASSERT(PxIsFinite(unitResponse));
157 PxReal recipResponse = unitResponse <= minRowResponse ? 0 : 1.0f/unitResponse;
158
159
160
161 if(c.flags & Px1DConstraintFlag::eSPRING)
162 {
163 PxReal a = dt * dt * c.mods.spring.stiffness + dt * c.mods.spring.damping;
164 PxReal b = dt * (c.mods.spring.damping * c.velocityTarget - c.mods.spring.stiffness * c.geometricError);
165
167 {
168 PxReal x = 1.0f/(1.0f+a);
169 constant = unbiasedConstant = x * recipResponse * b;
170 velMultiplier = -x * recipResponse * a;
171 impulseMultiplier = 1.0f-x;
172 }
173 else
174 {
175 PxReal x = unitResponse == 0.f ? 0.f : 1.0f/(1.0f+a*unitResponse);
176 constant = unbiasedConstant = x * b;
177 velMultiplier = -x*a;
178 impulseMultiplier = 1.0f-x;
179 }
180 }
181 else
182 {
183 PxReal geomError = c.geometricError * erp;
184 velMultiplier = -recipResponse;
185 impulseMultiplier = 1.0f;
186
187 if(c.flags & Px1DConstraintFlag::eRESTITUTION && -normalVel>c.mods.bounce.velocityThreshold)
188 {
189 unbiasedConstant = constant = recipResponse * c.mods.bounce.restitution*-normalVel;
190 }
191 else
192 {
193 // see usage of 'for internal use' in preprocessRows()
194 constant = recipResponse * (c.velocityTarget - geomError*recipdt);
195 unbiasedConstant = recipResponse * (c.velocityTarget - c.forInternalUse*recipdt);
196 }
197 }
198}
199
200}
201}
202
203#endif
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
returns true if all 3 elems of the vector are finite (not NAN or INF, etc.)
Definition PxVec3.h:156
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(float f)
returns true if the passed number is a finite floating point number as opposed to INF,...
Definition PxMath.h:326
Definition CmSpatialVector.h:483
Definition DySolverConstraint1D.h:98
Definition DySolverConstraint1D.h:50
Definition DySolverConstraint1D.h:71
PxReal minImpulse
Lower bound on impulse magnitude
Definition DySolverConstraint1D.h:88
PxVec3 lin1
linear velocity projection (body 1)
Definition DySolverConstraint1D.h:76
PxReal constant
constraint constant term
Definition DySolverConstraint1D.h:74
PxVec3 ang0
angular velocity projection (body 0)
Definition DySolverConstraint1D.h:79
PxReal appliedForce
applied force to correct velocity+bias
Definition DySolverConstraint1D.h:90
PxReal velMultiplier
constraint velocity multiplier
Definition DySolverConstraint1D.h:80
PxVec3 ang0Writeback
unscaled angular velocity projection (body 0)
Definition DySolverConstraint1D.h:85
PxVec3 ang1
angular velocity projection (body 1)
Definition DySolverConstraint1D.h:82
PxReal maxImpulse
Upper bound on impulse magnitude.
Definition DySolverConstraint1D.h:89
PxVec3 lin0
linear velocity projection (body 0)
Definition DySolverConstraint1D.h:73
PxReal impulseMultiplier
constraint impulse multiplier
Definition DySolverConstraint1D.h:83
PxReal unbiasedConstant
constraint constant term without bias
Definition DySolverConstraint1D.h:77
@ eRESTITUTION
whether the restitution model should be applied to generate the target velocity. Mutually exclusive w...
Definition PxConstraintDesc.h:67
@ eACCELERATION_SPRING
whether the constraint is a force or acceleration spring. Only valid if eSPRING is set.
Definition PxConstraintDesc.h:66
@ eSPRING
whether the constraint is a spring. Mutually exclusive with eRESTITUTION. If set, eKEEPBIAS is ignore...
Definition PxConstraintDesc.h:65
Struct for specifying mass scaling for a pair of rigids.
Definition PxConstraintDesc.h:184
PxReal angular1
multiplier for inverse MoI of body1
Definition PxConstraintDesc.h:195
PxReal linear0
multiplier for inverse mass of body0
Definition PxConstraintDesc.h:192
PxReal angular0
multiplier for inverse MoI of body0
Definition PxConstraintDesc.h:193
PxReal linear1
multiplier for inverse mass of body1
Definition PxConstraintDesc.h:194