collision.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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. #endif
  25. #include "serverenvironment.h"
  26. #include "serverobject.h"
  27. #include "util/timetaker.h"
  28. #include "profiler.h"
  29. // float error is 10 - 9.96875 = 0.03125
  30. //#define COLL_ZERO 0.032 // broken unit tests
  31. #define COLL_ZERO 0
  32. struct NearbyCollisionInfo {
  33. NearbyCollisionInfo(bool is_ul, bool is_obj, int bouncy,
  34. const v3s16 &pos, const aabb3f &box) :
  35. is_unloaded(is_ul),
  36. is_object(is_obj),
  37. bouncy(bouncy),
  38. position(pos),
  39. box(box)
  40. {}
  41. bool is_unloaded;
  42. bool is_step_up = false;
  43. bool is_object;
  44. int bouncy;
  45. v3s16 position;
  46. aabb3f box;
  47. };
  48. // Helper function:
  49. // Checks for collision of a moving aabbox with a static aabbox
  50. // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision
  51. // The time after which the collision occurs is stored in dtime.
  52. int axisAlignedCollision(
  53. const aabb3f &staticbox, const aabb3f &movingbox,
  54. const v3f &speed, f32 d, f32 *dtime)
  55. {
  56. //TimeTaker tt("axisAlignedCollision");
  57. f32 xsize = (staticbox.MaxEdge.X - staticbox.MinEdge.X) - COLL_ZERO; // reduce box size for solve collision stuck (flying sand)
  58. f32 ysize = (staticbox.MaxEdge.Y - staticbox.MinEdge.Y); // - COLL_ZERO; // Y - no sense for falling, but maybe try later
  59. f32 zsize = (staticbox.MaxEdge.Z - staticbox.MinEdge.Z) - COLL_ZERO;
  60. aabb3f relbox(
  61. movingbox.MinEdge.X - staticbox.MinEdge.X,
  62. movingbox.MinEdge.Y - staticbox.MinEdge.Y,
  63. movingbox.MinEdge.Z - staticbox.MinEdge.Z,
  64. movingbox.MaxEdge.X - staticbox.MinEdge.X,
  65. movingbox.MaxEdge.Y - staticbox.MinEdge.Y,
  66. movingbox.MaxEdge.Z - staticbox.MinEdge.Z
  67. );
  68. if(speed.X > 0) // Check for collision with X- plane
  69. {
  70. if (relbox.MaxEdge.X <= d) {
  71. *dtime = -relbox.MaxEdge.X / speed.X;
  72. if ((relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
  73. (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO) &&
  74. (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
  75. (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
  76. return 0;
  77. }
  78. else if(relbox.MinEdge.X > xsize)
  79. {
  80. return -1;
  81. }
  82. }
  83. else if(speed.X < 0) // Check for collision with X+ plane
  84. {
  85. if (relbox.MinEdge.X >= xsize - d) {
  86. *dtime = (xsize - relbox.MinEdge.X) / speed.X;
  87. if ((relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
  88. (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO) &&
  89. (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
  90. (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
  91. return 0;
  92. }
  93. else if(relbox.MaxEdge.X < 0)
  94. {
  95. return -1;
  96. }
  97. }
  98. // NO else if here
  99. if(speed.Y > 0) // Check for collision with Y- plane
  100. {
  101. if (relbox.MaxEdge.Y <= d) {
  102. *dtime = -relbox.MaxEdge.Y / speed.Y;
  103. if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
  104. (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
  105. (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
  106. (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
  107. return 1;
  108. }
  109. else if(relbox.MinEdge.Y > ysize)
  110. {
  111. return -1;
  112. }
  113. }
  114. else if(speed.Y < 0) // Check for collision with Y+ plane
  115. {
  116. if (relbox.MinEdge.Y >= ysize - d) {
  117. *dtime = (ysize - relbox.MinEdge.Y) / speed.Y;
  118. if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
  119. (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
  120. (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
  121. (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
  122. return 1;
  123. }
  124. else if(relbox.MaxEdge.Y < 0)
  125. {
  126. return -1;
  127. }
  128. }
  129. // NO else if here
  130. if(speed.Z > 0) // Check for collision with Z- plane
  131. {
  132. if (relbox.MaxEdge.Z <= d) {
  133. *dtime = -relbox.MaxEdge.Z / speed.Z;
  134. if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
  135. (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
  136. (relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
  137. (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO))
  138. return 2;
  139. }
  140. //else if(relbox.MinEdge.Z > zsize)
  141. //{
  142. // return -1;
  143. //}
  144. }
  145. else if(speed.Z < 0) // Check for collision with Z+ plane
  146. {
  147. if (relbox.MinEdge.Z >= zsize - d) {
  148. *dtime = (zsize - relbox.MinEdge.Z) / speed.Z;
  149. if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
  150. (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
  151. (relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
  152. (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO))
  153. return 2;
  154. }
  155. //else if(relbox.MaxEdge.Z < 0)
  156. //{
  157. // return -1;
  158. //}
  159. }
  160. return -1;
  161. }
  162. // Helper function:
  163. // Checks if moving the movingbox up by the given distance would hit a ceiling.
  164. bool wouldCollideWithCeiling(
  165. const std::vector<NearbyCollisionInfo> &cinfo,
  166. const aabb3f &movingbox,
  167. f32 y_increase, f32 d)
  168. {
  169. //TimeTaker tt("wouldCollideWithCeiling");
  170. assert(y_increase >= 0); // pre-condition
  171. for (const auto &it : cinfo) {
  172. const aabb3f &staticbox = it.box;
  173. if ((movingbox.MaxEdge.Y - d <= staticbox.MinEdge.Y) &&
  174. (movingbox.MaxEdge.Y + y_increase > staticbox.MinEdge.Y) &&
  175. (movingbox.MinEdge.X < staticbox.MaxEdge.X) &&
  176. (movingbox.MaxEdge.X > staticbox.MinEdge.X) &&
  177. (movingbox.MinEdge.Z < staticbox.MaxEdge.Z) &&
  178. (movingbox.MaxEdge.Z > staticbox.MinEdge.Z))
  179. return true;
  180. }
  181. return false;
  182. }
  183. static inline void getNeighborConnectingFace(const v3s16 &p,
  184. const NodeDefManager *nodedef, Map *map, MapNode n, int v, int *neighbors)
  185. {
  186. MapNode n2 = map->getNodeNoEx(p);
  187. if (nodedef->nodeboxConnects(n, n2, v))
  188. *neighbors |= v;
  189. }
  190. collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
  191. f32 pos_max_d, const aabb3f &box_0,
  192. f32 stepheight, f32 dtime,
  193. v3f *pos_f, v3f *speed_f,
  194. v3f accel_f, ActiveObject *self,
  195. bool collideWithObjects)
  196. {
  197. static bool time_notification_done = false;
  198. Map *map = &env->getMap();
  199. //TimeTaker tt("collisionMoveSimple");
  200. ScopeProfiler sp(g_profiler, "collisionMoveSimple avg", SPT_AVG);
  201. collisionMoveResult result;
  202. /*
  203. Calculate new velocity
  204. */
  205. if (dtime > 0.5f) {
  206. if (!time_notification_done) {
  207. time_notification_done = true;
  208. infostream << "collisionMoveSimple: maximum step interval exceeded,"
  209. " lost movement details!"<<std::endl;
  210. }
  211. dtime = 0.5f;
  212. } else {
  213. time_notification_done = false;
  214. }
  215. *speed_f += accel_f * dtime;
  216. // If there is no speed, there are no collisions
  217. if (speed_f->getLength() == 0)
  218. return result;
  219. // Limit speed for avoiding hangs
  220. speed_f->Y = rangelim(speed_f->Y, -5000, 5000);
  221. speed_f->X = rangelim(speed_f->X, -5000, 5000);
  222. speed_f->Z = rangelim(speed_f->Z, -5000, 5000);
  223. /*
  224. Collect node boxes in movement range
  225. */
  226. std::vector<NearbyCollisionInfo> cinfo;
  227. {
  228. //TimeTaker tt2("collisionMoveSimple collect boxes");
  229. ScopeProfiler sp2(g_profiler, "collisionMoveSimple collect boxes avg", SPT_AVG);
  230. v3f newpos_f = *pos_f + *speed_f * dtime;
  231. v3f minpos_f(
  232. MYMIN(pos_f->X, newpos_f.X),
  233. MYMIN(pos_f->Y, newpos_f.Y) + 0.01f * BS, // bias rounding, player often at +/-n.5
  234. MYMIN(pos_f->Z, newpos_f.Z)
  235. );
  236. v3f maxpos_f(
  237. MYMAX(pos_f->X, newpos_f.X),
  238. MYMAX(pos_f->Y, newpos_f.Y),
  239. MYMAX(pos_f->Z, newpos_f.Z)
  240. );
  241. v3s16 min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3s16(1, 1, 1);
  242. v3s16 max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3s16(1, 1, 1);
  243. bool any_position_valid = false;
  244. v3s16 p;
  245. for (p.X = min.X; p.X <= max.X; p.X++)
  246. for (p.Y = min.Y; p.Y <= max.Y; p.Y++)
  247. for (p.Z = min.Z; p.Z <= max.Z; p.Z++) {
  248. bool is_position_valid;
  249. MapNode n = map->getNodeNoEx(p, &is_position_valid);
  250. if (is_position_valid && n.getContent() != CONTENT_IGNORE) {
  251. // Object collides into walkable nodes
  252. any_position_valid = true;
  253. const NodeDefManager *nodedef = gamedef->getNodeDefManager();
  254. const ContentFeatures &f = nodedef->get(n);
  255. if (!f.walkable)
  256. continue;
  257. int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
  258. int neighbors = 0;
  259. if (f.drawtype == NDT_NODEBOX &&
  260. f.node_box.type == NODEBOX_CONNECTED) {
  261. v3s16 p2 = p;
  262. p2.Y++;
  263. getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors);
  264. p2 = p;
  265. p2.Y--;
  266. getNeighborConnectingFace(p2, nodedef, map, n, 2, &neighbors);
  267. p2 = p;
  268. p2.Z--;
  269. getNeighborConnectingFace(p2, nodedef, map, n, 4, &neighbors);
  270. p2 = p;
  271. p2.X--;
  272. getNeighborConnectingFace(p2, nodedef, map, n, 8, &neighbors);
  273. p2 = p;
  274. p2.Z++;
  275. getNeighborConnectingFace(p2, nodedef, map, n, 16, &neighbors);
  276. p2 = p;
  277. p2.X++;
  278. getNeighborConnectingFace(p2, nodedef, map, n, 32, &neighbors);
  279. }
  280. std::vector<aabb3f> nodeboxes;
  281. n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors);
  282. // Calculate float position only once
  283. v3f posf = intToFloat(p, BS);
  284. for (auto box : nodeboxes) {
  285. box.MinEdge += posf;
  286. box.MaxEdge += posf;
  287. cinfo.emplace_back(false, false, n_bouncy_value, p, box);
  288. }
  289. } else {
  290. // Collide with unloaded nodes (position invalid) and loaded
  291. // CONTENT_IGNORE nodes (position valid)
  292. aabb3f box = getNodeBox(p, BS);
  293. cinfo.emplace_back(true, false, 0, p, box);
  294. }
  295. }
  296. // Do not move if world has not loaded yet, since custom node boxes
  297. // are not available for collision detection.
  298. // This also intentionally occurs in the case of the object being positioned
  299. // solely on loaded CONTENT_IGNORE nodes, no matter where they come from.
  300. if (!any_position_valid) {
  301. *speed_f = v3f(0, 0, 0);
  302. return result;
  303. }
  304. } // tt2
  305. if(collideWithObjects)
  306. {
  307. ScopeProfiler sp2(g_profiler, "collisionMoveSimple objects avg", SPT_AVG);
  308. //TimeTaker tt3("collisionMoveSimple collect object boxes");
  309. /* add object boxes to cinfo */
  310. std::vector<ActiveObject*> objects;
  311. #ifndef SERVER
  312. ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
  313. if (c_env != 0) {
  314. // Calculate distance by speed, add own extent and 1.5m of tolerance
  315. f32 distance = speed_f->getLength() * dtime +
  316. box_0.getExtent().getLength() + 1.5f * BS;
  317. std::vector<DistanceSortedActiveObject> clientobjects;
  318. c_env->getActiveObjects(*pos_f, distance, clientobjects);
  319. for (auto &clientobject : clientobjects) {
  320. // Do collide with everything but itself and the parent CAO
  321. if (!self || (self != clientobject.obj &&
  322. self != clientobject.obj->getParent())) {
  323. objects.push_back((ActiveObject*) clientobject.obj);
  324. }
  325. }
  326. }
  327. else
  328. #endif
  329. {
  330. ServerEnvironment *s_env = dynamic_cast<ServerEnvironment*>(env);
  331. if (s_env != NULL) {
  332. // Calculate distance by speed, add own extent and 1.5m of tolerance
  333. f32 distance = speed_f->getLength() * dtime +
  334. box_0.getExtent().getLength() + 1.5f * BS;
  335. std::vector<u16> s_objects;
  336. s_env->getObjectsInsideRadius(s_objects, *pos_f, distance);
  337. for (u16 obj_id : s_objects) {
  338. ServerActiveObject *current = s_env->getActiveObject(obj_id);
  339. if (!self || (self != current &&
  340. self != current->getParent())) {
  341. objects.push_back((ActiveObject*)current);
  342. }
  343. }
  344. }
  345. }
  346. for (std::vector<ActiveObject*>::const_iterator iter = objects.begin();
  347. iter != objects.end(); ++iter) {
  348. ActiveObject *object = *iter;
  349. if (object) {
  350. aabb3f object_collisionbox;
  351. if (object->getCollisionBox(&object_collisionbox) &&
  352. object->collideWithObjects()) {
  353. cinfo.emplace_back(false, true, 0, v3s16(), object_collisionbox);
  354. }
  355. }
  356. }
  357. } //tt3
  358. /*
  359. Collision detection
  360. */
  361. /*
  362. Collision uncertainty radius
  363. Make it a bit larger than the maximum distance of movement
  364. */
  365. f32 d = pos_max_d * 1.1f;
  366. // A fairly large value in here makes moving smoother
  367. //f32 d = 0.15*BS;
  368. // This should always apply, otherwise there are glitches
  369. assert(d > pos_max_d); // invariant
  370. int loopcount = 0;
  371. while(dtime > BS * 1e-10f) {
  372. //TimeTaker tt3("collisionMoveSimple dtime loop");
  373. ScopeProfiler sp2(g_profiler, "collisionMoveSimple dtime loop avg", SPT_AVG);
  374. // Avoid infinite loop
  375. loopcount++;
  376. if (loopcount >= 100) {
  377. warningstream << "collisionMoveSimple: Loop count exceeded, aborting to avoid infiniite loop" << std::endl;
  378. break;
  379. }
  380. aabb3f movingbox = box_0;
  381. movingbox.MinEdge += *pos_f;
  382. movingbox.MaxEdge += *pos_f;
  383. int nearest_collided = -1;
  384. f32 nearest_dtime = dtime;
  385. int nearest_boxindex = -1;
  386. /*
  387. Go through every nodebox, find nearest collision
  388. */
  389. for (u32 boxindex = 0; boxindex < cinfo.size(); boxindex++) {
  390. const NearbyCollisionInfo &box_info = cinfo[boxindex];
  391. // Ignore if already stepped up this nodebox.
  392. if (box_info.is_step_up)
  393. continue;
  394. // Find nearest collision of the two boxes (raytracing-like)
  395. f32 dtime_tmp;
  396. int collided = axisAlignedCollision(box_info.box,
  397. movingbox, *speed_f, d, &dtime_tmp);
  398. if (collided == -1 || dtime_tmp >= nearest_dtime)
  399. continue;
  400. nearest_dtime = dtime_tmp;
  401. nearest_collided = collided;
  402. nearest_boxindex = boxindex;
  403. }
  404. if (nearest_collided == -1) {
  405. // No collision with any collision box.
  406. *pos_f += *speed_f * dtime;
  407. dtime = 0; // Set to 0 to avoid "infinite" loop due to small FP numbers
  408. } else {
  409. // Otherwise, a collision occurred.
  410. NearbyCollisionInfo &nearest_info = cinfo[nearest_boxindex];
  411. const aabb3f& cbox = nearest_info.box;
  412. // Check for stairs.
  413. bool step_up = (nearest_collided != 1) && // must not be Y direction
  414. (movingbox.MinEdge.Y < cbox.MaxEdge.Y) &&
  415. (movingbox.MinEdge.Y + stepheight > cbox.MaxEdge.Y) &&
  416. (!wouldCollideWithCeiling(cinfo, movingbox,
  417. cbox.MaxEdge.Y - movingbox.MinEdge.Y,
  418. d));
  419. // Get bounce multiplier
  420. float bounce = -(float)nearest_info.bouncy / 100.0f;
  421. // Move to the point of collision and reduce dtime by nearest_dtime
  422. if (nearest_dtime < 0) {
  423. // Handle negative nearest_dtime (can be caused by the d allowance)
  424. if (!step_up) {
  425. if (nearest_collided == 0)
  426. pos_f->X += speed_f->X * nearest_dtime;
  427. if (nearest_collided == 1)
  428. pos_f->Y += speed_f->Y * nearest_dtime;
  429. if (nearest_collided == 2)
  430. pos_f->Z += speed_f->Z * nearest_dtime;
  431. }
  432. } else {
  433. *pos_f += *speed_f * nearest_dtime;
  434. dtime -= nearest_dtime;
  435. }
  436. bool is_collision = true;
  437. if (nearest_info.is_unloaded)
  438. is_collision = false;
  439. CollisionInfo info;
  440. if (nearest_info.is_object)
  441. info.type = COLLISION_OBJECT;
  442. else
  443. info.type = COLLISION_NODE;
  444. info.node_p = nearest_info.position;
  445. info.old_speed = *speed_f;
  446. info.plane = nearest_collided;
  447. // Set the speed component that caused the collision to zero
  448. if (step_up) {
  449. // Special case: Handle stairs
  450. nearest_info.is_step_up = true;
  451. is_collision = false;
  452. } else if (nearest_collided == 0) { // X
  453. if (fabs(speed_f->X) > BS * 3)
  454. speed_f->X *= bounce;
  455. else
  456. speed_f->X = 0;
  457. result.collides = true;
  458. } else if (nearest_collided == 1) { // Y
  459. if(fabs(speed_f->Y) > BS * 3)
  460. speed_f->Y *= bounce;
  461. else
  462. speed_f->Y = 0;
  463. result.collides = true;
  464. } else if (nearest_collided == 2) { // Z
  465. if (fabs(speed_f->Z) > BS * 3)
  466. speed_f->Z *= bounce;
  467. else
  468. speed_f->Z = 0;
  469. result.collides = true;
  470. }
  471. info.new_speed = *speed_f;
  472. if (info.new_speed.getDistanceFrom(info.old_speed) < 0.1f * BS)
  473. is_collision = false;
  474. if (is_collision) {
  475. result.collisions.push_back(info);
  476. }
  477. }
  478. }
  479. /*
  480. Final touches: Check if standing on ground, step up stairs.
  481. */
  482. aabb3f box = box_0;
  483. box.MinEdge += *pos_f;
  484. box.MaxEdge += *pos_f;
  485. for (const auto &box_info : cinfo) {
  486. const aabb3f &cbox = box_info.box;
  487. /*
  488. See if the object is touching ground.
  489. Object touches ground if object's minimum Y is near node's
  490. maximum Y and object's X-Z-area overlaps with the node's
  491. X-Z-area.
  492. Use 0.15*BS so that it is easier to get on a node.
  493. */
  494. if (cbox.MaxEdge.X - d > box.MinEdge.X && cbox.MinEdge.X + d < box.MaxEdge.X &&
  495. cbox.MaxEdge.Z - d > box.MinEdge.Z &&
  496. cbox.MinEdge.Z + d < box.MaxEdge.Z) {
  497. if (box_info.is_step_up) {
  498. pos_f->Y += cbox.MaxEdge.Y - box.MinEdge.Y;
  499. box = box_0;
  500. box.MinEdge += *pos_f;
  501. box.MaxEdge += *pos_f;
  502. }
  503. if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.15f * BS) {
  504. result.touching_ground = true;
  505. if (box_info.is_object)
  506. result.standing_on_object = true;
  507. }
  508. }
  509. }
  510. return result;
  511. }