15 #include "odeJointCollection.h"
18 OdeJointCollection() {
23 _joints(copy._joints) {
26 void OdeJointCollection::
28 _joints = copy._joints;
31 void OdeJointCollection::
38 if (_joints.get_ref_count() > 1) {
39 Joints old_joints = _joints;
40 _joints = Joints::empty_array(0);
41 _joints.v() = old_joints.v();
44 _joints.push_back(joint);
47 bool OdeJointCollection::
48 remove_joint(
const OdeJoint &joint) {
50 for (
int i = 0; joint_index == -1 && i < (int)_joints.size(); i++) {
51 if (_joints[i] == joint) {
56 if (joint_index == -1) {
66 if (_joints.get_ref_count() > 1) {
67 Joints old_joints = _joints;
68 _joints = Joints::empty_array(0);
69 _joints.v() = old_joints.v();
72 _joints.erase(_joints.begin() + joint_index);
76 void OdeJointCollection::
78 int other_num_joints = other.get_num_joints();
79 for (
int i = 0; i < other_num_joints; i++) {
80 add_joint(other.get_joint(i));
84 void OdeJointCollection::
87 int num_joints = get_num_joints();
88 for (
int i = 0; i < num_joints; i++) {
90 if (!other.has_joint(joint)) {
91 new_joints.push_back(joint);
97 void OdeJointCollection::
98 remove_duplicate_joints() {
101 int num_joints = get_num_joints();
102 for (
int i = 0; i < num_joints; i++) {
104 bool duplicated =
false;
106 for (
int j = 0; j < i && !duplicated; j++) {
107 duplicated = (joint == get_joint(j));
111 new_joints.push_back(joint);
115 _joints = new_joints;
118 bool OdeJointCollection::
119 has_joint(
const OdeJoint &joint)
const {
120 for (
int i = 0; i < get_num_joints(); i++) {
121 if (joint == get_joint(i)) {
128 void OdeJointCollection::
133 bool OdeJointCollection::
135 return _joints.empty();
138 int OdeJointCollection::
139 get_num_joints()
const {
140 return _joints.size();
144 get_joint(
int index)
const {
145 nassertr(index >= 0 && index < (
int)_joints.size(),
OdeJoint());
146 return _joints[index];
150 operator [] (
int index)
const {
151 return get_joint(index);
162 return _joints.size();
int size() const
Returns the number of joints in the collection.