RavEngine
Loading...
Searching...
No Matches
ScConstraintCore.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 SC_CONSTRAINT_CORE_H
30#define SC_CONSTRAINT_CORE_H
31
32#include "PxConstraint.h"
33
34namespace physx
35{
36 class PxsSimulationController;
37namespace Sc
38{
39 class ConstraintSim;
40 class RigidCore;
41
43 {
44 //= ATTENTION! =====================================================================================
45 // Changing the data layout of this class breaks the binary serialization format. See comments for
46 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
47 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
48 // accordingly.
49 //==================================================================================================
50 public:
51// PX_SERIALIZATION
52 ConstraintCore(const PxEMPTY) : mFlags(PxEmpty), mConnector(NULL), mSim(NULL) {}
53 PX_FORCE_INLINE void setConstraintFunctions(PxConstraintConnector& n, const PxConstraintShaderTable& shaders)
54 {
55 mConnector = &n;
56 mSolverPrep = shaders.solverPrep;
57 mProject = shaders.project;
58 mVisualize = shaders.visualize;
59 }
60 static void getBinaryMetaData(PxOutputStream& stream);
61//~PX_SERIALIZATION
62 ConstraintCore(PxConstraintConnector& connector, const PxConstraintShaderTable& shaders, PxU32 dataSize);
64
65 void setBodies(RigidCore* r0v, RigidCore* r1v);
66
67 PxConstraint* getPxConstraint();
68 const PxConstraint* getPxConstraint() const;
69 PX_FORCE_INLINE PxConstraintConnector* getPxConnector() const { return mConnector; }
70
71 PX_FORCE_INLINE PxConstraintFlags getFlags() const { return mFlags; }
72 void setFlags(PxConstraintFlags flags);
73
74 void getForce(PxVec3& force, PxVec3& torque) const;
75
76 void setBreakForce(PxReal linear, PxReal angular);
77 PX_FORCE_INLINE void getBreakForce(PxReal& linear, PxReal& angular) const
78 {
79 linear = mLinearBreakForce;
80 angular = mAngularBreakForce;
81 }
82
83 void setMinResponseThreshold(PxReal threshold);
84 PX_FORCE_INLINE PxReal getMinResponseThreshold() const { return mMinResponseThreshold; }
85
86 void breakApart();
87
88 PX_FORCE_INLINE PxConstraintVisualize getVisualize() const { return mVisualize; }
89 PX_FORCE_INLINE PxConstraintProject getProject() const { return mProject; }
90 PX_FORCE_INLINE PxConstraintSolverPrep getSolverPrep() const { return mSolverPrep; }
91 PX_FORCE_INLINE PxU32 getConstantBlockSize() const { return mDataSize; }
92
93 PX_FORCE_INLINE void setSim(ConstraintSim* sim)
94 {
95 PX_ASSERT((sim==0) ^ (mSim == 0));
96 mSim = sim;
97 }
98 PX_FORCE_INLINE ConstraintSim* getSim() const { return mSim; }
99
100 PX_FORCE_INLINE bool isDirty() const { return mIsDirty ? true : false; }
101 PX_FORCE_INLINE void setDirty() { mIsDirty = 1; }
102 PX_FORCE_INLINE void clearDirty() { mIsDirty = 0; }
103
104 private:
105 PxConstraintFlags mFlags;
106 //In order to support O(1) insert/remove mIsDirty really wants to be an index into NpScene's dirty joint array
107 PxU8 mIsDirty;
108 PxU8 mPadding;
109
110 PxVec3 mAppliedForce;
111 PxVec3 mAppliedTorque;
112
113 PxConstraintConnector* mConnector;
114 PxConstraintProject mProject;
115 PxConstraintSolverPrep mSolverPrep;
116 PxConstraintVisualize mVisualize;
117 PxU32 mDataSize;
118 PxReal mLinearBreakForce;
119 PxReal mAngularBreakForce;
120 PxReal mMinResponseThreshold;
121
122 ConstraintSim* mSim;
123 };
124
125} // namespace Sc
126
127}
128
129#endif
This class connects a custom constraint to the SDK.
Definition PxConstraintDesc.h:354
A plugin class for implementing constraints.
Definition PxConstraint.h:100
Output stream class for I/O.
Definition PxIO.h:114
3 Element vector class.
Definition PxVec3.h:50
Definition ScConstraintCore.h:43
Definition ScConstraintSim.h:48
Definition ScRigidCore.h:61
#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
void(* PxConstraintVisualize)(PxConstraintVisualizer &visualizer, const void *constantBlock, const PxTransform &body0Transform, const PxTransform &body1Transform, PxU32 flags)
Solver constraint visualization function.
Definition PxConstraintDesc.h:323
PX_DEPRECATED void(* PxConstraintProject)(const void *constantBlock, PxTransform &bodyAToWorld, PxTransform &bodyBToWorld, bool projectToA)
Solver constraint projection shader.
Definition PxConstraintDesc.h:247
PxEMPTY
Definition Px.h:87
a table of function pointers for a constraint
Definition PxConstraint.h:87
PxConstraintSolverPrep solverPrep
solver constraint generation function
Definition PxConstraint.h:88
PxConstraintProject project
Definition PxConstraint.h:89
PxConstraintVisualize visualize
constraint visualization function
Definition PxConstraint.h:90