15 #include "collisionHandlerPusher.h" 16 #include "collisionNode.h" 17 #include "collisionEntry.h" 18 #include "collisionPolygon.h" 19 #include "config_collide.h" 23 TypeHandle CollisionHandlerPusher::_type_handle;
45 CollisionHandlerPusher::
46 CollisionHandlerPusher() {
47 _horizontal = pushers_horizontal;
55 CollisionHandlerPusher::
56 ~CollisionHandlerPusher() {
70 bool CollisionHandlerPusher::
74 FromEntries::const_iterator fi;
75 for (fi = _from_entries.begin(); fi != _from_entries.end(); ++fi) {
76 const NodePath &from_node_path = (*fi).first;
77 const Entries &entries = (*fi).second;
79 Colliders::iterator ci;
80 ci = _colliders.
find(from_node_path);
81 if (ci == _colliders.end()) {
86 <<
"CollisionHandlerPusher doesn't know about " 87 << from_node_path <<
", disabling.\n";
90 ColliderDef &def = (*ci).second;
100 typedef epvector<ShoveData> Shoves;
103 Entries::const_iterator ei;
104 for (ei = entries.begin(); ei != entries.end(); ++ei) {
113 if (!entry->
get_all(def._target, surface_point, normal, interior_point)) {
115 if (collide_cat.is_debug()) {
117 <<
"Cannot shove on " << from_node_path <<
" for collision into " 123 if (!surface_point.almost_equal(interior_point)) {
134 sd._length = (surface_point - interior_point).length();
139 if (collide_cat.is_debug()) {
141 <<
"Shove on " << from_node_path <<
" from " 143 <<
" times " << sd._length <<
"\n";
147 shoves.push_back(sd);
152 if (!shoves.empty()) {
160 for (si = shoves.begin(); si != shoves.end(); ++si) {
163 for (sj = shoves.begin(); sj != si; ++sj) {
166 PN_stdfloat d = sd._vector.dot(sd2._vector);
167 if (collide_cat.is_debug()) {
169 <<
"Considering dot product " << d <<
"\n";
175 if (sd2._length < sd._length) {
202 if (collide_cat.is_debug()) {
204 <<
"Discarding shove from convex corner.\n";
214 if (sd2._length < sd._length) {
227 LVector3 net_shove(0.0f, 0.0f, 0.0f);
228 LVector3 force_normal(0.0f, 0.0f, 0.0f);
229 for (si = shoves.begin(); si != shoves.end(); ++si) {
232 net_shove += sd._vector * sd._length;
233 force_normal += sd._vector;
238 if (collide_cat.is_debug()) {
240 <<
"Net shove on " << from_node_path <<
" is: " 241 << net_shove <<
"\n";
246 CPT(TransformState) trans = def._target.get_transform();
248 pos += net_shove * trans->get_mat();
249 def._target.set_transform(trans->set_pos(pos));
250 def.updated_transform();
254 apply_net_shove(def, net_shove, force_normal);
255 apply_linear_force(def, force_normal);
270 void CollisionHandlerPusher::
271 apply_net_shove(ColliderDef &def,
const LVector3 &net_shove,
281 void CollisionHandlerPusher::
282 apply_linear_force(ColliderDef &def,
const LVector3 &force_normal) {
bool get_all(const NodePath &space, LPoint3 &surface_point, LVector3 &surface_normal, LPoint3 &interior_point) const
Simultaneously transforms the surface point, surface normal, and interior point of the collision into...
This is the base class for all three-component vectors and points.
bool is_exact_type(TypeHandle handle) const
Returns true if the current object is the indicated type exactly.
NodePath get_into_node_path() const
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
virtual LPoint3 get_collision_origin() const
Returns the point in space deemed to be the "origin" of the solid for collision purposes.
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
The ShoveData class is used within CollisionHandlerPusher::handle_entries(), to track multiple shoves...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
NodePath find(const string &path) const
Searches for a node below the referenced node that matches the indicated string.
const CollisionSolid * get_into() const
Returns the CollisionSolid pointer for the particular solid was collided into.
Defines a single collision event.
NodePath get_from_node_path() const
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
TypeHandle is the identifier used to differentiate C++ class types.
bool normalize()
Normalizes the vector in place.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...