public static Sphere FromCollider(Collider c, BoundingSphereAlgorithm algorithm, bool local = false) { if (c is SphereCollider) { return(FromCollider(c as SphereCollider, local)); } else if (c is CapsuleCollider) { return(FromCollider(c as CapsuleCollider, local)); } else if (algorithm != BoundingSphereAlgorithm.FromBounds && c is MeshCollider) { return(FromMesh((c as MeshCollider).sharedMesh, algorithm, Trans.GetGlobal(c.transform))); } else { var bounds = AABBox.FromCollider(c, local); return(new Sphere(bounds.Center, bounds.Extents.magnitude)); } }
/// <summary> /// Attempts to calculate geometry for a collider. Not tested yet. /// </summary> /// <param name="c"></param> /// <returns></returns> public static IPhysicsGeom GetGeom(this Collider c, BoundingSphereAlgorithm algorithm, bool local = false) { if (c == null) { return(null); } if (c is CharacterController) { return(Capsule.FromCollider(c as CharacterController, local)); } if (c is CapsuleCollider) { return(Capsule.FromCollider(c as CapsuleCollider, local)); } else if (c is BoxCollider) { return(Box.FromCollider(c as BoxCollider, local)); } else if (c is SphereCollider) { return(Sphere.FromCollider(c as SphereCollider, local)); } else if (algorithm != BoundingSphereAlgorithm.FromBounds && c is MeshCollider) { if (local) { return(Sphere.FromMesh((c as MeshCollider).sharedMesh, algorithm)); } else { return(Sphere.FromMesh((c as MeshCollider).sharedMesh, algorithm, Trans.GetGlobal(c.transform))); } } else { //otherwise just return bounds as AABBox return(AABBox.FromCollider(c, local)); } }
public static Sphere GetGlobalBoundingSphere(this Renderer rend, BoundingSphereAlgorithm algorithm) { if (algorithm != BoundingSphereAlgorithm.FromBounds && rend is SkinnedMeshRenderer) { return(Sphere.FromMesh((rend as SkinnedMeshRenderer).sharedMesh, algorithm, Trans.GetGlobal(rend.transform))); } else if (algorithm != BoundingSphereAlgorithm.FromBounds && rend is MeshRenderer && rend.HasComponent <MeshFilter>()) { return(Sphere.FromMesh((rend as MeshRenderer).GetComponent <MeshFilter>().sharedMesh, algorithm, Trans.GetGlobal(rend.transform))); } else { var bounds = rend.bounds; return(new Sphere(bounds.center, bounds.extents.magnitude)); } }
public void ApplyForce(Trans forceOrigin, Rigidbody body) { var force = this.GetForce(forceOrigin, Trans.GetGlobal(body.transform)); body.AddForce(force, _forceMode); }