Panda3D
Loading...
Searching...
No Matches
physxPulleyJoint.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 physxPulleyJoint.cxx
10 * @author enn0x
11 * @date 2009-10-02
12 */
13
14#include "physxPulleyJoint.h"
16#include "physxMotorDesc.h"
17
18TypeHandle PhysxPulleyJoint::_type_handle;
19
20/**
21 *
22 */
23void PhysxPulleyJoint::
24link(NxJoint *jointPtr) {
25
26 _ptr = jointPtr->isPulleyJoint();
27 _ptr->userData = this;
28 _error_type = ET_ok;
29
30 set_name(jointPtr->getName());
31
32 PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
33 scene->_joints.add(this);
34}
35
36/**
37 *
38 */
39void PhysxPulleyJoint::
40unlink() {
41
42 _ptr->userData = nullptr;
43 _error_type = ET_released;
44
45 PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
46 scene->_joints.remove(this);
47}
48
49/**
50 * Saves the state of the joint object to a descriptor.
51 */
53save_to_desc(PhysxPulleyJointDesc &jointDesc) const {
54
55 nassertv(_error_type == ET_ok);
56 _ptr->saveToDesc(jointDesc._desc);
57}
58
59/**
60 * Loads the entire state of the joint from a descriptor with a single call.
61 */
63load_from_desc(const PhysxPulleyJointDesc &jointDesc) {
64
65 nassertv(_error_type == ET_ok);
66 _ptr->loadFromDesc(jointDesc._desc);
67}
68
69/**
70 * Sets motor parameters for the joint.
71 *
72 * For a positive velTarget, the motor pulls the first body towards its
73 * pulley, for a negative velTarget, the motor pulls the second body towards
74 * its pulley.
75 *
76 * velTarget - the relative velocity the motor is trying to achieve. The
77 * motor will only be able to reach this velocity if the maxForce is
78 * sufficiently large. If the joint is moving faster than this velocity, the
79 * motor will actually try to brake. If you set this to infinity then the
80 * motor will keep speeding up, unless there is some sort of resistance on the
81 * attached bodies.
82 *
83 * maxForce - the maximum force the motor can exert. Zero disables the motor.
84 * Default is 0, should be >= 0. Setting this to a very large value if
85 * velTarget is also very large may not be a good idea.
86 *
87 * freeSpin - if this flag is set, and if the joint is moving faster than
88 * velTarget, then neither braking nor additional acceleration will result.
89 * default: false.
90 *
91 * This automatically enables the motor.
92 */
94set_motor(const PhysxMotorDesc &motor) {
95
96 nassertv(_error_type == ET_ok);
97 _ptr->setMotor(motor._desc);
98}
99
100/**
101 * Sets or clear a single pulley joint flag.
102 */
104set_flag(PhysxPulleyJointFlag flag, bool value) {
105
106 nassertv(_error_type == ET_ok);
107 NxU32 flags = _ptr->getFlags();
108
109 if (value == true) {
110 flags |= flag;
111 }
112 else {
113 flags &= ~(flag);
114 }
115
116 _ptr->setFlags(flags);
117}
118
119/**
120 * Retrieves the value of a single PulleyJointFlag.
121 */
123get_flag(PhysxPulleyJointFlag flag) const {
124
125 nassertr(_error_type == ET_ok, false);
126 return (_ptr->getFlags() & flag) ? true : false;
127}
128
129/**
130 *
131 */
132PhysxMotorDesc PhysxPulleyJoint::
133get_motor() const {
134
135 nassertr(_error_type == ET_ok, false);
136
137 PhysxMotorDesc value;
138 _ptr->getMotor(value._desc);
139 return value;
140}
void set_name(const char *name)
Sets a name string for this object.
Describes a joint motor.
Descriptor class for distance joint.
void set_flag(PhysxPulleyJointFlag flag, bool value)
Sets or clear a single pulley joint flag.
bool get_flag(PhysxPulleyJointFlag flag) const
Retrieves the value of a single PulleyJointFlag.
void load_from_desc(const PhysxPulleyJointDesc &jointDesc)
Loads the entire state of the joint from a descriptor with a single call.
void save_to_desc(PhysxPulleyJointDesc &jointDesc) const
Saves the state of the joint object to a descriptor.
void set_motor(const PhysxMotorDesc &motor)
Sets motor parameters for the joint.
A scene is a collection of bodies, constraints, and effectors which can interact.
Definition physxScene.h:69
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.