Panda3D
Loading...
Searching...
No Matches
physxJoint.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file physxJoint.cxx
10 * @author enn0x
11 * @date 2009-10-02
12 */
13
14#include "physxJoint.h"
15#include "physxManager.h"
16#include "physxActor.h"
17#include "physxScene.h"
19#include "physxDistanceJoint.h"
20#include "physxFixedJoint.h"
23#include "physxPrismaticJoint.h"
24#include "physxPulleyJoint.h"
25#include "physxRevoluteJoint.h"
26#include "physxSphericalJoint.h"
27#include "physxD6Joint.h"
28
29TypeHandle PhysxJoint::_type_handle;
30
31/**
32 *
33 */
34void PhysxJoint::
35release() {
36
37 nassertv(_error_type == ET_ok);
38
39 unlink();
40 ptr()->getScene().releaseJoint(*ptr());
41}
42
43/**
44 *
45 */
46PhysxJoint *PhysxJoint::
47factory(NxJointType shapeType) {
48
49 switch (shapeType) {
50
51 case NX_JOINT_PRISMATIC:
52 return new PhysxPrismaticJoint();
53
54 case NX_JOINT_REVOLUTE:
55 return new PhysxRevoluteJoint();
56
57 case NX_JOINT_CYLINDRICAL:
58 return new PhysxCylindricalJoint();
59
60 case NX_JOINT_SPHERICAL:
61 return new PhysxSphericalJoint();
62
63 case NX_JOINT_POINT_ON_LINE:
64 return new PhysxPointOnLineJoint();
65
66 case NX_JOINT_POINT_IN_PLANE:
67 return new PhysxPointInPlaneJoint();
68
69 case NX_JOINT_DISTANCE:
70 return new PhysxDistanceJoint();
71
72 case NX_JOINT_PULLEY:
73 return new PhysxPulleyJoint();
74
75 case NX_JOINT_FIXED:
76 return new PhysxFixedJoint();
77
78 case NX_JOINT_D6:
79 return new PhysxD6Joint();
80 }
81
82 physx_cat.error() << "Unknown joint type.\n";
83 return nullptr;
84}
85
86/**
87 * Sets a name string for this object. The name can be retrieved again with
88 * get_name(). This is for debugging and is not used by the physics engine.
89 */
91set_name(const char *name) {
92
93 nassertv(_error_type == ET_ok);
94
95 _name = name ? name : "";
96 ptr()->setName(_name.c_str());
97}
98
99/**
100 * Returns the name string.
101 */
102const char *PhysxJoint::
103get_name() const {
104
105 nassertr(_error_type == ET_ok, "");
106 return ptr()->getName();
107}
108
109/**
110 * Retrieves the actor which this joint is associated with.
111 */
113get_actor(unsigned int idx) const {
114
115 nassertr_always(idx < 2, nullptr);
116 nassertr(_error_type == ET_ok, nullptr);
117
118 NxActor *actorPtr[2];
119 ptr()->getActors(&actorPtr[0], &actorPtr[1]);
120 return (PhysxActor *)(actorPtr[idx]->userData);
121}
122
123/**
124 * Retrieves the scene which this joint is associated with.
125 */
127get_scene() const {
128
129 nassertr(_error_type == ET_ok, nullptr);
130 return (PhysxScene *)(ptr()->getScene().userData);
131}
132
133/**
134 * Sets the point where the two actors are attached, specified in global
135 * coordinates.
136 */
138set_global_anchor(const LPoint3f &anchor) {
139
140 nassertv(_error_type == ET_ok);
141 ptr()->setGlobalAnchor(PhysxManager::point3_to_nxVec3(anchor));
142}
143
144/**
145 * Retrieves the joint anchor.
146 */
148get_global_anchor() const {
149
150 nassertr(_error_type == ET_ok, LPoint3f::zero());
151 return PhysxManager::nxVec3_to_point3(ptr()->getGlobalAnchor());
152}
153
154/**
155 * Sets the direction of the joint's primary axis, specified in global
156 * coordinates.
157 */
159set_global_axis(const LVector3f &axis) {
160
161 nassertv(_error_type == ET_ok);
162 ptr()->setGlobalAxis(PhysxManager::vec3_to_nxVec3(axis));
163}
164
165/**
166 * Retrieves the joint axis.
167 */
169get_global_axis() const {
170
171 nassertr(_error_type == ET_ok, LVector3f::zero());
172 return PhysxManager::nxVec3_to_vec3(ptr()->getGlobalAxis());
173}
174
175/**
176 * Sets the maximum force magnitude that the joint is able to withstand
177 * without breaking.
178 *
179 * If the joint force rises above this threshold, the joint breaks, and
180 * becomes disabled.
181 *
182 * There are two values, one for linear forces, and one for angular forces.
183 * Both values are used directly as a value for the maximum impulse tolerated
184 * by the joint constraints.
185 *
186 * Both force values are NX_MAX_REAL by default. This setting makes the joint
187 * unbreakable. The values should always be nonnegative.
188 *
189 * The distinction between maxForce and maxTorque is dependent on how the
190 * joint is implemented internally, which may not be obvious. For example
191 * what appears to be an angular degree of freedom may be constrained
192 * indirectly by a linear constraint.
193 *
194 * So in most practical applications the user should set both maxTorque and
195 * maxForce to low values.
196 */
198set_breakable(float maxForce, float maxTorque) {
199
200 nassertv(_error_type == ET_ok);
201 ptr()->setBreakable(maxForce, maxTorque);
202}
203
204/**
205 * Switch between acceleration and force based spring.
206 */
208set_use_acceleration_spring(bool value) {
209
210 nassertv(_error_type == ET_ok);
211 ptr()->setUseAccelerationSpring(value);
212}
213
214/**
215 * Checks whether acceleration spring is used.
216 */
219
220 nassertr(_error_type == ET_ok, false);
221 return ptr()->getUseAccelerationSpring();
222}
223
224/**
225 * Sets the solver extrapolation factor.
226 */
229
230 nassertv(_error_type == ET_ok);
231 ptr()->setSolverExtrapolationFactor(factor);
232}
233
234/**
235 * Retrieves the solver extrapolation factor.
236 */
239
240 nassertr(_error_type == ET_ok, false);
241 return ptr()->getSolverExtrapolationFactor();
242}
243
244/**
245 * Sets the limit point. The point is specified in the global coordinate
246 * frame.
247 *
248 * All types of joints may be limited with the same system: You may elect a
249 * point attached to one of the two actors to act as the limit point. You may
250 * also specify several planes attached to the other actor.
251 *
252 * The points and planes move together with the actor they are attached to.
253 *
254 * The simulation then makes certain that the pair of actors only move
255 * relative to each other so that the limit point stays on the positive side
256 * of all limit planes.
257 *
258 * The default limit point is (0,0,0) in the local frame of actor2. Calling
259 * this deletes all existing limit planes
260 */
262set_limit_point(const LPoint3f &pos, bool isOnActor2) {
263
264 nassertv(_error_type == ET_ok);
265 ptr()->setLimitPoint(PhysxManager::point3_to_nxVec3(pos), isOnActor2);
266}
267
268/**
269 * Adds a limit plane. The parameters are given in global coordinates. The
270 * plane is affixed to the actor that does not have the limit point.
271 *
272 * The normal of the plane points toward the positive side of the plane, and
273 * thus toward the limit point. If the normal points away from the limit
274 * point at the time of this call, the method returns false and the limit
275 * plane is ignored.
276 */
278add_limit_plane(const LVector3f &normal, const LPoint3f &pointInPlane, float restitution) {
279
280 nassertv(_error_type == ET_ok);
281 ptr()->addLimitPlane(PhysxManager::vec3_to_nxVec3(normal),
282 PhysxManager::point3_to_nxVec3(pointInPlane),
283 restitution);
284}
285
286/**
287 * Deletes all limit planes added to the joint.
288 */
291
292 nassertv(_error_type == ET_ok);
293 ptr()->purgeLimitPlanes();
294}
Actors are the main simulation objects.
Definition physxActor.h:44
Cylindrical Joints permit relative translational movement between two bodies along an axis,...
A D6 joint is a general constraint between two actors.
A distance joint maintains a certain distance between two points on two actors.
A fixed joint permits no relative movement between two bodies.
Abstract base class for the different types of joints.
Definition physxJoint.h:32
PhysxActor * get_actor(unsigned int idx) const
Retrieves the actor which this joint is associated with.
void add_limit_plane(const LVector3f &normal, const LPoint3f &pointInPlane, float restitution=0.0f)
Adds a limit plane.
const char * get_name() const
Returns the name string.
float get_solver_extrapolation_factor() const
Retrieves the solver extrapolation factor.
void purge_limit_planes()
Deletes all limit planes added to the joint.
PhysxScene * get_scene() const
Retrieves the scene which this joint is associated with.
void set_limit_point(const LPoint3f &pos, bool isOnActor2=true)
Sets the limit point.
void set_name(const char *name)
Sets a name string for this object.
void set_use_acceleration_spring(bool value)
Switch between acceleration and force based spring.
void set_global_anchor(const LPoint3f &anchor)
Sets the point where the two actors are attached, specified in global coordinates.
void set_breakable(float maxForce, float maxTorque)
Sets the maximum force magnitude that the joint is able to withstand without breaking.
void set_global_axis(const LVector3f &axis)
Sets the direction of the joint's primary axis, specified in global coordinates.
void set_solver_extrapolation_factor(float factor)
Sets the solver extrapolation factor.
LPoint3f get_global_anchor() const
Retrieves the joint anchor.
LVector3f get_global_axis() const
Retrieves the joint axis.
bool get_use_acceleration_spring() const
Checks whether acceleration spring is used.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
A point in plane joint constrains a point on one body to only move inside a plane attached to another...
A point on line joint constrains a point on one body to only move along a line attached to another bo...
A prismatic joint permits relative translational movement between two bodies along an axis,...
A pulley joint simulates a rope between two objects passing over two pulleys.
A joint which behaves in a similar way to a hinge or axel.
A scene is a collection of bodies, constraints, and effectors which can interact.
Definition physxScene.h:69
A sphere joint constrains two points on two bodies to coincide.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.