RavEngine
Loading...
Searching...
No Matches
DyConstraintPrep.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_CONSTRAINT_PREP_H
30#define DY_CONSTRAINT_PREP_H
31
32#include "DyConstraint.h"
33
34#include "DySolverConstraintDesc.h"
35#include "foundation/PxArray.h"
36#include "PxConstraint.h"
37
38#define DY_ARTICULATION_MIN_RESPONSE 1e-5f
39#define DY_ARTICULATION_CFM 2e-4f
40
41#define DY_ARTICULATION_BAD_RESPONSE 0.02f
42
43namespace physx
44{
45
46class PxcConstraintBlockStream;
47class PxsConstraintBlockManager;
48struct PxSolverBody;
49struct PxSolverBodyData;
50struct PxSolverConstraintDesc;
51
52namespace Cm
53{
54 struct SpatialVectorF;
55}
56
57namespace Dy
58{
59
60 static const PxU32 MAX_CONSTRAINT_ROWS = 20;
61
63 {
64 const Constraint* constraint;
65 PxConstraintSolverPrep solverPrep;
66 const void* constantBlock;
67 PxU32 constantBlockByteSize;
68 };
69
70 SolverConstraintPrepState::Enum setupSolverConstraint4
71 (SolverConstraintShaderPrepDesc* PX_RESTRICT constraintShaderDescs,
73 const PxReal dt, const PxReal recipdt, PxU32& totalRows,
74 PxConstraintAllocator& allocator);
75
76 SolverConstraintPrepState::Enum setupSolverConstraint4
78 const PxReal dt, const PxReal recipdt, PxU32& totalRows,
79 PxConstraintAllocator& allocator, PxU32 maxRows);
80
81 PxU32 SetupSolverConstraint(SolverConstraintShaderPrepDesc& shaderDesc,
83 PxConstraintAllocator& allocator,
84 PxReal dt, PxReal invdt, Cm::SpatialVectorF* Z);
85
86
88 {
89 public:
90
91 static PxU32 setupSolverConstraint(
93 PxConstraintAllocator& allocator,
94 PxReal dt, PxReal invdt, Cm::SpatialVectorF* Z);
95 };
96
97 template<class PrepDescT>
98 PX_FORCE_INLINE void setupConstraintFlags(PrepDescT& prepDesc, PxU16 flags)
99 {
100 prepDesc.disablePreprocessing = (flags & PxConstraintFlag::eDISABLE_PREPROCESSING)!=0;
101 prepDesc.improvedSlerp = (flags & PxConstraintFlag::eIMPROVED_SLERP)!=0;
102 prepDesc.driveLimitsAreForces = (flags & PxConstraintFlag::eDRIVE_LIMITS_ARE_FORCES)!=0;
103 prepDesc.extendedLimits = (flags & PxConstraintFlag::eENABLE_EXTENDED_LIMITS)!=0;
104 prepDesc.disableConstraint = (flags & PxConstraintFlag::eDISABLE_CONSTRAINT)!=0;
105 }
106
107 void preprocessRows(Px1DConstraint** sorted,
108 Px1DConstraint* rows,
109 PxVec4* angSqrtInvInertia0,
110 PxVec4* angSqrtInvInertia1,
111 PxU32 rowCount,
112 const PxMat33& sqrtInvInertia0F32,
113 const PxMat33& sqrtInvInertia1F32,
114 const PxReal invMass0,
115 const PxReal invMass1,
116 const PxConstraintInvMassScale& ims,
117 bool disablePreprocessing,
118 bool diagonalizeDrive);
119
120 PX_FORCE_INLINE void setupConstraintRows(Px1DConstraint* PX_RESTRICT rows, PxU32 size)
121 {
122 // This is necessary so that there will be sensible defaults and shaders will
123 // continue to work (albeit with a recompile) if the row format changes.
124 // It's a bit inefficient because it fills in all constraint rows even if there
125 // is only going to be one generated. A way around this would be for the shader to
126 // specify the maximum number of rows it needs, or it could call a subroutine to
127 // prep the row before it starts filling it it.
128
129 PxMemZero(rows, sizeof(Px1DConstraint)*size);
130
131 for(PxU32 i=0; i<size; i++)
132 {
133 Px1DConstraint& c = rows[i];
134 //Px1DConstraintInit(c);
135 c.minImpulse = -PX_MAX_REAL;
136 c.maxImpulse = PX_MAX_REAL;
137 }
138 }
139}
140
141}
142
143#endif
Definition DyConstraintPrep.h:88
Definition PxSolverDefs.h:227
3x3 matrix class
Definition PxMat33.h:91
Definition PxVec4.h:50
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxU32(* PxConstraintSolverPrep)(Px1DConstraint *constraints, PxVec3p &bodyAWorldOffset, PxU32 maxConstraints, PxConstraintInvMassScale &invMassScale, const void *constantBlock, const PxTransform &bodyAToWorld, const PxTransform &bodyBToWorld, bool useExtendedLimits, PxVec3p &cAtW, PxVec3p &cBtW)
Solver constraint generation shader.
Definition PxConstraintDesc.h:223
PX_FORCE_INLINE void * PxMemZero(void *dest, PxU32 count)
Sets the bytes of the provided buffer to zero.
Definition PxMemory.h:53
Definition CmSpatialVector.h:134
Definition DyConstraint.h:53
Definition DyConstraintPrep.h:63
A one-dimensional constraint.
Definition PxConstraintDesc.h:134
@ eIMPROVED_SLERP
perform preprocessing for improved accuracy on D6 Slerp Drive (this flag will be removed in a future ...
Definition PxConstraint.h:65
@ eENABLE_EXTENDED_LIMITS
enables extended limit ranges for angular limits (e.g., limit values > PxPi or < -PxPi)
Definition PxConstraint.h:67
@ eDISABLE_PREPROCESSING
suppress constraint preprocessing, intended for use with rowResponseThreshold. May result in worse so...
Definition PxConstraint.h:66
@ eDISABLE_CONSTRAINT
disables the constraint. SolverPrep functions won't be called for this constraint.
Definition PxConstraint.h:70
@ eDRIVE_LIMITS_ARE_FORCES
limits for drive strength are forces rather than impulses
Definition PxConstraint.h:64
Struct for specifying mass scaling for a pair of rigids.
Definition PxConstraintDesc.h:184
Data structure used for preparing constraints before solving them.
Definition PxSolverDefs.h:178