24 TypeHandle CollisionHandlerFloor::_type_handle;
29 CollisionHandlerFloor::
30 CollisionHandlerFloor() {
39 CollisionHandlerFloor::
40 ~CollisionHandlerFloor() {
71 PN_stdfloat CollisionHandlerFloor::
72 set_highest_collision(
const NodePath &target_node_path,
const NodePath &from_node_path,
const Entries &entries) {
79 PN_stdfloat max_height = 0.0f;
80 PN_stdfloat min_height = 0.0f;
84 Entries::const_iterator ei;
85 for (ei = entries.begin(); ei != entries.end(); ++ei) {
87 nassertr(entry !=
nullptr, 0.0f);
92 if (collide_cat.is_debug()) {
94 <<
"Intersection point detected at " << point <<
"\n";
97 PN_stdfloat height = point[2];
98 if (height < _offset + _reach &&
99 (!got_max || height > max_height)) {
104 if (!got_min || height < min_height) {
111 if (!got_max && got_min) {
115 max_height = min_height;
121 cout<<
"\ncolliding with:\n";
122 for (Colliding::const_iterator i = _current_colliding.begin(); i != _current_colliding.end(); ++i) {
123 (**i).write(cout, 2);
125 cout<<
"\nhighest:\n";
126 highest->write(cout, 2);
132 _current_colliding.clear();
148 bool CollisionHandlerFloor::
155 _current_colliding.clear();
157 FromEntries::const_iterator fi;
158 for (fi = _from_entries.begin(); fi != _from_entries.end(); ++fi) {
159 const NodePath &from_node_path = (*fi).first;
160 const Entries &entries = (*fi).second;
162 Colliders::iterator ci;
163 ci = _colliders.
find(from_node_path);
164 if (ci == _colliders.end()) {
168 << get_type() <<
" doesn't know about "
169 << from_node_path <<
", disabling.\n";
172 ColliderDef &def = (*ci).second;
176 bool got_max =
false;
177 PN_stdfloat max_height = 0.0f;
180 Entries::const_iterator ei;
181 for (ei = entries.begin(); ei != entries.end(); ++ei) {
183 nassertr(entry !=
nullptr,
false);
188 if (collide_cat.is_debug()) {
190 <<
"Intersection point detected at " << point <<
"\n";
193 PN_stdfloat height = point[2];
194 if (!got_max || height > max_height) {
204 _current_colliding.insert(max_entry);
207 PN_stdfloat adjust = max_height + _offset;
209 PN_stdfloat max_height = set_highest_collision(def._target, from_node_path, entries);
212 PN_stdfloat adjust = max_height + _offset;
214 if (!IS_THRESHOLD_ZERO(adjust, 0.001)) {
215 if (collide_cat.is_debug()) {
217 <<
"Adjusting height by " << adjust <<
"\n";
220 if (adjust < 0.0f && _max_velocity != 0.0f) {
221 PN_stdfloat max_adjust =
223 adjust = std::max(adjust, -max_adjust);
227 LVecBase3 pos = trans->get_pos();
229 def._target.set_transform(trans->set_pos(pos));
230 def.updated_transform();
232 apply_linear_force(def, LVector3(0.0f, 0.0f, adjust));
234 if (collide_cat.is_spam()) {
236 <<
"Leaving height unchanged.\n";
249 void CollisionHandlerFloor::
250 apply_linear_force(ColliderDef &def,
const LVector3 &force) {
get_dt
Returns the elapsed time for the previous frame: the number of seconds elapsed between the last two c...
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
Defines a single collision event.
LPoint3 get_surface_point(const NodePath &space) const
Returns the point, on the surface of the "into" object, at which a collision is detected.
get_from_node_path
Returns the NodePath that represents the CollisionNode that contains the CollisionSolid that triggere...
bool has_surface_point() const
Returns true if the surface point has been specified, false otherwise.
void read_datagram(DatagramIterator &source)
Restores the object state from the given datagram, previously obtained using __getstate__.
void write_datagram(Datagram &destination) const
Serializes this object, to implement pickle support.
void write_datagram(Datagram &destination) const
Serializes this object, to implement pickle support.
void read_datagram(DatagramIterator &source)
Restores the object state from the given datagram, previously obtained using __getstate__.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
A class to retrieve the individual data elements previously stored in a Datagram.
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
NodePath find(const std::string &path) const
Searches for a node below the referenced node that matches the indicated string.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.