Skip to content

Commit

Permalink
Added Cylinder Gizmo and Capsule Gizmo
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsakharov committed Apr 4, 2024
1 parent c71653b commit b0d287d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Prowl.Runtime/Components/Physics/CapsuleCollider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Jitter2.Collision.Shapes;
using Prowl.Icons;
using System.Collections.Generic;
using System.Drawing;

namespace Prowl.Runtime
{
Expand All @@ -19,6 +20,15 @@ public override void OnValidate()
if (rigid != null)
rigid.IsActive = true;
}

public override void DrawGizmosSelected()
{
var mat = Matrix4x4.Identity;
mat = Matrix4x4.Multiply(mat, Matrix4x4.CreateScale(new Vector3(radius, height, radius) * 1.0025f));
mat = Matrix4x4.Multiply(mat, GameObject.GlobalCamRelative);
Gizmos.Matrix = mat;
Gizmos.Capsule(Color.yellow);
}
}

}
13 changes: 11 additions & 2 deletions Prowl.Runtime/Components/Physics/CylinderCollider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ public class CylinderCollider : Collider
public override List<Shape> CreateShapes() => [ new CylinderShape(radius, height) ];
public override void OnValidate()
{
(Shape[0] as CapsuleShape).Radius = radius;
(Shape[0] as CapsuleShape).Length = height;
(Shape[0] as CylinderShape).Radius = radius;
(Shape[0] as CylinderShape).Height = height;
Shape[0].UpdateShape();
var rigid = GetComponentInParent<Rigidbody>();
if (rigid != null)
rigid.IsActive = true;
}

public override void DrawGizmosSelected()
{
var mat = Matrix4x4.Identity;
mat = Matrix4x4.Multiply(mat, Matrix4x4.CreateScale(new Vector3(radius, height, radius) * 1.0025f));
mat = Matrix4x4.Multiply(mat, GameObject.GlobalCamRelative);
Gizmos.Matrix = mat;
Gizmos.Cylinder(Color.yellow);
}
}

}
4 changes: 2 additions & 2 deletions Prowl.Runtime/Components/Testings/TestDrawers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class TestDrawers : MonoBehaviour
public bool aBool;
public string aString;
public MeshRenderer aMeshRenderer;
public Mesh aMesh;
public Camera aCamera;
public Material aMaterial;
public GameObject aGameObject;

public float[] floats = new float[2];
public float[] aFloats = new float[2];

// Struct
public struct TestStruct
Expand Down

0 comments on commit b0d287d

Please sign in to comment.