summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2021-08-11 10:38:14 -0700
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2021-08-11 14:54:53 -0700
commitf9176a39ce48685adacca2698b8da8136c5de166 (patch)
tree5c1efcc6c45b7f5b8561985dfc7f97103787dcc1 /scene
parent7188cb60127c1f4e900f080adbc47a55645f1645 (diff)
Make radius & height in CapsuleShape3D independent
Also changed CapsuleMesh to make settings consistent between render and physics.
Diffstat (limited to 'scene')
-rw-r--r--scene/resources/capsule_shape_3d.cpp10
-rw-r--r--scene/resources/capsule_shape_3d.h2
-rw-r--r--scene/resources/primitive_meshes.cpp28
-rw-r--r--scene/resources/primitive_meshes.h6
4 files changed, 29 insertions, 17 deletions
diff --git a/scene/resources/capsule_shape_3d.cpp b/scene/resources/capsule_shape_3d.cpp
index 226fe1ecd2..e267941d6a 100644
--- a/scene/resources/capsule_shape_3d.cpp
+++ b/scene/resources/capsule_shape_3d.cpp
@@ -37,7 +37,7 @@ Vector<Vector3> CapsuleShape3D::get_debug_mesh_lines() const {
Vector<Vector3> points;
- Vector3 d(0, height * 0.5, 0);
+ Vector3 d(0, height * 0.5 - radius, 0);
for (int i = 0; i < 360; i++) {
float ra = Math::deg2rad((float)i);
float rb = Math::deg2rad((float)i + 1);
@@ -67,7 +67,7 @@ Vector<Vector3> CapsuleShape3D::get_debug_mesh_lines() const {
}
real_t CapsuleShape3D::get_enclosing_radius() const {
- return radius + height * 0.5;
+ return height * 0.5;
}
void CapsuleShape3D::_update_shape() {
@@ -80,6 +80,9 @@ void CapsuleShape3D::_update_shape() {
void CapsuleShape3D::set_radius(float p_radius) {
radius = p_radius;
+ if (radius > height * 0.5) {
+ radius = height * 0.5;
+ }
_update_shape();
notify_change_to_owners();
}
@@ -90,6 +93,9 @@ float CapsuleShape3D::get_radius() const {
void CapsuleShape3D::set_height(float p_height) {
height = p_height;
+ if (radius > height * 0.5) {
+ height = radius * 2;
+ }
_update_shape();
notify_change_to_owners();
}
diff --git a/scene/resources/capsule_shape_3d.h b/scene/resources/capsule_shape_3d.h
index 25645ecf9d..f09b4fb77d 100644
--- a/scene/resources/capsule_shape_3d.h
+++ b/scene/resources/capsule_shape_3d.h
@@ -36,7 +36,7 @@
class CapsuleShape3D : public Shape3D {
GDCLASS(CapsuleShape3D, Shape3D);
float radius = 1.0;
- float height = 1.0;
+ float height = 3.0;
protected:
static void _bind_methods();
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index dfa45cc810..ba85ea4a6c 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -300,7 +300,7 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const {
z = cos(u * Math_TAU);
Vector3 p = Vector3(x * radius * w, y, -z * radius * w);
- points.push_back(p + Vector3(0.0, 0.5 * mid_height, 0.0));
+ points.push_back(p + Vector3(0.0, 0.5 * height - radius, 0.0));
normals.push_back(p.normalized());
ADD_TANGENT(z, 0.0, x, 1.0)
uvs.push_back(Vector2(u, v * onethird));
@@ -328,8 +328,8 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const {
v = j;
v /= (rings + 1);
- y = mid_height * v;
- y = (mid_height * 0.5) - y;
+ y = (height - 2.0 * radius) * v;
+ y = (0.5 * height - radius) - y;
for (i = 0; i <= radial_segments; i++) {
u = i;
@@ -379,7 +379,7 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const {
z = cos(u2 * Math_TAU);
Vector3 p = Vector3(x * radius * w, y, -z * radius * w);
- points.push_back(p + Vector3(0.0, -0.5 * mid_height, 0.0));
+ points.push_back(p + Vector3(0.0, -0.5 * height + radius, 0.0));
normals.push_back(p.normalized());
ADD_TANGENT(z, 0.0, x, 1.0)
uvs.push_back(Vector2(u2, twothirds + ((v - 1.0) * onethird)));
@@ -410,8 +410,8 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const {
void CapsuleMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CapsuleMesh::set_radius);
ClassDB::bind_method(D_METHOD("get_radius"), &CapsuleMesh::get_radius);
- ClassDB::bind_method(D_METHOD("set_mid_height", "mid_height"), &CapsuleMesh::set_mid_height);
- ClassDB::bind_method(D_METHOD("get_mid_height"), &CapsuleMesh::get_mid_height);
+ ClassDB::bind_method(D_METHOD("set_height", "height"), &CapsuleMesh::set_height);
+ ClassDB::bind_method(D_METHOD("get_height"), &CapsuleMesh::get_height);
ClassDB::bind_method(D_METHOD("set_radial_segments", "segments"), &CapsuleMesh::set_radial_segments);
ClassDB::bind_method(D_METHOD("get_radial_segments"), &CapsuleMesh::get_radial_segments);
@@ -419,13 +419,16 @@ void CapsuleMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_rings"), &CapsuleMesh::get_rings);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_radius", "get_radius");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mid_height", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_mid_height", "get_mid_height");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_height", "get_height");
ADD_PROPERTY(PropertyInfo(Variant::INT, "radial_segments", PROPERTY_HINT_RANGE, "1,100,1,or_greater"), "set_radial_segments", "get_radial_segments");
ADD_PROPERTY(PropertyInfo(Variant::INT, "rings", PROPERTY_HINT_RANGE, "1,100,1,or_greater"), "set_rings", "get_rings");
}
void CapsuleMesh::set_radius(const float p_radius) {
radius = p_radius;
+ if (radius > height * 0.5) {
+ radius = height * 0.5;
+ }
_request_update();
}
@@ -433,13 +436,16 @@ float CapsuleMesh::get_radius() const {
return radius;
}
-void CapsuleMesh::set_mid_height(const float p_mid_height) {
- mid_height = p_mid_height;
+void CapsuleMesh::set_height(const float p_height) {
+ height = p_height;
+ if (radius > height * 0.5) {
+ height = radius * 2;
+ }
_request_update();
}
-float CapsuleMesh::get_mid_height() const {
- return mid_height;
+float CapsuleMesh::get_height() const {
+ return height;
}
void CapsuleMesh::set_radial_segments(const int p_segments) {
diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h
index a3de34d3e3..7915cb0028 100644
--- a/scene/resources/primitive_meshes.h
+++ b/scene/resources/primitive_meshes.h
@@ -108,7 +108,7 @@ class CapsuleMesh : public PrimitiveMesh {
private:
float radius = 1.0;
- float mid_height = 1.0;
+ float height = 3.0;
int radial_segments = 64;
int rings = 8;
@@ -120,8 +120,8 @@ public:
void set_radius(const float p_radius);
float get_radius() const;
- void set_mid_height(const float p_mid_height);
- float get_mid_height() const;
+ void set_height(const float p_height);
+ float get_height() const;
void set_radial_segments(const int p_segments);
int get_radial_segments() const;