Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_physics_material.cpp
45991 views
1
/**************************************************************************/
2
/* test_physics_material.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "tests/test_macros.h"
32
33
TEST_FORCE_LINK(test_physics_material)
34
35
#ifndef PHYSICS_3D_DISABLED
36
37
#include "scene/resources/physics_material.h"
38
39
namespace TestPhysicsMaterial {
40
41
TEST_CASE("[Physics_material] Defaults") {
42
Ref<PhysicsMaterial> physics_material;
43
physics_material.instantiate();
44
45
CHECK(physics_material->get_friction() == 1.);
46
CHECK(physics_material->is_rough() == false);
47
CHECK(physics_material->get_bounce() == 0.);
48
CHECK(physics_material->is_absorbent() == false);
49
}
50
51
TEST_CASE("[Physics_material] Friction") {
52
Ref<PhysicsMaterial> physics_material;
53
physics_material.instantiate();
54
55
real_t friction = 0.314;
56
physics_material->set_friction(friction);
57
CHECK(physics_material->get_friction() == friction);
58
}
59
60
TEST_CASE("[Physics_material] Rough") {
61
Ref<PhysicsMaterial> physics_material;
62
physics_material.instantiate();
63
64
bool rough = true;
65
physics_material->set_rough(rough);
66
CHECK(physics_material->is_rough() == rough);
67
68
real_t friction = 0.314;
69
physics_material->set_friction(friction);
70
CHECK(physics_material->computed_friction() == -friction);
71
72
rough = false;
73
physics_material->set_rough(rough);
74
CHECK(physics_material->is_rough() == rough);
75
76
CHECK(physics_material->computed_friction() == friction);
77
}
78
79
TEST_CASE("[Physics_material] Bounce") {
80
Ref<PhysicsMaterial> physics_material;
81
physics_material.instantiate();
82
83
real_t bounce = 0.271;
84
physics_material->set_bounce(bounce);
85
CHECK(physics_material->get_bounce() == bounce);
86
}
87
88
TEST_CASE("[Physics_material] Absorbent") {
89
Ref<PhysicsMaterial> physics_material;
90
physics_material.instantiate();
91
92
bool absorbent = true;
93
physics_material->set_absorbent(absorbent);
94
CHECK(physics_material->is_absorbent() == absorbent);
95
96
real_t bounce = 0.271;
97
physics_material->set_bounce(bounce);
98
CHECK(physics_material->computed_bounce() == -bounce);
99
100
absorbent = false;
101
physics_material->set_absorbent(absorbent);
102
CHECK(physics_material->is_absorbent() == absorbent);
103
104
CHECK(physics_material->computed_bounce() == bounce);
105
}
106
107
} // namespace TestPhysicsMaterial
108
109
#endif // PHYSICS_3D_DISABLED
110
111