Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
collision.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
23#include <vector>
24
25class Map;
26class IGameDef;
27class Environment;
28class ActiveObject;
29
31{
34};
35
37{
42};
43
45{
46 CollisionInfo() = default;
47
50 v3s16 node_p = v3s16(-32768,-32768,-32768); // COLLISION_NODE
51 ActiveObject *object = nullptr; // COLLISION_OBJECT
54 int plane = -1;
55};
56
58{
60
61 bool touching_ground = false;
62 bool collides = false;
63 bool standing_on_object = false;
64 std::vector<CollisionInfo> collisions;
65};
66
67// Moves using a single iteration; speed should not exceed pos_max_d/dtime
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);
74
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
80 const aabb3f &staticbox, const aabb3f &movingbox,
81 v3f speed, f32 *dtime);
82
83// Helper function:
84// Checks if moving the movingbox up by the given distance would hit a ceiling.
86 const std::vector<aabb3f> &staticboxes,
87 const aabb3f &movingbox,
88 f32 y_increase, f32 d);
Definition: activeobject.h:153
Definition: environment.h:49
Definition: gamedef.h:51
Definition: map.h:116
CollisionAxis
Definition: collision.h:37
@ COLLISION_AXIS_X
Definition: collision.h:39
@ COLLISION_AXIS_Y
Definition: collision.h:40
@ COLLISION_AXIS_Z
Definition: collision.h:41
@ COLLISION_AXIS_NONE
Definition: collision.h:38
collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, f32 pos_max_d, const aabb3f &box_0, f32 stepheight, f32 dtime, v3f *pos_f, v3f *speed_f, v3f accel_f, ActiveObject *self=NULL, bool collideWithObjects=true)
Definition: collision.cpp:229
bool wouldCollideWithCeiling(const std::vector< aabb3f > &staticboxes, const aabb3f &movingbox, f32 y_increase, f32 d)
CollisionType
Definition: collision.h:31
@ COLLISION_OBJECT
Definition: collision.h:33
@ COLLISION_NODE
Definition: collision.h:32
CollisionAxis axisAlignedCollision(const aabb3f &staticbox, const aabb3f &movingbox, v3f speed, f32 *dtime)
Definition: collision.cpp:94
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
Definition: collision.h:45
CollisionInfo()=default
CollisionAxis axis
Definition: collision.h:49
int plane
Definition: collision.h:54
CollisionType type
Definition: collision.h:48
v3f old_speed
Definition: collision.h:52
v3s16 node_p
Definition: collision.h:50
v3f new_speed
Definition: collision.h:53
Definition: collision.h:58
std::vector< CollisionInfo > collisions
Definition: collision.h:64
bool collides
Definition: collision.h:62
collisionMoveResult()=default
bool touching_ground
Definition: collision.h:61
bool standing_on_object
Definition: collision.h:63