Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2013 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 : class Environment;
29 : class ActiveObject;
30 :
31 : enum CollisionType
32 : {
33 : COLLISION_NODE,
34 : COLLISION_OBJECT,
35 : };
36 :
37 22249 : struct CollisionInfo
38 : {
39 : enum CollisionType type;
40 : v3s16 node_p; // COLLISION_NODE
41 : bool bouncy;
42 : v3f old_speed;
43 : v3f new_speed;
44 :
45 11341 : CollisionInfo():
46 : type(COLLISION_NODE),
47 : node_p(-32768,-32768,-32768),
48 : bouncy(false),
49 : old_speed(0,0,0),
50 11341 : new_speed(0,0,0)
51 11341 : {}
52 : };
53 :
54 27253 : struct collisionMoveResult
55 : {
56 : bool touching_ground;
57 : bool collides;
58 : bool collides_xz;
59 : bool standing_on_unloaded;
60 : std::vector<CollisionInfo> collisions;
61 :
62 19418 : collisionMoveResult():
63 : touching_ground(false),
64 : collides(false),
65 : collides_xz(false),
66 19418 : standing_on_unloaded(false)
67 19418 : {}
68 : };
69 :
70 : // Moves using a single iteration; speed should not exceed pos_max_d/dtime
71 : collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef,
72 : f32 pos_max_d, const aabb3f &box_0,
73 : f32 stepheight, f32 dtime,
74 : v3f &pos_f, v3f &speed_f,
75 : v3f &accel_f,ActiveObject* self=0,
76 : bool collideWithObjects=true);
77 :
78 : #if 0
79 : // This doesn't seem to work and isn't used
80 : // Moves using as many iterations as needed
81 : collisionMoveResult collisionMovePrecise(Map *map, IGameDef *gamedef,
82 : f32 pos_max_d, const aabb3f &box_0,
83 : f32 stepheight, f32 dtime,
84 : v3f &pos_f, v3f &speed_f, v3f &accel_f);
85 : #endif
86 :
87 : // Helper function:
88 : // Checks for collision of a moving aabbox with a static aabbox
89 : // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision
90 : // dtime receives time until first collision, invalid if -1 is returned
91 : int axisAlignedCollision(
92 : const aabb3f &staticbox, const aabb3f &movingbox,
93 : const v3f &speed, f32 d, f32 &dtime);
94 :
95 : // Helper function:
96 : // Checks if moving the movingbox up by the given distance would hit a ceiling.
97 : bool wouldCollideWithCeiling(
98 : const std::vector<aabb3f> &staticboxes,
99 : const aabb3f &movingbox,
100 : f32 y_increase, f32 d);
101 :
102 :
103 : #endif
104 :
|