Custom boxy nodes (stairs, slabs) and collision changes
[oweals/minetest.git] / src / collision.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef COLLISION_HEADER
21 #define COLLISION_HEADER
22
23 #include "irrlichttypes_bloated.h"
24 #include <vector>
25
26 class Map;
27 class IGameDef;
28
29 struct collisionMoveResult
30 {
31         bool touching_ground;
32         bool collides;
33         bool collides_xz;
34         bool standing_on_unloaded;
35
36         collisionMoveResult():
37                 touching_ground(false),
38                 collides(false),
39                 collides_xz(false),
40                 standing_on_unloaded(false)
41         {}
42 };
43
44 // Moves using a single iteration; speed should not exceed pos_max_d/dtime
45 collisionMoveResult collisionMoveSimple(Map *map, IGameDef *gamedef,
46                 f32 pos_max_d, const aabb3f &box_0,
47                 f32 stepheight, f32 dtime,
48                 v3f &pos_f, v3f &speed_f, v3f &accel_f);
49
50 #if 0
51 // This doesn't seem to work and isn't used
52 // Moves using as many iterations as needed
53 collisionMoveResult collisionMovePrecise(Map *map, IGameDef *gamedef,
54                 f32 pos_max_d, const aabb3f &box_0,
55                 f32 stepheight, f32 dtime,
56                 v3f &pos_f, v3f &speed_f, v3f &accel_f);
57 #endif
58
59 // Helper function:
60 // Checks for collision of a moving aabbox with a static aabbox
61 // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision
62 // dtime receives time until first collision, invalid if -1 is returned
63 int axisAlignedCollision(
64                 const aabb3f &staticbox, const aabb3f &movingbox,
65                 const v3f &speed, f32 d, f32 &dtime);
66
67 // Helper function:
68 // Checks if moving the movingbox up by the given distance would hit a ceiling.
69 bool wouldCollideWithCeiling(
70                 const std::vector<aabb3f> &staticboxes,
71                 const aabb3f &movingbox,
72                 f32 y_increase, f32 d);
73
74
75 enum CollisionType
76 {
77         COLLISION_FALL
78 };
79
80 struct CollisionInfo
81 {
82         CollisionType t;
83         f32 speed;
84 };
85
86 #endif
87