Skip to content

Commit

Permalink
Merge pull request #36488 from Chaosus/capsule_y
Browse files Browse the repository at this point in the history
Changed default capsule axis to vertical
  • Loading branch information
akien-mga authored Feb 23, 2020
2 parents 4b6c056 + 3b0638f commit b975754
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
44 changes: 22 additions & 22 deletions editor/spatial_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3447,32 +3447,32 @@ void CollisionShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {

Vector<Vector3> points;

Vector3 d(0, 0, height * 0.5);
Vector3 d(0, height * 0.5, 0);
for (int i = 0; i < 360; i++) {

float ra = Math::deg2rad((float)i);
float rb = Math::deg2rad((float)i + 1);
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius;
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius;

points.push_back(Vector3(a.x, a.y, 0) + d);
points.push_back(Vector3(b.x, b.y, 0) + d);
points.push_back(Vector3(a.x, 0, a.y) + d);
points.push_back(Vector3(b.x, 0, b.y) + d);

points.push_back(Vector3(a.x, a.y, 0) - d);
points.push_back(Vector3(b.x, b.y, 0) - d);
points.push_back(Vector3(a.x, 0, a.y) - d);
points.push_back(Vector3(b.x, 0, b.y) - d);

if (i % 90 == 0) {

points.push_back(Vector3(a.x, a.y, 0) + d);
points.push_back(Vector3(a.x, a.y, 0) - d);
points.push_back(Vector3(a.x, 0, a.y) + d);
points.push_back(Vector3(a.x, 0, a.y) - d);
}

Vector3 dud = i < 180 ? d : -d;

points.push_back(Vector3(0, a.y, a.x) + dud);
points.push_back(Vector3(0, b.y, b.x) + dud);
points.push_back(Vector3(a.y, 0, a.x) + dud);
points.push_back(Vector3(b.y, 0, b.x) + dud);
points.push_back(Vector3(0, a.x, a.y) + dud);
points.push_back(Vector3(0, b.x, b.y) + dud);
points.push_back(Vector3(a.y, a.x, 0) + dud);
points.push_back(Vector3(b.y, b.x, 0) + dud);
}

p_gizmo->add_lines(points, material);
Expand All @@ -3486,31 +3486,31 @@ void CollisionShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius;
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius;

collision_segments.push_back(Vector3(a.x, a.y, 0) + d);
collision_segments.push_back(Vector3(b.x, b.y, 0) + d);
collision_segments.push_back(Vector3(a.x, 0, a.y) + d);
collision_segments.push_back(Vector3(b.x, 0, b.y) + d);

collision_segments.push_back(Vector3(a.x, a.y, 0) - d);
collision_segments.push_back(Vector3(b.x, b.y, 0) - d);
collision_segments.push_back(Vector3(a.x, 0, a.y) - d);
collision_segments.push_back(Vector3(b.x, 0, b.y) - d);

if (i % 16 == 0) {

collision_segments.push_back(Vector3(a.x, a.y, 0) + d);
collision_segments.push_back(Vector3(a.x, a.y, 0) - d);
collision_segments.push_back(Vector3(a.x, 0, a.y) + d);
collision_segments.push_back(Vector3(a.x, 0, a.y) - d);
}

Vector3 dud = i < 32 ? d : -d;

collision_segments.push_back(Vector3(0, a.y, a.x) + dud);
collision_segments.push_back(Vector3(0, b.y, b.x) + dud);
collision_segments.push_back(Vector3(a.y, 0, a.x) + dud);
collision_segments.push_back(Vector3(b.y, 0, b.x) + dud);
collision_segments.push_back(Vector3(0, a.x, a.y) + dud);
collision_segments.push_back(Vector3(0, b.x, b.y) + dud);
collision_segments.push_back(Vector3(a.y, a.x, 0) + dud);
collision_segments.push_back(Vector3(b.y, b.x, 0) + dud);
}

p_gizmo->add_collision_segments(collision_segments);

Vector<Vector3> handles;
handles.push_back(Vector3(cs2->get_radius(), 0, 0));
handles.push_back(Vector3(0, 0, cs2->get_height() * 0.5 + cs2->get_radius()));
handles.push_back(Vector3(0, cs2->get_height() * 0.5 + cs2->get_radius(), 0));
p_gizmo->add_handles(handles, handles_material);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/bullet/shape_bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ btBoxShape *ShapeBullet::create_shape_box(const btVector3 &boxHalfExtents) {
return bulletnew(btBoxShape(boxHalfExtents));
}

btCapsuleShapeZ *ShapeBullet::create_shape_capsule(btScalar radius, btScalar height) {
return bulletnew(btCapsuleShapeZ(radius, height));
btCapsuleShape *ShapeBullet::create_shape_capsule(btScalar radius, btScalar height) {
return bulletnew(btCapsuleShape(radius, height));
}

btCylinderShape *ShapeBullet::create_shape_cylinder(btScalar radius, btScalar height) {
Expand Down
2 changes: 1 addition & 1 deletion modules/bullet/shape_bullet.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ShapeBullet : public RIDBullet {
static class btStaticPlaneShape *create_shape_plane(const btVector3 &planeNormal, btScalar planeConstant);
static class btSphereShape *create_shape_sphere(btScalar radius);
static class btBoxShape *create_shape_box(const btVector3 &boxHalfExtents);
static class btCapsuleShapeZ *create_shape_capsule(btScalar radius, btScalar height);
static class btCapsuleShape *create_shape_capsule(btScalar radius, btScalar height);
static class btCylinderShape *create_shape_cylinder(btScalar radius, btScalar height);
/// IMPORTANT: Remember to delete the shape interface by calling: delete my_shape->getMeshInterface();
static class btConvexPointCloudShape *create_shape_convex(btAlignedObjectArray<btVector3> &p_vertices, const btVector3 &p_local_scaling = btVector3(1, 1, 1));
Expand Down
22 changes: 11 additions & 11 deletions scene/resources/capsule_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,32 @@ Vector<Vector3> CapsuleShape::get_debug_mesh_lines() {

Vector<Vector3> points;

Vector3 d(0, 0, height * 0.5);
Vector3 d(0, height * 0.5, 0);
for (int i = 0; i < 360; i++) {

float ra = Math::deg2rad((float)i);
float rb = Math::deg2rad((float)i + 1);
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius;
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius;

points.push_back(Vector3(a.x, a.y, 0) + d);
points.push_back(Vector3(b.x, b.y, 0) + d);
points.push_back(Vector3(a.x, 0, a.y) + d);
points.push_back(Vector3(b.x, 0, b.y) + d);

points.push_back(Vector3(a.x, a.y, 0) - d);
points.push_back(Vector3(b.x, b.y, 0) - d);
points.push_back(Vector3(a.x, 0, a.y) - d);
points.push_back(Vector3(b.x, 0, b.y) - d);

if (i % 90 == 0) {

points.push_back(Vector3(a.x, a.y, 0) + d);
points.push_back(Vector3(a.x, a.y, 0) - d);
points.push_back(Vector3(a.x, 0, a.y) + d);
points.push_back(Vector3(a.x, 0, a.y) - d);
}

Vector3 dud = i < 180 ? d : -d;

points.push_back(Vector3(0, a.y, a.x) + dud);
points.push_back(Vector3(0, b.y, b.x) + dud);
points.push_back(Vector3(a.y, 0, a.x) + dud);
points.push_back(Vector3(b.y, 0, b.x) + dud);
points.push_back(Vector3(0, a.x, a.y) + dud);
points.push_back(Vector3(0, b.x, b.y) + dud);
points.push_back(Vector3(a.y, a.x, 0) + dud);
points.push_back(Vector3(b.y, b.x, 0) + dud);
}

return points;
Expand Down
38 changes: 19 additions & 19 deletions scene/resources/primitive_meshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,19 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const {

v /= (rings + 1);
w = sin(0.5 * Math_PI * v);
z = radius * cos(0.5 * Math_PI * v);
y = radius * cos(0.5 * Math_PI * v);

for (i = 0; i <= radial_segments; i++) {
u = i;
u /= radial_segments;

x = sin(u * (Math_PI * 2.0));
y = -cos(u * (Math_PI * 2.0));
x = -sin(u * (Math_PI * 2.0));
z = cos(u * (Math_PI * 2.0));

Vector3 p = Vector3(x * radius * w, y * radius * w, z);
points.push_back(p + Vector3(0.0, 0.0, 0.5 * mid_height));
Vector3 p = Vector3(x * radius * w, y, -z * radius * w);
points.push_back(p + Vector3(0.0, 0.5 * mid_height, 0.0));
normals.push_back(p.normalized());
ADD_TANGENT(-y, x, 0.0, 1.0)
ADD_TANGENT(z, 0.0, x, 1.0)
uvs.push_back(Vector2(u, v * onethird));
point++;

Expand All @@ -341,20 +341,20 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const {
v = j;
v /= (rings + 1);

z = mid_height * v;
z = (mid_height * 0.5) - z;
y = mid_height * v;
y = (mid_height * 0.5) - y;

for (i = 0; i <= radial_segments; i++) {
u = i;
u /= radial_segments;

x = sin(u * (Math_PI * 2.0));
y = -cos(u * (Math_PI * 2.0));
x = -sin(u * (Math_PI * 2.0));
z = cos(u * (Math_PI * 2.0));

Vector3 p = Vector3(x * radius, y * radius, z);
Vector3 p = Vector3(x * radius, y, -z * radius);
points.push_back(p);
normals.push_back(Vector3(x, y, 0.0));
ADD_TANGENT(-y, x, 0.0, 1.0)
normals.push_back(Vector3(x, 0.0, -z));
ADD_TANGENT(z, 0.0, x, 1.0)
uvs.push_back(Vector2(u, onethird + (v * onethird)));
point++;

Expand Down Expand Up @@ -382,19 +382,19 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const {
v /= (rings + 1);
v += 1.0;
w = sin(0.5 * Math_PI * v);
z = radius * cos(0.5 * Math_PI * v);
y = radius * cos(0.5 * Math_PI * v);

for (i = 0; i <= radial_segments; i++) {
float u2 = i;
u2 /= radial_segments;

x = sin(u2 * (Math_PI * 2.0));
y = -cos(u2 * (Math_PI * 2.0));
x = -sin(u2 * (Math_PI * 2.0));
z = cos(u2 * (Math_PI * 2.0));

Vector3 p = Vector3(x * radius * w, y * radius * w, z);
points.push_back(p + Vector3(0.0, 0.0, -0.5 * mid_height));
Vector3 p = Vector3(x * radius * w, y, -z * radius * w);
points.push_back(p + Vector3(0.0, -0.5 * mid_height, 0.0));
normals.push_back(p.normalized());
ADD_TANGENT(-y, x, 0.0, 1.0)
ADD_TANGENT(z, 0.0, x, 1.0)
uvs.push_back(Vector2(u2, twothirds + ((v - 1.0) * onethird)));
point++;

Expand Down

0 comments on commit b975754

Please sign in to comment.