1 | #ifndef NX_PHYSICS_NXMATERIALDESC
|
---|
2 | #define NX_PHYSICS_NXMATERIALDESC
|
---|
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 "NxSpringDesc.h"
|
---|
16 |
|
---|
17 | /**
|
---|
18 | \brief Flags which control the behavior of a material.
|
---|
19 |
|
---|
20 | @see NxMaterial NxMaterialDesc
|
---|
21 | */
|
---|
22 | enum NxMaterialFlag
|
---|
23 | {
|
---|
24 | /**
|
---|
25 | \brief Flag to enable anisotropic friction computation.
|
---|
26 |
|
---|
27 | For a pair of actors, anisotropic friction is used only if at least one of the two actors' materials are anisotropic.
|
---|
28 | The anisotropic friction parameters for the pair are taken from the material which is more anisotropic (i.e. the difference
|
---|
29 | between its two dynamic friction coefficients is greater).
|
---|
30 |
|
---|
31 | The anisotropy direction of the chosen material is transformed to world space:
|
---|
32 |
|
---|
33 | dirOfAnisotropyWS = shape2world * dirOfAnisotropy
|
---|
34 |
|
---|
35 | Next, the directions of anisotropy in one or more contact planes (i.e. orthogonal to the contact normal) have to be determined.
|
---|
36 | The two directions are:
|
---|
37 |
|
---|
38 | uAxis = (dirOfAnisotropyWS ^ contactNormal).normalize()
|
---|
39 | vAxis = contactNormal ^ uAxis
|
---|
40 |
|
---|
41 | This way [uAxis, contactNormal, vAxis] forms a basis.
|
---|
42 |
|
---|
43 | It may happen, however, that (dirOfAnisotropyWS | contactNormal).magnitude() == 1
|
---|
44 | and then (dirOfAnisotropyWS ^ contactNormal) has zero length. This happens when
|
---|
45 | the contactNormal is coincident to the direction of anisotropy. In this case we perform isotropic friction.
|
---|
46 |
|
---|
47 | <b>Platform:</b>
|
---|
48 | \li PC SW: Yes
|
---|
49 | \li PPU : Yex
|
---|
50 | \li PS3 : Yes
|
---|
51 | \li XB360: Yes
|
---|
52 |
|
---|
53 | @see NxMaterialDesc.dirOfAnisotropy
|
---|
54 | */
|
---|
55 | NX_MF_ANISOTROPIC = 1 << 0,
|
---|
56 |
|
---|
57 | /**
|
---|
58 | \brief If a material with this flag set is involved in the contact, the contact constraints generated behave like a unilateral spring.
|
---|
59 |
|
---|
60 | The user must assign the spring member to point to a NxSpringDesc object.
|
---|
61 | Do not use this together with ::NxWheelShape, that already includes the suspension component automatically.
|
---|
62 |
|
---|
63 | <b>Platform:</b>
|
---|
64 | \li PC SW: Yes
|
---|
65 | \li PPU : No
|
---|
66 | \li PS3 : Yes
|
---|
67 | \li XB360: Yes
|
---|
68 |
|
---|
69 | @see NxWheelShape NxMaterialDesc.spring
|
---|
70 | */
|
---|
71 | NX_MF_SPRING_CONTACT = 1 << 2,
|
---|
72 |
|
---|
73 | /**
|
---|
74 | If this flag is set, friction computations are always skipped between shapes with this material and any other shape.
|
---|
75 | It may be a good idea to use this when all friction is to be performed using the tire friction model (see ::NxWheelShape).
|
---|
76 |
|
---|
77 | <b>Platform:</b>
|
---|
78 | \li PC SW: Yes
|
---|
79 | \li PPU : No
|
---|
80 | \li PS3 : Yes
|
---|
81 | \li XB360: Yes
|
---|
82 |
|
---|
83 | @see NxWheelShape
|
---|
84 | */
|
---|
85 | NX_MF_DISABLE_FRICTION = 1 << 4,
|
---|
86 |
|
---|
87 | /**
|
---|
88 | If this flag is set, strong static friction computations are skipped. These can cause problems for very fast sliding objects that
|
---|
89 | still need precise steering behavior, such as raycast vehicles. It may make sense to reenable this when the car has come to rest to prevent it from
|
---|
90 | creeping down inclines.
|
---|
91 | This setting only matters if the NX_MF_DISABLE_FRICTION bit is 0.
|
---|
92 |
|
---|
93 | <b>Platform:</b>
|
---|
94 | \li PC SW: Yes
|
---|
95 | \li PPU : No
|
---|
96 | \li PS3 : Yes
|
---|
97 | \li XB360: Yes
|
---|
98 |
|
---|
99 | @see NxWheelShape
|
---|
100 | */
|
---|
101 | NX_MF_DISABLE_STRONG_FRICTION = 1 << 5,
|
---|
102 |
|
---|
103 | /**
|
---|
104 | This flag is only used when NX_MF_SPRING_CONTACT is also specified. In this case the spring contact's direction will be determined by the
|
---|
105 | associated capsule shape's axis, rather than the contact normal.
|
---|
106 |
|
---|
107 | <b>Platform:</b>
|
---|
108 | \li PC SW: Yes
|
---|
109 | \li PPU : No
|
---|
110 | \li PS3 : Yes
|
---|
111 | \li XB360: Yes
|
---|
112 |
|
---|
113 | @see NX_MF_SPRING_CONTACT NxWheelShape
|
---|
114 | */
|
---|
115 | NX_MF_WHEEL_AXIS_CONTACT_NORMAL = 1 << 6,
|
---|
116 |
|
---|
117 | //Note: Bits 16-31 are reserved for internal use!
|
---|
118 | };
|
---|
119 |
|
---|
120 | /**
|
---|
121 | Flag that determines the combine mode. When two actors come in contact with eachother, they each have
|
---|
122 | materials with various coefficients, but we only need a single set of coefficients for the pair.
|
---|
123 |
|
---|
124 | Physics doesn't have any inherent combinations because the coefficients are determined empirically on a case by case
|
---|
125 | basis. However, simulating this with a pairwise lookup table is often impractical.
|
---|
126 |
|
---|
127 | For this reason the following combine behaviors are available:
|
---|
128 |
|
---|
129 | NX_CM_AVERAGE = 2,
|
---|
130 | NX_CM_MIN = 0,
|
---|
131 | NX_CM_MULTIPLY = 1,
|
---|
132 | NX_CM_MAX = 3,
|
---|
133 |
|
---|
134 | The effective combine mode for the pair is max(material0.combineMode, material1.combineMode).
|
---|
135 |
|
---|
136 | <b>Platform:</b>
|
---|
137 | \li PC SW: Yes
|
---|
138 | \li PPU : No
|
---|
139 | \li PS3 : Yes
|
---|
140 | \li XB360: Yes
|
---|
141 |
|
---|
142 | @see NxMaterial NxMaterialDesc NxMaterialDesc.frictionCombineMode NxMaterialDesc.restitutionCombineMode
|
---|
143 | */
|
---|
144 | enum NxCombineMode
|
---|
145 | {
|
---|
146 | NX_CM_AVERAGE = 0, //!< Average: (a + b)/2.
|
---|
147 | NX_CM_MIN = 1, //!< Minimum: min(a,b)
|
---|
148 | NX_CM_MULTIPLY = 2, //!< Mutiply: a*b
|
---|
149 | NX_CM_MAX = 3, //!< Maximum: max(a,b)
|
---|
150 | NX_CM_N_VALUES = 4, //this a sentinel to denote the number of possible values. We assert that the variable's value is smaller than this.
|
---|
151 | NX_CM_PAD_32 = 0xffffffff
|
---|
152 | };
|
---|
153 |
|
---|
154 |
|
---|
155 | /**
|
---|
156 | \brief Descriptor of #NxMaterial.
|
---|
157 |
|
---|
158 | @see NxMaterial NxScene.createMaterial()
|
---|
159 | */
|
---|
160 | class NxMaterialDesc
|
---|
161 | {
|
---|
162 | public:
|
---|
163 | /**
|
---|
164 | coefficient of dynamic friction -- should be in [0, 1] and also be less or equal to staticFriction.
|
---|
165 | if flags & NX_MF_ANISOTROPIC is set, then this value is used for the primary direction of anisotropy (U axis)
|
---|
166 |
|
---|
167 | <b>Range:</b> [0,1]<br>
|
---|
168 | <b>Default:</b> 0.0
|
---|
169 |
|
---|
170 | <b>Platform:</b>
|
---|
171 | \li PC SW: Yes
|
---|
172 | \li PPU : Yes
|
---|
173 | \li PS3 : Yes
|
---|
174 | \li XB360: Yes
|
---|
175 |
|
---|
176 | @see flags frictionCombineMode
|
---|
177 | */
|
---|
178 | NxReal dynamicFriction;
|
---|
179 |
|
---|
180 | /**
|
---|
181 | coefficient of static friction -- should be in [0, +inf]
|
---|
182 | if flags & NX_MF_ANISOTROPIC is set, then this value is used for the primary direction of anisotropy (U axis)
|
---|
183 |
|
---|
184 | <b>Range:</b> [0,inf]<br>
|
---|
185 | <b>Default:</b> 0.0
|
---|
186 |
|
---|
187 | <b>Platform:</b>
|
---|
188 | \li PC SW: Yes
|
---|
189 | \li PPU : Yes
|
---|
190 | \li PS3 : Yes
|
---|
191 | \li XB360: Yes
|
---|
192 |
|
---|
193 | @see flags frictionCombineMode
|
---|
194 | */
|
---|
195 | NxReal staticFriction;
|
---|
196 |
|
---|
197 | /**
|
---|
198 | coefficient of restitution -- 0 makes the object bounce as little as possible, higher values up to 1.0 result in more bounce.
|
---|
199 |
|
---|
200 | <b>Range:</b> [0,1]<br>
|
---|
201 | <b>Default:</b> 0.0
|
---|
202 |
|
---|
203 | <b>Platform:</b>
|
---|
204 | \li PC SW: Yes
|
---|
205 | \li PPU : Yes
|
---|
206 | \li PS3 : Yes
|
---|
207 | \li XB360: Yes
|
---|
208 |
|
---|
209 | @see flags restitutionCombineMode
|
---|
210 | */
|
---|
211 | NxReal restitution;
|
---|
212 |
|
---|
213 | /**
|
---|
214 | anisotropic dynamic friction coefficient for along the secondary (V) axis of anisotropy.
|
---|
215 | This is only used if flags & NX_MF_ANISOTROPIC is set.
|
---|
216 |
|
---|
217 | <b>Range:</b> [0,1]<br>
|
---|
218 | <b>Default:</b> 0.0
|
---|
219 |
|
---|
220 | <b>Platform:</b>
|
---|
221 | \li PC SW: Yes
|
---|
222 | \li PPU : Yes
|
---|
223 | \li PS3 : Yes
|
---|
224 | \li XB360: Yes
|
---|
225 |
|
---|
226 | @see flags dynamicFriction
|
---|
227 | */
|
---|
228 | NxReal dynamicFrictionV;
|
---|
229 |
|
---|
230 | /**
|
---|
231 | anisotropic static friction coefficient for along the secondary (V) axis of anisotropy.
|
---|
232 | This is only used if flags & NX_MF_ANISOTROPIC is set.
|
---|
233 |
|
---|
234 | <b>Range:</b> [0,inf]<br>
|
---|
235 | <b>Default:</b> 0.0
|
---|
236 |
|
---|
237 | <b>Platform:</b>
|
---|
238 | \li PC SW: Yes
|
---|
239 | \li PPU : Yes
|
---|
240 | \li PS3 : Yes
|
---|
241 | \li XB360: Yes
|
---|
242 |
|
---|
243 | @see flags staticFriction
|
---|
244 | */
|
---|
245 | NxReal staticFrictionV;
|
---|
246 |
|
---|
247 | /**
|
---|
248 | shape space direction (unit vector) of anisotropy.
|
---|
249 | This is only used if flags & NX_MF_ANISOTROPIC is set.
|
---|
250 |
|
---|
251 | <b>Range:</b> direction vector<br>
|
---|
252 | <b>Default:</b> 1.0f,0.0f,0.0f
|
---|
253 |
|
---|
254 | <b>Platform:</b>
|
---|
255 | \li PC SW: Yes
|
---|
256 | \li PPU : Yes
|
---|
257 | \li PS3 : Yes
|
---|
258 | \li XB360: Yes
|
---|
259 |
|
---|
260 | @see flags staticFrictionV dynamicFrictionV
|
---|
261 | */
|
---|
262 | NxVec3 dirOfAnisotropy;
|
---|
263 |
|
---|
264 | /**
|
---|
265 | Flags, a combination of the bits defined by the enum ::NxMaterialFlag .
|
---|
266 |
|
---|
267 | <b>Default:</b> 0
|
---|
268 |
|
---|
269 | <b>Platform:</b>
|
---|
270 | \li PC SW: Yes
|
---|
271 | \li PPU : Partial
|
---|
272 | \li PS3 : Yes
|
---|
273 | \li XB360: Yes
|
---|
274 |
|
---|
275 | @see NxMaterialFlag
|
---|
276 | */
|
---|
277 | NxU32 flags;
|
---|
278 |
|
---|
279 | /**
|
---|
280 | Friction combine mode. See the enum ::NxCombineMode .
|
---|
281 |
|
---|
282 | <b>Default:</b> NX_CM_AVERAGE
|
---|
283 |
|
---|
284 | <b>Platform:</b>
|
---|
285 | \li PC SW: Yes
|
---|
286 | \li PPU : No
|
---|
287 | \li PS3 : Yes
|
---|
288 | \li XB360: Yes
|
---|
289 |
|
---|
290 | @see NxCombineMode staticFriction dynamicFriction
|
---|
291 | */
|
---|
292 | NxCombineMode frictionCombineMode;
|
---|
293 |
|
---|
294 | /**
|
---|
295 | Restitution combine mode. See the enum ::NxCombineMode .
|
---|
296 |
|
---|
297 | <b>Default:</b> NX_CM_AVERAGE
|
---|
298 |
|
---|
299 | <b>Platform:</b>
|
---|
300 | \li PC SW: Yes
|
---|
301 | \li PPU : No
|
---|
302 | \li PS3 : Yes
|
---|
303 | \li XB360: Yes
|
---|
304 |
|
---|
305 | @see NxCombineMode restitution
|
---|
306 | */
|
---|
307 | NxCombineMode restitutionCombineMode;
|
---|
308 |
|
---|
309 | /**
|
---|
310 | additional spring data for special materials with flag NX_MF_SPRING_CONTACT.
|
---|
311 | The object pointed to will be copied by the SDK at material creation time.
|
---|
312 |
|
---|
313 | Note: This replaces programData and programDataSize used in prior versions.
|
---|
314 |
|
---|
315 | <b>Range:</b> See #NxSpringDesc<br>
|
---|
316 | <b>Default:</b> NULL
|
---|
317 |
|
---|
318 | <b>Platform:</b>
|
---|
319 | \li PC SW: Yes
|
---|
320 | \li PPU : No
|
---|
321 | \li PS3 : Yes
|
---|
322 | \li XB360: Yes
|
---|
323 |
|
---|
324 | @see flags NxSpringDesc
|
---|
325 | */
|
---|
326 | NxSpringDesc * spring;
|
---|
327 |
|
---|
328 | /**
|
---|
329 | \brief constructor sets to default.
|
---|
330 | */
|
---|
331 | NX_INLINE NxMaterialDesc();
|
---|
332 | /**
|
---|
333 | \brief (re)sets the structure to the default.
|
---|
334 | */
|
---|
335 | NX_INLINE void setToDefault();
|
---|
336 | /**
|
---|
337 | \brief Returns true if the descriptor is valid.
|
---|
338 |
|
---|
339 | \return true if the current settings are valid
|
---|
340 | */
|
---|
341 | NX_INLINE bool isValid() const;
|
---|
342 | };
|
---|
343 |
|
---|
344 | NX_INLINE NxMaterialDesc::NxMaterialDesc()
|
---|
345 | {
|
---|
346 | setToDefault();
|
---|
347 | }
|
---|
348 |
|
---|
349 | NX_INLINE void NxMaterialDesc::setToDefault()
|
---|
350 | {
|
---|
351 | dynamicFriction = 0.0f;
|
---|
352 | staticFriction = 0.0f;
|
---|
353 | restitution = 0.0f;
|
---|
354 |
|
---|
355 |
|
---|
356 | dynamicFrictionV= 0.0f;
|
---|
357 | staticFrictionV = 0.0f;
|
---|
358 |
|
---|
359 | dirOfAnisotropy.set(1,0,0);
|
---|
360 | flags = 0;
|
---|
361 | frictionCombineMode = NX_CM_AVERAGE;
|
---|
362 | restitutionCombineMode = NX_CM_AVERAGE;
|
---|
363 | spring = 0;
|
---|
364 | }
|
---|
365 |
|
---|
366 | NX_INLINE bool NxMaterialDesc::isValid() const
|
---|
367 | {
|
---|
368 | if(dynamicFriction < 0.0f || dynamicFriction > 1.0f)
|
---|
369 | return false;
|
---|
370 | if(staticFriction < 0.0f)
|
---|
371 | return false;
|
---|
372 | if(restitution < 0.0f || restitution > 1.0f)
|
---|
373 | return false;
|
---|
374 |
|
---|
375 |
|
---|
376 | if (flags & NX_MF_ANISOTROPIC)
|
---|
377 | {
|
---|
378 | NxReal ad = dirOfAnisotropy.magnitudeSquared();
|
---|
379 | if (ad < 0.98f || ad > 1.03f)
|
---|
380 | return false;
|
---|
381 | if(dynamicFrictionV < 0.0f || dynamicFrictionV > 1.0f)
|
---|
382 | return false;
|
---|
383 | if(staticFrictionV < 0.0f)
|
---|
384 | return false;
|
---|
385 | }
|
---|
386 | /*
|
---|
387 | if (flags & NX_MF_MOVING_SURFACE)
|
---|
388 | {
|
---|
389 | NxReal md = dirOfMotion.magnitudeSquared();
|
---|
390 | if (md < 0.98f || md > 1.03f)
|
---|
391 | return false;
|
---|
392 | }
|
---|
393 | */
|
---|
394 | if (frictionCombineMode >= NX_CM_N_VALUES)
|
---|
395 | return false;
|
---|
396 | if (restitutionCombineMode >= NX_CM_N_VALUES)
|
---|
397 | return false;
|
---|
398 |
|
---|
399 | return true;
|
---|
400 | }
|
---|
401 |
|
---|
402 | /** @} */
|
---|
403 | #endif
|
---|
404 |
|
---|
405 |
|
---|
406 | //AGCOPYRIGHTBEGIN
|
---|
407 | ///////////////////////////////////////////////////////////////////////////
|
---|
408 | // Copyright © 2005 AGEIA Technologies.
|
---|
409 | // All rights reserved. www.ageia.com
|
---|
410 | ///////////////////////////////////////////////////////////////////////////
|
---|
411 | //AGCOPYRIGHTEND
|
---|
412 |
|
---|