Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_physics_material.h
10277 views
1
/**************************************************************************/
2
/* test_physics_material.h */
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
#pragma once
32
33
#include "scene/resources/physics_material.h"
34
#include "tests/test_macros.h"
35
36
namespace TestPhysics_material {
37
38
TEST_CASE("[Physics_material] Defaults") {
39
Ref<PhysicsMaterial> physics_material;
40
physics_material.instantiate();
41
42
CHECK(physics_material->get_friction() == 1.);
43
CHECK(physics_material->is_rough() == false);
44
CHECK(physics_material->get_bounce() == 0.);
45
CHECK(physics_material->is_absorbent() == false);
46
}
47
48
TEST_CASE("[Physics_material] Friction") {
49
Ref<PhysicsMaterial> physics_material;
50
physics_material.instantiate();
51
52
real_t friction = 0.314;
53
physics_material->set_friction(friction);
54
CHECK(physics_material->get_friction() == friction);
55
}
56
57
TEST_CASE("[Physics_material] Rough") {
58
Ref<PhysicsMaterial> physics_material;
59
physics_material.instantiate();
60
61
bool rough = true;
62
physics_material->set_rough(rough);
63
CHECK(physics_material->is_rough() == rough);
64
65
real_t friction = 0.314;
66
physics_material->set_friction(friction);
67
CHECK(physics_material->computed_friction() == -friction);
68
69
rough = false;
70
physics_material->set_rough(rough);
71
CHECK(physics_material->is_rough() == rough);
72
73
CHECK(physics_material->computed_friction() == friction);
74
}
75
76
TEST_CASE("[Physics_material] Bounce") {
77
Ref<PhysicsMaterial> physics_material;
78
physics_material.instantiate();
79
80
real_t bounce = 0.271;
81
physics_material->set_bounce(bounce);
82
CHECK(physics_material->get_bounce() == bounce);
83
}
84
85
TEST_CASE("[Physics_material] Absorbent") {
86
Ref<PhysicsMaterial> physics_material;
87
physics_material.instantiate();
88
89
bool absorbent = true;
90
physics_material->set_absorbent(absorbent);
91
CHECK(physics_material->is_absorbent() == absorbent);
92
93
real_t bounce = 0.271;
94
physics_material->set_bounce(bounce);
95
CHECK(physics_material->computed_bounce() == -bounce);
96
97
absorbent = false;
98
physics_material->set_absorbent(absorbent);
99
CHECK(physics_material->is_absorbent() == absorbent);
100
101
CHECK(physics_material->computed_bounce() == bounce);
102
}
103
104
} // namespace TestPhysics_material
105
106