clientobject: add null checks
[waspsaliva.git] / src / collision.h
blob998598f1ea387b6f7c3a96b657db32dc4564a586
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #pragma once
22 #include "irrlichttypes_bloated.h"
23 #include <vector>
25 class Map;
26 class IGameDef;
27 class Environment;
28 class ActiveObject;
30 enum CollisionType
32 COLLISION_NODE,
33 COLLISION_OBJECT,
36 enum CollisionAxis
38 COLLISION_AXIS_NONE = -1,
39 COLLISION_AXIS_X,
40 COLLISION_AXIS_Y,
41 COLLISION_AXIS_Z,
44 struct CollisionInfo
46 CollisionInfo() = default;
48 CollisionType type = COLLISION_NODE;
49 CollisionAxis axis = COLLISION_AXIS_NONE;
50 v3s16 node_p = v3s16(-32768,-32768,-32768); // COLLISION_NODE
51 ActiveObject *object = nullptr; // COLLISION_OBJECT
52 v3f old_speed;
53 v3f new_speed;
54 int plane = -1;
57 struct collisionMoveResult
59 collisionMoveResult() = default;
61 bool touching_ground = false;
62 bool collides = false;
63 bool standing_on_object = false;
64 std::vector<CollisionInfo> collisions;
67 // Moves using a single iteration; speed should not exceed pos_max_d/dtime
68 collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef,
69 f32 pos_max_d, const aabb3f &box_0,
70 f32 stepheight, f32 dtime,
71 v3f *pos_f, v3f *speed_f,
72 v3f accel_f, ActiveObject *self=NULL,
73 bool collideWithObjects=true, bool jesus=false);
75 // Helper function:
76 // Checks for collision of a moving aabbox with a static aabbox
77 // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision
78 // dtime receives time until first collision, invalid if -1 is returned
79 CollisionAxis axisAlignedCollision(
80 const aabb3f &staticbox, const aabb3f &movingbox,
81 const v3f &speed, f32 *dtime);
83 // Helper function:
84 // Checks if moving the movingbox up by the given distance would hit a ceiling.
85 bool wouldCollideWithCeiling(
86 const std::vector<aabb3f> &staticboxes,
87 const aabb3f &movingbox,
88 f32 y_increase, f32 d);