21 PhysicsObjectCollection::
22 PhysicsObjectCollection() {
28 PhysicsObjectCollection::
30 _physics_objects(copy._physics_objects)
37 void PhysicsObjectCollection::
39 _physics_objects = copy._physics_objects;
51 if (_physics_objects.get_ref_count() > 1) {
52 PhysicsObjects old_physics_objects = _physics_objects;
53 _physics_objects = PhysicsObjects::empty_array(0);
54 _physics_objects.v() = old_physics_objects.v();
57 _physics_objects.push_back(physics_object);
67 int object_index = -1;
68 for (
int i = 0; object_index == -1 && i < (int)_physics_objects.size(); i++) {
69 if (_physics_objects[i] == physics_object) {
74 if (object_index == -1) {
83 if (_physics_objects.get_ref_count() > 1) {
84 PhysicsObjects old_physics_objects = _physics_objects;
85 _physics_objects = PhysicsObjects::empty_array(0);
86 _physics_objects.v() = old_physics_objects.v();
89 _physics_objects.erase(_physics_objects.begin() + object_index);
101 for (
int i = 0; i < other_num_physics_objects; i++) {
113 PhysicsObjects new_physics_objects;
115 for (
int i = 0; i < num_physics_objects; i++) {
118 new_physics_objects.push_back(physics_object);
121 _physics_objects = new_physics_objects;
131 PhysicsObjects new_physics_objects;
134 for (
int i = 0; i < num_physics_objects; i++) {
136 bool duplicated =
false;
138 for (
int j = 0; j < i && !duplicated; j++) {
139 duplicated = (physics_object == get_physics_object(j));
143 new_physics_objects.push_back(physics_object);
147 _physics_objects = new_physics_objects;
157 if (physics_object == get_physics_object(i)) {
169 _physics_objects.clear();
178 return _physics_objects.empty();
184 int PhysicsObjectCollection::
185 get_num_physics_objects()
const {
186 return _physics_objects.size();
193 get_physics_object(
int index)
const {
194 nassertr(index >= 0 && index < (
int)_physics_objects.size(), PT(
PhysicsObject)());
196 return _physics_objects[index];
204 operator [] (
int index)
const {
205 nassertr(index >= 0 && index < (
int)_physics_objects.size(), PT(
PhysicsObject)());
207 return _physics_objects[index];
214 int PhysicsObjectCollection::
216 return _physics_objects.size();
223 void PhysicsObjectCollection::
224 output(std::ostream &out)
const {
226 out <<
"1 PhysicsObject";
236 void PhysicsObjectCollection::
237 write(std::ostream &out,
int indent_level)
const {
239 indent(out, indent_level) << get_physics_object(i) <<
"\n";
bool remove_physics_object(PT(PhysicsObject) physics_object)
Removes the indicated PhysicsObject from the collection.
A body on which physics will be applied.
void clear()
Removes all PhysicsObjects from the collection.
This is a set of zero or more PhysicsObjects.
void add_physics_objects_from(const PhysicsObjectCollection &other)
Adds all the PhysicsObjects indicated in the other collection to this collection.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_num_physics_objects
Returns the number of PhysicsObjects in the collection.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
void remove_physics_objects_from(const PhysicsObjectCollection &other)
Removes from this collection all of the PhysicsObjects listed in the other collection.
void remove_duplicate_physics_objects()
Removes any duplicate entries of the same PhysicsObjects on this collection.
bool is_empty() const
Returns true if there are no PhysicsObjects in the collection, false otherwise.
bool has_physics_object(PT(PhysicsObject) physics_object) const
Returns true if the indicated PhysicsObject appears in this collection, false otherwise.
void add_physics_object(PT(PhysicsObject) physics_object)
Adds a new PhysicsObject to the collection.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.