1 | #ifndef NX_PHYSICS_NXJOINTDESC
|
---|
2 | #define NX_PHYSICS_NXJOINTDESC
|
---|
3 | /*----------------------------------------------------------------------------*\
|
---|
4 | |
|
---|
5 | | Public Interface to NovodeX Technology
|
---|
6 | |
|
---|
7 | | www.novodex.com
|
---|
8 | |
|
---|
9 | \*----------------------------------------------------------------------------*/
|
---|
10 | /** \addtogroup physics
|
---|
11 | @{
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "Nxp.h"
|
---|
15 | #include "NxJoint.h"
|
---|
16 | #include "NxActor.h"
|
---|
17 | #include "PhysXLoader.h"
|
---|
18 | #include "NxUtilLib.h"
|
---|
19 |
|
---|
20 | /**
|
---|
21 | \brief Descriptor class for the #NxJoint class.
|
---|
22 |
|
---|
23 | Joint descriptors for all the different joint types are derived from this class.
|
---|
24 |
|
---|
25 | <b>Platform:</b>
|
---|
26 | \li PC SW: Yes
|
---|
27 | \li PPU : No
|
---|
28 | \li PS3 : Yes
|
---|
29 | \li XB360: Yes
|
---|
30 |
|
---|
31 | @see NxJoint NxScene.createJoint()
|
---|
32 | @see NxCylindricalJointDesc NxD6JointDesc NxDistanceJointDesc NxFixedJointDesc NxPointInPlaneJointDesc
|
---|
33 | NxPointOnLineJointDesc NxPrismaticJointDesc NxPulleyJointDesc NxRevoluteJointDesc NxSPhericalJointDesc
|
---|
34 | */
|
---|
35 | class NxJointDesc
|
---|
36 | {
|
---|
37 | protected:
|
---|
38 |
|
---|
39 | /**
|
---|
40 | \brief The type of joint. This is set by the ctor of the derived class.
|
---|
41 | */
|
---|
42 | const NxJointType type;
|
---|
43 | public:
|
---|
44 |
|
---|
45 | /**
|
---|
46 | \brief The two actors connected by the joint.
|
---|
47 |
|
---|
48 | The actors must be in the same scene as this joint.
|
---|
49 |
|
---|
50 | At least one of the two pointers must be a dynamic actor.
|
---|
51 |
|
---|
52 | One of the two may be NULL to indicate the world frame. Neither may be a static actor!
|
---|
53 |
|
---|
54 | <b>Default:</b> NULL
|
---|
55 |
|
---|
56 | @see NxActor
|
---|
57 | */
|
---|
58 | NxActor * actor[2];
|
---|
59 |
|
---|
60 | /**
|
---|
61 | \brief X axis of joint space, in actor[i]'s space, orthogonal to localAxis[i]
|
---|
62 |
|
---|
63 | #localAxis and localNormal should be unit length and at right angles to each other, ie
|
---|
64 | dot(localNormal[0],localAxis[0])==0 and dot(localNormal[1],localAxis[1])==0.
|
---|
65 |
|
---|
66 | <b>Range:</b> direction vector<br>
|
---|
67 | <b>Default:</b> [0] 1.0f,0.0f,0.0f<br>
|
---|
68 | <b>Default:</b> [1] 1.0f,0.0f,0.0f
|
---|
69 |
|
---|
70 | @see localAxis setGlobalAxis()
|
---|
71 | */
|
---|
72 | NxVec3 localNormal[2];
|
---|
73 |
|
---|
74 | /**
|
---|
75 | \brief Z axis of joint space, in actor[i]'s space. This is the primary axis of the joint.
|
---|
76 |
|
---|
77 | localAxis and #localNormal should be unit length and at right angles to each other, ie
|
---|
78 | dot(localNormal[0],localAxis[0])==0 and dot(localNormal[1],localAxis[1])==0.
|
---|
79 |
|
---|
80 | <b>Range:</b> direction vector<br>
|
---|
81 | <b>Default:</b> [0] 0.0f,0.0f,1.0f<br>
|
---|
82 | <b>Default:</b> [1] 0.0f,0.0f,1.0f
|
---|
83 |
|
---|
84 | @see localNormal setGlobalAxis()
|
---|
85 | */
|
---|
86 | NxVec3 localAxis[2];
|
---|
87 |
|
---|
88 | /**
|
---|
89 | \brief Attachment point of joint in actor[i]'s space
|
---|
90 |
|
---|
91 | <b>Range:</b> position vector<br>
|
---|
92 | <b>Default:</b> [0] Zero<br>
|
---|
93 | <b>Default:</b> [1] Zero
|
---|
94 |
|
---|
95 | @see setGlobalAnchor()
|
---|
96 | */
|
---|
97 | NxVec3 localAnchor[2];
|
---|
98 |
|
---|
99 | /**
|
---|
100 | Maximum linear force that the joint can withstand before breaking, must be positive.
|
---|
101 |
|
---|
102 | <b>Range:</b> (0,inf]<br>
|
---|
103 | <b>Default:</b> NX_MAX_REAL
|
---|
104 |
|
---|
105 | @see NxJoint.setBreakable() NxUserNotify.onJointBreak()
|
---|
106 | */
|
---|
107 | NxReal maxForce;
|
---|
108 |
|
---|
109 | /**
|
---|
110 | \brief Maximum angular force (torque) that the joint can withstand before breaking, must be positive.
|
---|
111 |
|
---|
112 | <b>Range:</b> (0,inf]<br>
|
---|
113 | <b>Default:</b> NX_MAX_REAL
|
---|
114 |
|
---|
115 | @see NxJoint.setBreakable() NxUserNotify.onJointBreak()
|
---|
116 | */
|
---|
117 | NxReal maxTorque;
|
---|
118 |
|
---|
119 | /**
|
---|
120 | \brief Will be copied to NxJoint::userData.
|
---|
121 |
|
---|
122 | <b>Default:</b> NULL
|
---|
123 | */
|
---|
124 | void* userData;
|
---|
125 |
|
---|
126 | /**
|
---|
127 | \brief Possible debug name. The string is not copied by the SDK, only the pointer is stored.
|
---|
128 |
|
---|
129 | <b>Default</b> NULL
|
---|
130 | */
|
---|
131 | const char* name;
|
---|
132 |
|
---|
133 | /**
|
---|
134 | \brief This is a combination of the bits defined by ::NxJointFlag .
|
---|
135 |
|
---|
136 | <b>Default:</b> NX_JF_VISUALIZATION
|
---|
137 | */
|
---|
138 | NxU32 jointFlags;
|
---|
139 |
|
---|
140 |
|
---|
141 | NX_INLINE virtual ~NxJointDesc();
|
---|
142 |
|
---|
143 | /**
|
---|
144 | \brief (re)sets the structure to the default.
|
---|
145 | */
|
---|
146 | NX_INLINE virtual void setToDefault();
|
---|
147 |
|
---|
148 | /**
|
---|
149 | \brief Returns true if the descriptor is valid.
|
---|
150 |
|
---|
151 | \return true if the current settings are valid
|
---|
152 | */
|
---|
153 | NX_INLINE virtual bool isValid() const;
|
---|
154 |
|
---|
155 |
|
---|
156 | /**
|
---|
157 | \brief Set the localAnchor[] members ufing a world space point.
|
---|
158 |
|
---|
159 | sets the members localAnchor[0,1] by transforming the passed world space
|
---|
160 | vector into actor1 resp. actor2's local space. The actor pointers must already be set!
|
---|
161 |
|
---|
162 | \param[in] wsAnchor Global frame anchor point. <b>Range:</b> position vector
|
---|
163 |
|
---|
164 | @see setGlobalAxis() localAxis
|
---|
165 | */
|
---|
166 | NX_INLINE void setGlobalAnchor(const NxVec3 & wsAnchor);
|
---|
167 |
|
---|
168 | /**
|
---|
169 | \brief Set the local axis/normal using a world space axis.
|
---|
170 |
|
---|
171 | sets the members localAxis[0,1] by transforming the passed world space
|
---|
172 | vector into actor1 resp. actor2's local space, and finding arbitrary orthogonals for localNormal[0,1].
|
---|
173 | The actor pointers must already be set!
|
---|
174 |
|
---|
175 | \param[in] wsAxis Global frame axis. <b>Range:</b> direction vector
|
---|
176 |
|
---|
177 | @see setGlobalAnchor() localAnchor
|
---|
178 | */
|
---|
179 | NX_INLINE void setGlobalAxis(const NxVec3 & wsAxis);
|
---|
180 |
|
---|
181 | /**
|
---|
182 | \brief Retrieves the joint type.
|
---|
183 |
|
---|
184 | \return The type of joint this descriptor describes. See #NxJointType.
|
---|
185 |
|
---|
186 | @see NxJointType
|
---|
187 | */
|
---|
188 | NX_INLINE NxJointType getType() const { return type; }
|
---|
189 | protected:
|
---|
190 | /**
|
---|
191 | \brief Constructor sets to default.
|
---|
192 |
|
---|
193 | \param t Joint type
|
---|
194 | */
|
---|
195 | NX_INLINE NxJointDesc(NxJointType t);
|
---|
196 | };
|
---|
197 |
|
---|
198 | /**
|
---|
199 | \brief Set the local anchor stored in a #NxJointDesc from a global anchor point.
|
---|
200 |
|
---|
201 | \warning #NxCreatePhysicsSDK() must be called before using this function.
|
---|
202 |
|
---|
203 | \param dis Joint desc to update.
|
---|
204 | \param wsAnchor Anchor point in the global frame. <b>Range:</b> position vector
|
---|
205 |
|
---|
206 | @see NxJointDesc.setGlobalAnchor()
|
---|
207 | */
|
---|
208 | NX_INLINE void NX_CALL_CONV NxJointDesc_SetGlobalAnchor(NxJointDesc & dis, const NxVec3 & wsAnchor)
|
---|
209 | {
|
---|
210 | NxGetUtilLib()->NxJointDesc_SetGlobalAnchor(dis,wsAnchor);
|
---|
211 | }
|
---|
212 |
|
---|
213 | /**
|
---|
214 | \brief Set the local axis stored in a #NxJointDesc from a global axis.
|
---|
215 |
|
---|
216 | \warning #NxCreatePhysicsSDK() must be called before using this function.
|
---|
217 |
|
---|
218 | \param dis Joint desc to update.
|
---|
219 | \param wsAxis Axis in the global frame. <b>Range:</b> direction vector
|
---|
220 |
|
---|
221 | @see NxJointDesc.setGlobalAxis()
|
---|
222 | */
|
---|
223 | NX_INLINE void NX_CALL_CONV NxJointDesc_SetGlobalAxis(NxJointDesc & dis, const NxVec3 & wsAxis)
|
---|
224 | {
|
---|
225 | NxGetUtilLib()->NxJointDesc_SetGlobalAxis(dis,wsAxis);
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 | NX_INLINE NxJointDesc::NxJointDesc(NxJointType t) : type(t) //constructor sets to default
|
---|
230 | {
|
---|
231 | setToDefault();
|
---|
232 | }
|
---|
233 |
|
---|
234 | NX_INLINE NxJointDesc::~NxJointDesc()
|
---|
235 | {
|
---|
236 | }
|
---|
237 |
|
---|
238 | NX_INLINE void NxJointDesc::setToDefault()
|
---|
239 | {
|
---|
240 | for (int i=0; i<2; i++)
|
---|
241 | {
|
---|
242 | actor[i] = 0;
|
---|
243 | localAxis[i].set(0,0,1);
|
---|
244 | localNormal[i].set(1,0,0);
|
---|
245 | localAnchor[i].zero();
|
---|
246 | }
|
---|
247 |
|
---|
248 | maxForce = NX_MAX_REAL;
|
---|
249 | maxTorque = NX_MAX_REAL;
|
---|
250 | userData = NULL;
|
---|
251 | name = NULL;
|
---|
252 | jointFlags = NX_JF_VISUALIZATION;
|
---|
253 | }
|
---|
254 |
|
---|
255 | NX_INLINE bool NxJointDesc::isValid() const
|
---|
256 | {
|
---|
257 | if (!(actor[0] || actor[1]))
|
---|
258 | return false;
|
---|
259 | //non-null pointers must be dynamic:
|
---|
260 | if (actor[0] && ! actor[0]->isDynamic())
|
---|
261 | return false;
|
---|
262 | if (actor[1] && ! actor[1]->isDynamic())
|
---|
263 | return false;
|
---|
264 |
|
---|
265 | if (type >= NX_JOINT_COUNT)
|
---|
266 | return false;
|
---|
267 | for (int i=0; i<2; i++)
|
---|
268 | {
|
---|
269 | if (localAxis[i].magnitudeSquared() < 0.9f) return false;
|
---|
270 | if (localNormal[i].magnitudeSquared() < 0.9f) return false;
|
---|
271 | //check orthogonal pairs
|
---|
272 | if (fabsf(localAxis[i].dot(localNormal[i])) > 0.1f) return false;
|
---|
273 | }
|
---|
274 | if (maxForce <= 0)
|
---|
275 | return false;
|
---|
276 | if (maxTorque <= 0)
|
---|
277 | return false;
|
---|
278 |
|
---|
279 | return true;
|
---|
280 | }
|
---|
281 |
|
---|
282 | NX_INLINE void NxJointDesc::setGlobalAnchor(const NxVec3 & wsAnchor)
|
---|
283 | {
|
---|
284 | NxJointDesc_SetGlobalAnchor(*this, wsAnchor);
|
---|
285 | }
|
---|
286 |
|
---|
287 | NX_INLINE void NxJointDesc::setGlobalAxis(const NxVec3 & wsAxis)
|
---|
288 | {
|
---|
289 | NxJointDesc_SetGlobalAxis(*this, wsAxis);
|
---|
290 | }
|
---|
291 |
|
---|
292 | /** @} */
|
---|
293 | #endif
|
---|
294 |
|
---|
295 |
|
---|
296 | //AGCOPYRIGHTBEGIN
|
---|
297 | ///////////////////////////////////////////////////////////////////////////
|
---|
298 | // Copyright © 2005 AGEIA Technologies.
|
---|
299 | // All rights reserved. www.ageia.com
|
---|
300 | ///////////////////////////////////////////////////////////////////////////
|
---|
301 | //AGCOPYRIGHTEND
|
---|
302 |
|
---|