RavEngine
Loading...
Searching...
No Matches
ScConstraintSim.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_SIM_H
30#define SC_CONSTRAINT_SIM_H
31
32#include "foundation/PxArray.h"
33#include "PxSimulationEventCallback.h"
34#include "DyConstraint.h"
35
36namespace physx
37{
38namespace Sc
39{
40 class Scene;
41 class ConstraintInteraction;
42 class ConstraintCore;
43 class RigidCore;
44 class BodySim;
45 class RigidSim;
46
48 {
49 public:
50 enum Enum
51 {
52 ePENDING_GROUP_UPDATE = (1<<0), // For constraint projection an island of the bodies connected by constraints is generated.
53 // Schedule generation/update of the island this constraint is a part of.
54 eBREAKABLE = (1<<1), // The constraint can break
55 eCHECK_MAX_FORCE_EXCEEDED = (1<<2), // This constraint will get tested for breakage at the end of the sim step
56 eBROKEN = (1<<3)
57 };
59 RigidCore* r0,
60 RigidCore* r1,
61 Scene& scene);
62
64
65 void setBodies(RigidCore* r0, RigidCore* r1);
66
67 void checkMaxForceExceeded();
68
69 void setBreakForceLL(PxReal linear, PxReal angular);
70 PX_FORCE_INLINE void setMinResponseThresholdLL(PxReal threshold) { mLowLevelConstraint.minResponseThreshold = threshold; }
71 PX_FORCE_INLINE const void* getConstantsLL() const { return mLowLevelConstraint.constantBlock; }
72
73 void postFlagChange(PxConstraintFlags oldFlags, PxConstraintFlags newFlags);
74
75 PX_FORCE_INLINE const Dy::Constraint& getLowLevelConstraint() const { return mLowLevelConstraint; }
76 PX_FORCE_INLINE Dy::Constraint& getLowLevelConstraint() { return mLowLevelConstraint; }
77 PX_FORCE_INLINE ConstraintCore& getCore() const { return mCore; }
78 PX_FORCE_INLINE BodySim* getBody(PxU32 i) const // for static actors or world attached constraints NULL is returned
79 {
80 return mBodies[i];
81 }
82
83 RigidSim& getRigid(PxU32 i);
84
85 void getForce(PxVec3& force, PxVec3& torque);
86
87 PX_FORCE_INLINE PxU8 readFlag(PxU8 flag) const { return PxU8(mFlags & flag); }
88 PX_FORCE_INLINE void setFlag(PxU8 flag) { mFlags |= flag; }
89 PX_FORCE_INLINE void clearFlag(PxU8 flag) { mFlags &= ~flag; }
90 PX_FORCE_INLINE PxU32 isBroken() const { return PxU32(mFlags) & ConstraintSim::eBROKEN; }
91
92 PX_FORCE_INLINE const ConstraintInteraction* getInteraction() const { return mInteraction; }
93
94 //------------------------------------ Projection trees -----------------------------------------
95 private:
96 PX_INLINE BodySim* getConstraintGroupBody();
97
98 public:
99 bool hasDynamicBody();
100
101 void projectPose(BodySim* childBody, PxArray<BodySim*>& projectedBodies);
102 PX_FORCE_INLINE BodySim* getOtherBody(BodySim* b) { return (b == mBodies[0]) ? mBodies[1] : mBodies[0]; }
103 PX_FORCE_INLINE BodySim* getAnyBody() { return mBodies[0] ? mBodies[0] : mBodies[1]; }
104
105 bool needsProjection();
106 //-----------------------------------------------------------------------------------------------
107
108 void visualize(PxRenderBuffer &out);
109 private:
110 ConstraintSim& operator=(const ConstraintSim&);
111 bool createLLConstraint();
112 void destroyLLConstraint();
113 private:
114 Dy::Constraint mLowLevelConstraint;
115 Scene& mScene;
116 ConstraintCore& mCore;
117 ConstraintInteraction* mInteraction;
118 BodySim* mBodies[2];
119 PxU8 mFlags;
120 };
121} // namespace Sc
122
123}
124
125#endif
Definition PxArray.h:53
Interface for points, lines, triangles, and text buffer.
Definition PxRenderBuffer.h:136
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
Definition ScBodySim.h:60
Definition ScConstraintCore.h:43
Definition ScConstraintInteraction.h:42
Definition ScConstraintSim.h:48
Definition ScRigidCore.h:61
Definition ScRigidSim.h:42
Definition ScScene.h:240
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition DyConstraint.h:53