Panda3D
physxMaterialDesc.cxx
1 // Filename: physxMaterialDesc.cxx
2 // Created by: enn0x (21Sep09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "physxMaterialDesc.h"
16 #include "physxManager.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PhysxMaterialDesc::set_restitution
20 // Access: Published
21 // Description: Sets the coefficient of restitution -- 0 makes the
22 // object bounce as little as possible, higher values
23 // up to 1.0 result in more bounce. Note that values
24 // close to or above 1 may cause stability problems
25 // and/or increasing energy. Range: [0,1]
26 // Default: 0.0
27 ////////////////////////////////////////////////////////////////////
29 set_restitution(float restitution) {
30 
31  _desc.restitution = restitution;
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: PhysxMaterialDesc::set_static_friction
36 // Access: Published
37 // Description: Sets the coefficient of static friction -- should
38 // be in [0, +inf].
39 // If the flag MF_anisotropic is set, then this value
40 // is used for the primary direction of anisotropy
41 // (U axis).
42 ////////////////////////////////////////////////////////////////////
44 set_static_friction(float coef) {
45 
46  _desc.staticFriction = coef;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: PhysxMaterialDesc::set_dynamic_friction
51 // Access: Published
52 // Description: Sets the coefficient of dynamic friction -- should
53 // be in [0, +inf]. If set to greater than
54 // staticFriction, the effective value of staticFriction
55 // will be increased to match.
56 // If the flag MF_anisotropic is set, then this value
57 // is used for the primary direction of anisotropy
58 // (U axis).
59 ////////////////////////////////////////////////////////////////////
61 set_dynamic_friction(float coef) {
62 
63  _desc.dynamicFriction = coef;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: PhysxMaterialDesc::set_static_friction_v
68 // Access: Published
69 // Description: Sets the anisotropic static friction coefficient
70 // for along the secondary (V) axis of anisotropy.
71 // This is only used if the flag MF_anisotropic is
72 // set.
73 ////////////////////////////////////////////////////////////////////
75 set_static_friction_v(float coef) {
76 
77  _desc.staticFrictionV = coef;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: PhysxMaterialDesc::set_dynamic_friction_v
82 // Access: Published
83 // Description: Sets the anisotropic dynamic friction coefficient
84 // for along the secondary (V) axis of anisotropy.
85 // This is only used if the flag MF_anisotropic is
86 // set.
87 ////////////////////////////////////////////////////////////////////
90 
91  _desc.dynamicFrictionV = coef;
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: PhysxMaterialDesc::set_flag
96 // Access: Published
97 // Description: Sets flags which control the behavior of a
98 // material.
99 ////////////////////////////////////////////////////////////////////
101 set_flag(PhysxMaterialFlag flag, bool value) {
102 
103  if (value == true) {
104  _desc.flags |= flag;
105  }
106  else {
107  _desc.flags &= ~(flag);
108  }
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: PhysxMaterialDesc::set_dir_of_anisotropy
113 // Access: Published
114 // Description: Sets the shape space direction (unit vector) of
115 // anisotropy.
116 // This is only used if the flag MF_anisotropic is
117 // set.
118 ////////////////////////////////////////////////////////////////////
121 
122  _desc.dirOfAnisotropy = PhysxManager::vec3_to_nxVec3(dir);
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: PhysxMaterialDesc::set_friction_combine_mode
127 // Access: Published
128 // Description: Sets the friction combine mode.
129 // - CM_average : Average: (a + b)/2.
130 // - CM_min : Minimum: min(a,b).
131 // - CM_multiply : Multiply: a*b.
132 // - CM_max : Maximum: max(a,b).
133 ////////////////////////////////////////////////////////////////////
135 set_friction_combine_mode(PhysxCombineMode mode) {
136 
137  _desc.frictionCombineMode = (NxCombineMode)mode;
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: PhysxMaterialDesc::set_restitution_combine_mode
142 // Access: Published
143 // Description: Sets the restitution combine mode.
144 // - CM_average : Average: (a + b)/2.
145 // - CM_min : Minimum: min(a,b).
146 // - CM_multiply : Multiply: a*b.
147 // - CM_max : Maximum: max(a,b).
148 ////////////////////////////////////////////////////////////////////
150 set_restitution_combine_mode(PhysxCombineMode mode) {
151 
152  _desc.restitutionCombineMode = (NxCombineMode)mode;
153 }
154 
155 ////////////////////////////////////////////////////////////////////
156 // Function: PhysxMaterialDesc::get_restitution
157 // Access: Published
158 // Description: Returns the coefficient of restitution.
159 ////////////////////////////////////////////////////////////////////
162 
163  return _desc.restitution;
164 }
165 
166 ////////////////////////////////////////////////////////////////////
167 // Function: PhysxMaterialDesc::get_static_friction
168 // Access: Published
169 // Description: Retruns the coefficient of static friction.
170 ////////////////////////////////////////////////////////////////////
173 
174  return _desc.staticFriction;
175 }
176 
177 ////////////////////////////////////////////////////////////////////
178 // Function: PhysxMaterialDesc::get_dynamic_friction
179 // Access: Published
180 // Description: Returns the coefficient of dynamic friction.
181 ////////////////////////////////////////////////////////////////////
184 
185  return _desc.dynamicFriction;
186 }
187 
188 ////////////////////////////////////////////////////////////////////
189 // Function: PhysxMaterialDesc::get_static_friction_v
190 // Access: Published
191 // Description: Returns the anisotropic static friction coefficient
192 // for along the secondary (V) axis of anisotropy.
193 ////////////////////////////////////////////////////////////////////
196 
197  return _desc.staticFrictionV;
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function: PhysxMaterialDesc::get_dynamic_friction_v
202 // Access: Published
203 // Description: Returns the anisotropic dynamic friction
204 // coefficient for along the secondary (V) axis of
205 // anisotropy.
206 ////////////////////////////////////////////////////////////////////
209 
210  return _desc.dynamicFrictionV;
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: PhysxMaterialDesc::get_flag
215 // Access: Published
216 // Description: Returns flags which control the behavior of a
217 // material.
218 ////////////////////////////////////////////////////////////////////
220 get_flag(PhysxMaterialFlag flag) const {
221 
222  return (_desc.flags & flag) ? true : false;
223 }
224 
225 ////////////////////////////////////////////////////////////////////
226 // Function: PhysxMaterialDesc::get_dir_of_anisotropy
227 // Access: Published
228 // Description: Returns the shape space direction (unit vector) of
229 // anisotropy.
230 ////////////////////////////////////////////////////////////////////
233 
234  return PhysxManager::nxVec3_to_vec3(_desc.dirOfAnisotropy);
235 }
236 
237 ////////////////////////////////////////////////////////////////////
238 // Function: PhysxMaterialDesc::get_friction_combine_mode
239 // Access: Published
240 // Description: Returns the friction combine mode.
241 ////////////////////////////////////////////////////////////////////
242 PhysxEnums::PhysxCombineMode PhysxMaterialDesc::
244 
245  return (PhysxCombineMode)_desc.frictionCombineMode;
246 }
247 
248 ////////////////////////////////////////////////////////////////////
249 // Function: PhysxMaterialDesc::get_restitution_combine_mode
250 // Access: Published
251 // Description: Returns the restitution combine mode.
252 ////////////////////////////////////////////////////////////////////
253 PhysxEnums::PhysxCombineMode PhysxMaterialDesc::
255 
256  return (PhysxCombineMode)_desc.restitutionCombineMode;
257 }
258 
float get_static_friction_v() const
Returns the anisotropic static friction coefficient for along the secondary (V) axis of anisotropy...
void set_dynamic_friction_v(float coef)
Sets the anisotropic dynamic friction coefficient for along the secondary (V) axis of anisotropy...
void set_flag(PhysxMaterialFlag flag, bool value)
Sets flags which control the behavior of a material.
float get_restitution() const
Returns the coefficient of restitution.
PhysxCombineMode get_restitution_combine_mode() const
Returns the restitution combine mode.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
LVector3f get_dir_of_anisotropy() const
Returns the shape space direction (unit vector) of anisotropy.
bool get_flag(PhysxMaterialFlag flag) const
Returns flags which control the behavior of a material.
void set_dynamic_friction(float coef)
Sets the coefficient of dynamic friction – should be in [0, +inf].
void set_dir_of_anisotropy(const LVector3f dir)
Sets the shape space direction (unit vector) of anisotropy.
void set_restitution(float rest)
Sets the coefficient of restitution – 0 makes the object bounce as little as possible, higher values up to 1.0 result in more bounce.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:33
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:44
float get_dynamic_friction() const
Returns the coefficient of dynamic friction.
float get_dynamic_friction_v() const
Returns the anisotropic dynamic friction coefficient for along the secondary (V) axis of anisotropy...
void set_friction_combine_mode(PhysxCombineMode mode)
Sets the friction combine mode.
void set_static_friction(float coef)
Sets the coefficient of static friction – should be in [0, +inf].
float get_static_friction() const
Retruns the coefficient of static friction.
PhysxCombineMode get_friction_combine_mode() const
Returns the friction combine mode.
void set_restitution_combine_mode(PhysxCombineMode mode)
Sets the restitution combine mode.
void set_static_friction_v(float coef)
Sets the anisotropic static friction coefficient for along the secondary (V) axis of anisotropy...