15 #include "collisionHandlerFloor.h"
16 #include "collisionNode.h"
17 #include "collisionEntry.h"
18 #include "config_collide.h"
20 #include "clockObject.h"
22 TypeHandle CollisionHandlerFloor::_type_handle;
29 CollisionHandlerFloor::
30 CollisionHandlerFloor() {
41 CollisionHandlerFloor::
42 ~CollisionHandlerFloor() {
56 PN_stdfloat CollisionHandlerFloor::
57 set_highest_collision(
const NodePath &target_node_path,
const NodePath &from_node_path,
const Entries &entries) {
65 PN_stdfloat max_height = 0.0f;
66 PN_stdfloat min_height = 0.0f;
70 Entries::const_iterator ei;
71 for (ei = entries.begin(); ei != entries.end(); ++ei) {
78 if (collide_cat.is_debug()) {
80 <<
"Intersection point detected at " << point <<
"\n";
83 PN_stdfloat height = point[2];
84 if (height < _offset + _reach &&
85 (!got_max || height > max_height)) {
90 if (!got_min || height < min_height) {
97 if (!got_max && got_min) {
102 max_height = min_height;
108 cout<<
"\ncolliding with:\n";
109 for (Colliding::const_iterator i = _current_colliding.begin(); i != _current_colliding.end(); ++i) {
110 (**i).write(cout, 2);
112 cout<<
"\nhighest:\n";
113 highest->write(cout, 2);
119 _current_colliding.clear();
138 bool CollisionHandlerFloor::
145 _current_colliding.clear();
147 FromEntries::const_iterator fi;
148 for (fi = _from_entries.begin(); fi != _from_entries.end(); ++fi) {
149 const NodePath &from_node_path = (*fi).first;
150 const Entries &entries = (*fi).second;
152 Colliders::iterator ci;
153 ci = _colliders.find(from_node_path);
154 if (ci == _colliders.end()) {
159 << get_type() <<
" doesn't know about "
160 << from_node_path <<
", disabling.\n";
163 ColliderDef &def = (*ci).second;
167 bool got_max =
false;
168 PN_stdfloat max_height = 0.0f;
171 Entries::const_iterator ei;
172 for (ei = entries.begin(); ei != entries.end(); ++ei) {
179 if (collide_cat.is_debug()) {
181 <<
"Intersection point detected at " << point <<
"\n";
184 PN_stdfloat height = point[2];
185 if (!got_max || height > max_height) {
195 _current_colliding.insert(max_entry);
198 PN_stdfloat adjust = max_height + _offset;
200 PN_stdfloat max_height = set_highest_collision(def._target, from_node_path, entries);
203 PN_stdfloat adjust = max_height + _offset;
205 if (!IS_THRESHOLD_ZERO(adjust, 0.001)) {
206 if (collide_cat.is_debug()) {
208 <<
"Adjusting height by " << adjust <<
"\n";
211 if (adjust < 0.0f && _max_velocity != 0.0f) {
212 PN_stdfloat max_adjust =
214 adjust = max(adjust, -max_adjust);
217 CPT(TransformState) trans = def._target.get_transform();
220 def._target.set_transform(trans->set_pos(pos));
221 def.updated_transform();
223 apply_linear_force(def,
LVector3(0.0f, 0.0f, adjust));
225 if (collide_cat.is_spam()) {
227 <<
"Leaving height unchanged.\n";
242 void CollisionHandlerFloor::
243 apply_linear_force(ColliderDef &def,
const LVector3 &force) {
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
This is the base class for all three-component vectors and points.
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 ...
double get_dt(Thread *current_thread=Thread::get_current_thread()) const
Returns the elapsed time for the previous frame: the number of seconds elapsed between the last two c...
LPoint3 get_surface_point(const NodePath &space) const
Returns the point, on the surface of the "into" object, at which a collision is detected.
Defines a single collision event.
bool has_surface_point() const
Returns true if the surface point has been specified, false otherwise.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
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.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...