Panda3D
collisionLevelStateBase.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 collisionLevelStateBase.cxx
10  * @author drose
11  * @date 2002-03-16
12  */
13 
15 #include "collisionSolid.h"
16 #include "collisionNode.h"
17 #include "config_collide.h"
18 #include "dcast.h"
19 
20 PStatCollector CollisionLevelStateBase::_node_volume_pcollector("Collision Volumes:PandaNode");
21 
22 TypeHandle CollisionLevelStateBase::_type_handle;
23 
24 /**
25  *
26  */
27 void CollisionLevelStateBase::
28 clear() {
29  _colliders.clear();
30  _local_bounds.clear();
31  _parent_bounds.clear();
32 }
33 
34 /**
35  * Indicates an intention to add the indicated number of colliders to the
36  * level state.
37  */
39 reserve(int num_colliders) {
40  _colliders.reserve(num_colliders);
41  _local_bounds.reserve(num_colliders);
42 }
43 
44 /**
45  * Adds the indicated Collider to the set of Colliders in the current level
46  * state.
47  */
49 prepare_collider(const ColliderDef &def, const NodePath &root) {
50  _colliders.push_back(def);
51 
52  const CollisionSolid *collider = def._collider;
53  CPT(BoundingVolume) bv = collider->get_bounds();
54  if (!bv->is_of_type(GeometricBoundingVolume::get_class_type())) {
55  _local_bounds.push_back(nullptr);
56  } else {
57  // We can use a plain pointer, rather than a PT() here, because we know we
58  // are going to save the volume in the vector, below.
60  DCAST_INTO_V(gbv, bv->make_copy());
61 
62  // TODO: we need to make this logic work in the new relative world. The
63  // bounding volume should be extended by the object's motion relative to
64  // each object it is considering a collision with. That makes things
65  // complicated!
66  if (bv->as_bounding_sphere()) {
67  LPoint3 pos_delta = def._node_path.get_pos_delta(root);
68 
69  // LVector3 cap(pos_delta); if(cap.length()>fluid_cap_amount) {
70  // pos_delta=LPoint3(capcap.length())*fluid_cap_amount; }
71  if (pos_delta != LVector3::zero()) {
72  // If the node has a delta, we have to include the starting position
73  // in the volume as well. We only do this for bounding spheres, since
74  // (a) other kinds of volumes may not extend so well, and (b) we've
75  // only implemented fluid-motion detection for CollisionSpheres
76  // anyway.
77  LMatrix4 inv_trans = LMatrix4::translate_mat(-pos_delta);
78  PT(GeometricBoundingVolume) gbv_prev;
79  gbv_prev = DCAST(GeometricBoundingVolume, bv->make_copy());
80 
81  gbv_prev->xform(inv_trans);
82  gbv->extend_by(gbv_prev);
83  }
84  }
85 
86  CPT(TransformState) rel_transform = def._node_path.get_transform(root.get_parent());
87  gbv->xform(rel_transform->get_mat());
88  _local_bounds.push_back(gbv);
89  }
90 
91  _parent_bounds = _local_bounds;
92 }
Indicates a coordinate-system transform on vertices.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The abstract base class for all things that can collide with other things in the world,...
get_parent
Returns the NodePath to the parent of the referenced node: that is, this NodePath,...
Definition: nodePath.h:244
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LVector3 get_pos_delta() const
Returns the delta vector from this node's position in the previous frame (according to set_prev_trans...
Definition: nodePath.cxx:1007
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A lightweight class that represents a single element that may be timed and/or counted via stats.
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void reserve(int num_colliders)
Indicates an intention to add the indicated number of colliders to the level state.
void prepare_collider(const ColliderDef &def, const NodePath &root)
Adds the indicated Collider to the set of Colliders in the current level state.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
Definition: nodePath.cxx:758
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool extend_by(const GeometricBoundingVolume *vol)
Increases the size of the volume to include the given volume.