Panda3D
 All Classes Functions Variables Enumerations
physxJointDesc.cxx
1 // Filename: physxJointDesc.cxx
2 // Created by: enn0x (28Sep09)
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 "physxJointDesc.h"
16 #include "physxManager.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PhysxJointDesc::set_name
20 // Access: Published
21 // Description: Sets a possible debug name.
22 ////////////////////////////////////////////////////////////////////
24 set_name(const char *name) {
25 
26  _name = name ? name : "";
27  ptr()->name = _name.c_str();
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: PhysxJointDesc::set_max_force
32 // Access: Published
33 // Description: Set a possible debug name.
34 ////////////////////////////////////////////////////////////////////
36 set_max_force(float force) {
37 
38  ptr()->maxForce = force;
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: PhysxJointDesc::set_max_torque
43 // Access: Published
44 // Description: Set the maximum angular force (torque) that the
45 // joint can withstand before breaking, must be
46 // positive.
47 ////////////////////////////////////////////////////////////////////
49 set_max_torque(float torque) {
50 
51  ptr()->maxTorque = torque;
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: PhysxJointDesc::set_solver_extrapolation_factor
56 // Access: Published
57 // Description: Set the extrapolation factor for solving joint
58 // constraints.
59 ////////////////////////////////////////////////////////////////////
62 
63  ptr()->solverExtrapolationFactor = factor;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: PhysxJointDesc::set_actor
68 // Access: Published
69 // Description: Set the two actors connected by the joint.
70 // idx must be either 0 or 1.
71 ////////////////////////////////////////////////////////////////////
73 set_actor(unsigned int idx, const PhysxActor &actor) {
74 
75  nassertv_always(idx < 2);
76  ptr()->actor[idx] = actor.ptr();
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: PhysxJointDesc::set_local_normal
81 // Access: Published
82 // Description: Set the X axis of joint space, in actor[i]'s space,
83 // orthogonal to localAxis[i].
84 // idx must be either 0 or 1.
85 ////////////////////////////////////////////////////////////////////
87 set_local_normal(unsigned int idx, const LVector3f &normal) {
88 
89  nassertv_always(idx < 2);
90  ptr()->localNormal[idx] = PhysxManager::vec3_to_nxVec3(normal);
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: PhysxJointDesc::set_local_axis
95 // Access: Published
96 // Description: Set the Z axis of joint space, in actor[i]'s space.
97 // This is the primary axis of the joint.
98 // idx must be either 0 or 1.
99 ////////////////////////////////////////////////////////////////////
100 void PhysxJointDesc::
101 set_local_axis(unsigned int idx, const LVector3f &axis) {
102 
103  nassertv_always(idx < 2);
104  ptr()->localAxis[idx] = PhysxManager::vec3_to_nxVec3(axis);
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: PhysxJointDesc::set_local_anchor
109 // Access: Published
110 // Description: Set the attachment point of joint in actor[i]'s
111 // space. idx must be either 0 or 1.
112 ////////////////////////////////////////////////////////////////////
113 void PhysxJointDesc::
114 set_local_anchor(unsigned int idx, const LPoint3f &anchor) {
115 
116  nassertv_always(idx < 2);
117  ptr()->localAnchor[idx] = PhysxManager::point3_to_nxVec3(anchor);
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: PhysxJointDesc::set_joint_flag
122 // Access: Published
123 // Description: Set or clear a single JointFlag.
124 ////////////////////////////////////////////////////////////////////
125 void PhysxJointDesc::
126 set_joint_flag(PhysxJointFlag flag, bool value) {
127 
128  if (value == true) {
129  ptr()->jointFlags |= flag;
130  }
131  else {
132  ptr()->jointFlags &= ~(flag);
133  }
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: PhysxJointDesc::set_global_axis
138 // Access: Published
139 // Description: Set the local axis/normal using a world space axis.
140 ////////////////////////////////////////////////////////////////////
141 void PhysxJointDesc::
143 
144  ptr()->setGlobalAxis(PhysxManager::vec3_to_nxVec3(axis));
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: PhysxJointDesc::set_global_anchor
149 // Access: Published
150 // Description: Set the anchor using a world space point.
151 ////////////////////////////////////////////////////////////////////
152 void PhysxJointDesc::
153 set_global_anchor(const LPoint3f &anchor) {
154 
155  ptr()->setGlobalAnchor(PhysxManager::point3_to_nxVec3(anchor));
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: PhysxJointDesc::get_name
160 // Access: Published
161 // Description:
162 ////////////////////////////////////////////////////////////////////
163 const char *PhysxJointDesc::
164 get_name() const {
165 
166  return ptr()->name;
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: PhysxJointDesc::get_max_force
171 // Access: Published
172 // Description:
173 ////////////////////////////////////////////////////////////////////
174 float PhysxJointDesc::
175 get_max_force() const {
176 
177  return ptr()->maxForce;
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: PhysxJointDesc::get_max_torque
182 // Access: Published
183 // Description:
184 ////////////////////////////////////////////////////////////////////
185 float PhysxJointDesc::
186 get_max_torque() const {
187 
188  return ptr()->maxTorque;
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: PhysxJointDesc::get_solver_extrapolation_factor
193 // Access: Published
194 // Description:
195 ////////////////////////////////////////////////////////////////////
196 float PhysxJointDesc::
197 get_solver_extrapolation_factor() const {
198 
199  return ptr()->solverExtrapolationFactor;
200 }
201 
202 ////////////////////////////////////////////////////////////////////
203 // Function: PhysxJointDesc::get_local_normal
204 // Access: Published
205 // Description:
206 ////////////////////////////////////////////////////////////////////
207 LVector3f PhysxJointDesc::
208 get_local_normal(unsigned int idx) const {
209 
210  nassertr_always(idx < 2, LVector3f::zero());
211  return PhysxManager::nxVec3_to_vec3(ptr()->localNormal[idx]);
212 }
213 
214 ////////////////////////////////////////////////////////////////////
215 // Function: PhysxJointDesc::get_local_axis
216 // Access: Published
217 // Description:
218 ////////////////////////////////////////////////////////////////////
219 LVector3f PhysxJointDesc::
220 get_local_axis(unsigned int idx) const {
221 
222  nassertr_always(idx < 2, LVector3f::zero());
223  return PhysxManager::nxVec3_to_vec3(ptr()->localAxis[idx]);
224 }
225 
226 ////////////////////////////////////////////////////////////////////
227 // Function: PhysxJointDesc::get_local_anchor
228 // Access: Published
229 // Description:
230 ////////////////////////////////////////////////////////////////////
231 LPoint3f PhysxJointDesc::
232 get_local_anchor(unsigned int idx) const {
233 
234  nassertr_always(idx < 2, LPoint3f::zero());
235  return PhysxManager::nxVec3_to_point3(ptr()->localAnchor[idx]);
236 }
237 
238 ////////////////////////////////////////////////////////////////////
239 // Function: PhysxJointDesc::get_joint_flag
240 // Access: Published
241 // Description:
242 ////////////////////////////////////////////////////////////////////
243 bool PhysxJointDesc::
244 get_joint_flag(const PhysxJointFlag flag) const {
245 
246  return (ptr()->jointFlags & flag) ? true : false;
247 }
248 
249 ////////////////////////////////////////////////////////////////////
250 // Function: PhysxJointDesc::get_actor
251 // Access: Published
252 // Description:
253 ////////////////////////////////////////////////////////////////////
254 PhysxActor *PhysxJointDesc::
255 get_actor(unsigned int idx) const {
256 
257  nassertr_always(idx < 2, NULL);
258 
259  NxActor *actorPtr = ptr()->actor[idx];
260  if (actorPtr == NULL) {
261  return NULL;
262  }
263  else {
264  return (PhysxActor *)(actorPtr->userData);
265  }
266 }
267 
void set_global_axis(const LVector3f &axis)
Set the local axis/normal using a world space axis.
void set_local_anchor(unsigned int idx, const LPoint3f &anchor)
Set the attachment point of joint in actor[i]&#39;s space.
void set_local_axis(unsigned int idx, const LVector3f &axis)
Set the Z axis of joint space, in actor[i]&#39;s space.
static const LPoint3f & zero()
Returns a zero-length point.
Definition: lpoint3.h:258
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:77
static const LVector3f & zero()
Returns a zero-length vector.
Definition: lvector3.h:269
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
void set_joint_flag(PhysxJointFlag flag, bool value)
Set or clear a single JointFlag.
void set_max_torque(float torque)
Set the maximum angular force (torque) that the joint can withstand before breaking, must be positive.
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
void set_name(const char *name)
Sets a possible debug name.
Actors are the main simulation objects.
Definition: physxActor.h:48
void set_actor(unsigned int idx, const PhysxActor &actor)
Set the two actors connected by the joint.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
Definition: physxManager.I:88
void set_global_anchor(const LPoint3f &anchor)
Set the anchor using a world space point.
void set_local_normal(unsigned int idx, const LVector3f &normal)
Set the X axis of joint space, in actor[i]&#39;s space, orthogonal to localAxis[i].
void set_solver_extrapolation_factor(float factor)
Set the extrapolation factor for solving joint constraints.
void set_max_force(float force)
Set a possible debug name.