collision.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "collision.h"
  17. #include <cmath>
  18. #include "mapblock.h"
  19. #include "map.h"
  20. #include "nodedef.h"
  21. #include "gamedef.h"
  22. #ifndef SERVER
  23. #include "client/clientenvironment.h"
  24. #include "client/localplayer.h"
  25. #endif
  26. #include "serverenvironment.h"
  27. #include "server/serveractiveobject.h"
  28. #include "util/timetaker.h"
  29. #include "profiler.h"
  30. #ifdef __FAST_MATH__
  31. #warning "-ffast-math is known to cause bugs in collision code, do not use!"
  32. #endif
  33. namespace {
  34. struct NearbyCollisionInfo {
  35. // node
  36. NearbyCollisionInfo(bool is_ul, int bouncy, v3s16 pos, const aabb3f &box) :
  37. obj(nullptr),
  38. box(box),
  39. position(pos),
  40. bouncy(bouncy),
  41. is_unloaded(is_ul),
  42. is_step_up(false)
  43. {}
  44. // object
  45. NearbyCollisionInfo(ActiveObject *obj, int bouncy, const aabb3f &box) :
  46. obj(obj),
  47. box(box),
  48. bouncy(bouncy),
  49. is_unloaded(false),
  50. is_step_up(false)
  51. {}
  52. inline bool isObject() const { return obj != nullptr; }
  53. ActiveObject *obj;
  54. aabb3f box;
  55. v3s16 position;
  56. u8 bouncy;
  57. // bitfield to save space
  58. bool is_unloaded:1, is_step_up:1;
  59. };
  60. // Helper functions:
  61. // Truncate floating point numbers to specified number of decimal places
  62. // in order to move all the floating point error to one side of the correct value
  63. inline f32 truncate(const f32 val, const f32 factor)
  64. {
  65. return truncf(val * factor) / factor;
  66. }
  67. inline v3f truncate(const v3f vec, const f32 factor)
  68. {
  69. return v3f(
  70. truncate(vec.X, factor),
  71. truncate(vec.Y, factor),
  72. truncate(vec.Z, factor)
  73. );
  74. }
  75. }
  76. // Helper function:
  77. // Checks for collision of a moving aabbox with a static aabbox
  78. // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision
  79. // The time after which the collision occurs is stored in dtime.
  80. CollisionAxis axisAlignedCollision(
  81. const aabb3f &staticbox, const aabb3f &movingbox,
  82. const v3f speed, f32 *dtime)
  83. {
  84. //TimeTaker tt("axisAlignedCollision");
  85. aabb3f relbox(
  86. (movingbox.MaxEdge.X - movingbox.MinEdge.X) + (staticbox.MaxEdge.X - staticbox.MinEdge.X), // sum of the widths
  87. (movingbox.MaxEdge.Y - movingbox.MinEdge.Y) + (staticbox.MaxEdge.Y - staticbox.MinEdge.Y),
  88. (movingbox.MaxEdge.Z - movingbox.MinEdge.Z) + (staticbox.MaxEdge.Z - staticbox.MinEdge.Z),
  89. std::max(movingbox.MaxEdge.X, staticbox.MaxEdge.X) - std::min(movingbox.MinEdge.X, staticbox.MinEdge.X), //outer bounding 'box' dimensions
  90. std::max(movingbox.MaxEdge.Y, staticbox.MaxEdge.Y) - std::min(movingbox.MinEdge.Y, staticbox.MinEdge.Y),
  91. std::max(movingbox.MaxEdge.Z, staticbox.MaxEdge.Z) - std::min(movingbox.MinEdge.Z, staticbox.MinEdge.Z)
  92. );
  93. const f32 dtime_max = *dtime;
  94. f32 inner_margin; // the distance of clipping recovery
  95. f32 distance;
  96. f32 time;
  97. if (speed.Y) {
  98. distance = relbox.MaxEdge.Y - relbox.MinEdge.Y;
  99. *dtime = distance / std::abs(speed.Y);
  100. time = std::max(*dtime, 0.0f);
  101. if (*dtime <= dtime_max) {
  102. inner_margin = std::max(-0.5f * (staticbox.MaxEdge.Y - staticbox.MinEdge.Y), -2.0f);
  103. if ((speed.Y > 0 && staticbox.MinEdge.Y - movingbox.MaxEdge.Y > inner_margin) ||
  104. (speed.Y < 0 && movingbox.MinEdge.Y - staticbox.MaxEdge.Y > inner_margin)) {
  105. if (
  106. (std::max(movingbox.MaxEdge.X + speed.X * time, staticbox.MaxEdge.X)
  107. - std::min(movingbox.MinEdge.X + speed.X * time, staticbox.MinEdge.X)
  108. - relbox.MinEdge.X < 0) &&
  109. (std::max(movingbox.MaxEdge.Z + speed.Z * time, staticbox.MaxEdge.Z)
  110. - std::min(movingbox.MinEdge.Z + speed.Z * time, staticbox.MinEdge.Z)
  111. - relbox.MinEdge.Z < 0)
  112. )
  113. return COLLISION_AXIS_Y;
  114. }
  115. }
  116. else {
  117. return COLLISION_AXIS_NONE;
  118. }
  119. }
  120. // NO else if here
  121. if (speed.X) {
  122. distance = relbox.MaxEdge.X - relbox.MinEdge.X;
  123. *dtime = distance / std::abs(speed.X);
  124. time = std::max(*dtime, 0.0f);
  125. if (*dtime <= dtime_max) {
  126. inner_margin = std::max(-0.5f * (staticbox.MaxEdge.X - staticbox.MinEdge.X), -2.0f);
  127. if ((speed.X > 0 && staticbox.MinEdge.X - movingbox.MaxEdge.X > inner_margin) ||
  128. (speed.X < 0 && movingbox.MinEdge.X - staticbox.MaxEdge.X > inner_margin)) {
  129. if (
  130. (std::max(movingbox.MaxEdge.Y + speed.Y * time, staticbox.MaxEdge.Y)
  131. - std::min(movingbox.MinEdge.Y + speed.Y * time, staticbox.MinEdge.Y)
  132. - relbox.MinEdge.Y < 0) &&
  133. (std::max(movingbox.MaxEdge.Z + speed.Z * time, staticbox.MaxEdge.Z)
  134. - std::min(movingbox.MinEdge.Z + speed.Z * time, staticbox.MinEdge.Z)
  135. - relbox.MinEdge.Z < 0)
  136. )
  137. return COLLISION_AXIS_X;
  138. }
  139. } else {
  140. return COLLISION_AXIS_NONE;
  141. }
  142. }
  143. // NO else if here
  144. if (speed.Z) {
  145. distance = relbox.MaxEdge.Z - relbox.MinEdge.Z;
  146. *dtime = distance / std::abs(speed.Z);
  147. time = std::max(*dtime, 0.0f);
  148. if (*dtime <= dtime_max) {
  149. inner_margin = std::max(-0.5f * (staticbox.MaxEdge.Z - staticbox.MinEdge.Z), -2.0f);
  150. if ((speed.Z > 0 && staticbox.MinEdge.Z - movingbox.MaxEdge.Z > inner_margin) ||
  151. (speed.Z < 0 && movingbox.MinEdge.Z - staticbox.MaxEdge.Z > inner_margin)) {
  152. if (
  153. (std::max(movingbox.MaxEdge.X + speed.X * time, staticbox.MaxEdge.X)
  154. - std::min(movingbox.MinEdge.X + speed.X * time, staticbox.MinEdge.X)
  155. - relbox.MinEdge.X < 0) &&
  156. (std::max(movingbox.MaxEdge.Y + speed.Y * time, staticbox.MaxEdge.Y)
  157. - std::min(movingbox.MinEdge.Y + speed.Y * time, staticbox.MinEdge.Y)
  158. - relbox.MinEdge.Y < 0)
  159. )
  160. return COLLISION_AXIS_Z;
  161. }
  162. }
  163. }
  164. return COLLISION_AXIS_NONE;
  165. }
  166. // Helper function:
  167. // Checks if moving the movingbox up by the given distance would hit a ceiling.
  168. bool wouldCollideWithCeiling(
  169. const std::vector<NearbyCollisionInfo> &cinfo,
  170. const aabb3f &movingbox,
  171. f32 y_increase, f32 d)
  172. {
  173. //TimeTaker tt("wouldCollideWithCeiling");
  174. assert(y_increase >= 0); // pre-condition
  175. for (const auto &it : cinfo) {
  176. const aabb3f &staticbox = it.box;
  177. if ((movingbox.MaxEdge.Y - d <= staticbox.MinEdge.Y) &&
  178. (movingbox.MaxEdge.Y + y_increase > staticbox.MinEdge.Y) &&
  179. (movingbox.MinEdge.X < staticbox.MaxEdge.X) &&
  180. (movingbox.MaxEdge.X > staticbox.MinEdge.X) &&
  181. (movingbox.MinEdge.Z < staticbox.MaxEdge.Z) &&
  182. (movingbox.MaxEdge.Z > staticbox.MinEdge.Z))
  183. return true;
  184. }
  185. return false;
  186. }
  187. static inline void getNeighborConnectingFace(const v3s16 &p,
  188. const NodeDefManager *nodedef, Map *map, MapNode n, int v, int *neighbors)
  189. {
  190. MapNode n2 = map->getNode(p);
  191. if (nodedef->nodeboxConnects(n, n2, v))
  192. *neighbors |= v;
  193. }
  194. collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
  195. f32 pos_max_d, const aabb3f &box_0,
  196. f32 stepheight, f32 dtime,
  197. v3f *pos_f, v3f *speed_f,
  198. v3f accel_f, ActiveObject *self,
  199. bool collideWithObjects)
  200. {
  201. #define PROFILER_NAME(text) (s_env ? ("Server: " text) : ("Client: " text))
  202. static bool time_notification_done = false;
  203. Map *map = &env->getMap();
  204. ServerEnvironment *s_env = dynamic_cast<ServerEnvironment*>(env);
  205. ScopeProfiler sp(g_profiler, PROFILER_NAME("collisionMoveSimple()"), SPT_AVG, PRECISION_MICRO);
  206. collisionMoveResult result;
  207. /*
  208. Calculate new velocity
  209. */
  210. if (dtime > DTIME_LIMIT) {
  211. if (!time_notification_done) {
  212. time_notification_done = true;
  213. warningstream << "collisionMoveSimple: maximum step interval exceeded,"
  214. " lost movement details!"<<std::endl;
  215. }
  216. dtime = DTIME_LIMIT;
  217. } else {
  218. time_notification_done = false;
  219. }
  220. v3f dpos_f = (*speed_f + accel_f * 0.5f * dtime) * dtime;
  221. v3f newpos_f = *pos_f + dpos_f;
  222. *speed_f += accel_f * dtime;
  223. // If the object is static, there are no collisions
  224. if (dpos_f == v3f())
  225. return result;
  226. // Limit speed for avoiding hangs
  227. speed_f->Y = rangelim(speed_f->Y, -5000, 5000);
  228. speed_f->X = rangelim(speed_f->X, -5000, 5000);
  229. speed_f->Z = rangelim(speed_f->Z, -5000, 5000);
  230. *speed_f = truncate(*speed_f, 10000.0f);
  231. /*
  232. Collect node boxes in movement range
  233. */
  234. // cached allocation
  235. thread_local std::vector<NearbyCollisionInfo> cinfo;
  236. cinfo.clear();
  237. {
  238. v3f minpos_f(
  239. MYMIN(pos_f->X, newpos_f.X),
  240. MYMIN(pos_f->Y, newpos_f.Y) + 0.01f * BS, // bias rounding, player often at +/-n.5
  241. MYMIN(pos_f->Z, newpos_f.Z)
  242. );
  243. v3f maxpos_f(
  244. MYMAX(pos_f->X, newpos_f.X),
  245. MYMAX(pos_f->Y, newpos_f.Y),
  246. MYMAX(pos_f->Z, newpos_f.Z)
  247. );
  248. v3s16 min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3s16(1, 1, 1);
  249. v3s16 max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3s16(1, 1, 1);
  250. const auto *nodedef = gamedef->getNodeDefManager();
  251. bool any_position_valid = false;
  252. thread_local std::vector<aabb3f> nodeboxes;
  253. v3s16 p;
  254. for (p.Z = min.Z; p.Z <= max.Z; p.Z++)
  255. for (p.Y = min.Y; p.Y <= max.Y; p.Y++)
  256. for (p.X = min.X; p.X <= max.X; p.X++) {
  257. bool is_position_valid;
  258. MapNode n = map->getNode(p, &is_position_valid);
  259. if (is_position_valid && n.getContent() != CONTENT_IGNORE) {
  260. // Object collides into walkable nodes
  261. any_position_valid = true;
  262. const ContentFeatures &f = nodedef->get(n);
  263. if (!f.walkable)
  264. continue;
  265. // Negative bouncy may have a meaning, but we need +value here.
  266. int n_bouncy_value = abs(itemgroup_get(f.groups, "bouncy"));
  267. u8 neighbors = n.getNeighbors(p, map);
  268. nodeboxes.clear();
  269. n.getCollisionBoxes(nodedef, &nodeboxes, neighbors);
  270. // Calculate float position only once
  271. v3f posf = intToFloat(p, BS);
  272. for (auto box : nodeboxes) {
  273. box.MinEdge += posf;
  274. box.MaxEdge += posf;
  275. cinfo.emplace_back(false, n_bouncy_value, p, box);
  276. }
  277. } else {
  278. // Collide with unloaded nodes (position invalid) and loaded
  279. // CONTENT_IGNORE nodes (position valid)
  280. aabb3f box = getNodeBox(p, BS);
  281. cinfo.emplace_back(true, 0, p, box);
  282. }
  283. }
  284. // Do not move if world has not loaded yet, since custom node boxes
  285. // are not available for collision detection.
  286. // This also intentionally occurs in the case of the object being positioned
  287. // solely on loaded CONTENT_IGNORE nodes, no matter where they come from.
  288. if (!any_position_valid) {
  289. *speed_f = v3f(0, 0, 0);
  290. return result;
  291. }
  292. }
  293. /*
  294. Collect object boxes in movement range
  295. */
  296. auto process_object = [] (ActiveObject *object) {
  297. if (object && object->collideWithObjects()) {
  298. aabb3f box;
  299. if (object->getCollisionBox(&box))
  300. cinfo.emplace_back(object, 0, box);
  301. }
  302. };
  303. if (collideWithObjects) {
  304. // Calculate distance by speed, add own extent and 1.5m of tolerance
  305. const f32 distance = speed_f->getLength() * dtime +
  306. box_0.getExtent().getLength() + 1.5f * BS;
  307. #ifndef SERVER
  308. ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
  309. if (c_env) {
  310. std::vector<DistanceSortedActiveObject> clientobjects;
  311. c_env->getActiveObjects(*pos_f, distance, clientobjects);
  312. for (auto &clientobject : clientobjects) {
  313. // Do collide with everything but itself and the parent CAO
  314. if (!self || (self != clientobject.obj &&
  315. self != clientobject.obj->getParent())) {
  316. process_object(clientobject.obj);
  317. }
  318. }
  319. // add collision with local player
  320. LocalPlayer *lplayer = c_env->getLocalPlayer();
  321. if (lplayer->getParent() == nullptr) {
  322. aabb3f lplayer_collisionbox = lplayer->getCollisionbox();
  323. v3f lplayer_pos = lplayer->getPosition();
  324. lplayer_collisionbox.MinEdge += lplayer_pos;
  325. lplayer_collisionbox.MaxEdge += lplayer_pos;
  326. auto *obj = (ActiveObject*) lplayer->getCAO();
  327. cinfo.emplace_back(obj, 0, lplayer_collisionbox);
  328. }
  329. }
  330. else
  331. #endif
  332. if (s_env) {
  333. // search for objects which are not us, or we are not its parent.
  334. // we directly process the object in this callback to avoid useless
  335. // looping afterwards.
  336. auto include_obj_cb = [self, &process_object] (ServerActiveObject *obj) {
  337. if (!obj->isGone() &&
  338. (!self || (self != obj && self != obj->getParent()))) {
  339. process_object(obj);
  340. }
  341. return false;
  342. };
  343. // nothing is put into this vector
  344. std::vector<ServerActiveObject*> s_objects;
  345. s_env->getObjectsInsideRadius(s_objects, *pos_f, distance, include_obj_cb);
  346. }
  347. }
  348. /*
  349. Collision detection
  350. */
  351. f32 d = 0.0f;
  352. int loopcount = 0;
  353. while(dtime > BS * 1e-10f) {
  354. // Avoid infinite loop
  355. loopcount++;
  356. if (loopcount >= 100) {
  357. warningstream << "collisionMoveSimple: Loop count exceeded, aborting to avoid infiniite loop" << std::endl;
  358. break;
  359. }
  360. aabb3f movingbox = box_0;
  361. movingbox.MinEdge += *pos_f;
  362. movingbox.MaxEdge += *pos_f;
  363. CollisionAxis nearest_collided = COLLISION_AXIS_NONE;
  364. f32 nearest_dtime = dtime;
  365. int nearest_boxindex = -1;
  366. /*
  367. Go through every nodebox, find nearest collision
  368. */
  369. for (u32 boxindex = 0; boxindex < cinfo.size(); boxindex++) {
  370. const NearbyCollisionInfo &box_info = cinfo[boxindex];
  371. // Ignore if already stepped up this nodebox.
  372. if (box_info.is_step_up)
  373. continue;
  374. // Find nearest collision of the two boxes (raytracing-like)
  375. f32 dtime_tmp = nearest_dtime;
  376. CollisionAxis collided = axisAlignedCollision(box_info.box,
  377. movingbox, *speed_f, &dtime_tmp);
  378. if (collided == -1 || dtime_tmp >= nearest_dtime)
  379. continue;
  380. nearest_dtime = dtime_tmp;
  381. nearest_collided = collided;
  382. nearest_boxindex = boxindex;
  383. }
  384. if (nearest_collided == COLLISION_AXIS_NONE) {
  385. // No collision with any collision box.
  386. *pos_f += truncate(*speed_f * dtime, 100.0f);
  387. dtime = 0; // Set to 0 to avoid "infinite" loop due to small FP numbers
  388. } else {
  389. // Otherwise, a collision occurred.
  390. NearbyCollisionInfo &nearest_info = cinfo[nearest_boxindex];
  391. const aabb3f& cbox = nearest_info.box;
  392. //movingbox except moved to the horizontal position it would be after step up
  393. aabb3f stepbox = movingbox;
  394. stepbox.MinEdge.X += speed_f->X * dtime;
  395. stepbox.MinEdge.Z += speed_f->Z * dtime;
  396. stepbox.MaxEdge.X += speed_f->X * dtime;
  397. stepbox.MaxEdge.Z += speed_f->Z * dtime;
  398. // Check for stairs.
  399. bool step_up = (nearest_collided != COLLISION_AXIS_Y) && // must not be Y direction
  400. (movingbox.MinEdge.Y < cbox.MaxEdge.Y) &&
  401. (movingbox.MinEdge.Y + stepheight > cbox.MaxEdge.Y) &&
  402. (!wouldCollideWithCeiling(cinfo, stepbox,
  403. cbox.MaxEdge.Y - movingbox.MinEdge.Y,
  404. d));
  405. // Get bounce multiplier
  406. float bounce = -(float)nearest_info.bouncy / 100.0f;
  407. // Move to the point of collision and reduce dtime by nearest_dtime
  408. if (nearest_dtime < 0) {
  409. // Handle negative nearest_dtime
  410. if (!step_up) {
  411. if (nearest_collided == COLLISION_AXIS_X)
  412. pos_f->X += speed_f->X * nearest_dtime;
  413. if (nearest_collided == COLLISION_AXIS_Y)
  414. pos_f->Y += speed_f->Y * nearest_dtime;
  415. if (nearest_collided == COLLISION_AXIS_Z)
  416. pos_f->Z += speed_f->Z * nearest_dtime;
  417. }
  418. } else {
  419. *pos_f += truncate(*speed_f * nearest_dtime, 100.0f);
  420. dtime -= nearest_dtime;
  421. }
  422. bool is_collision = true;
  423. if (nearest_info.is_unloaded)
  424. is_collision = false;
  425. CollisionInfo info;
  426. if (nearest_info.isObject())
  427. info.type = COLLISION_OBJECT;
  428. else
  429. info.type = COLLISION_NODE;
  430. info.node_p = nearest_info.position;
  431. info.object = nearest_info.obj;
  432. info.old_speed = *speed_f;
  433. info.plane = nearest_collided;
  434. // Set the speed component that caused the collision to zero
  435. if (step_up) {
  436. // Special case: Handle stairs
  437. nearest_info.is_step_up = true;
  438. is_collision = false;
  439. } else if (nearest_collided == COLLISION_AXIS_X) {
  440. if (fabs(speed_f->X) > BS * 3)
  441. speed_f->X *= bounce;
  442. else
  443. speed_f->X = 0;
  444. result.collides = true;
  445. } else if (nearest_collided == COLLISION_AXIS_Y) {
  446. if(fabs(speed_f->Y) > BS * 3)
  447. speed_f->Y *= bounce;
  448. else
  449. speed_f->Y = 0;
  450. result.collides = true;
  451. } else if (nearest_collided == COLLISION_AXIS_Z) {
  452. if (fabs(speed_f->Z) > BS * 3)
  453. speed_f->Z *= bounce;
  454. else
  455. speed_f->Z = 0;
  456. result.collides = true;
  457. }
  458. info.new_speed = *speed_f;
  459. if (info.new_speed.getDistanceFrom(info.old_speed) < 0.1f * BS)
  460. is_collision = false;
  461. if (is_collision) {
  462. info.axis = nearest_collided;
  463. result.collisions.push_back(std::move(info));
  464. }
  465. }
  466. }
  467. /*
  468. Final touches: Check if standing on ground, step up stairs.
  469. */
  470. aabb3f box = box_0;
  471. box.MinEdge += *pos_f;
  472. box.MaxEdge += *pos_f;
  473. for (const auto &box_info : cinfo) {
  474. const aabb3f &cbox = box_info.box;
  475. /*
  476. See if the object is touching ground.
  477. Object touches ground if object's minimum Y is near node's
  478. maximum Y and object's X-Z-area overlaps with the node's
  479. X-Z-area.
  480. */
  481. if (cbox.MaxEdge.X - d > box.MinEdge.X && cbox.MinEdge.X + d < box.MaxEdge.X &&
  482. cbox.MaxEdge.Z - d > box.MinEdge.Z &&
  483. cbox.MinEdge.Z + d < box.MaxEdge.Z) {
  484. if (box_info.is_step_up) {
  485. pos_f->Y += cbox.MaxEdge.Y - box.MinEdge.Y;
  486. box = box_0;
  487. box.MinEdge += *pos_f;
  488. box.MaxEdge += *pos_f;
  489. }
  490. if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.05f) {
  491. result.touching_ground = true;
  492. if (box_info.isObject())
  493. result.standing_on_object = true;
  494. }
  495. }
  496. }
  497. return result;
  498. }