protected void CalculateFullSphere(Vector3d[] list) { SphereHull result = ConvexHull.FindEnclosingSphere(list); sphereCenter = result.Center; sphereRadius = result.Radius; }
private void CalcSphere(Vector3d[] list) { SphereHull result = ConvexHull.FindEnclosingSphere(list); sphereCenter = result.Center; sphereRadius = result.Radius; }
//private bool LoadDemData() //{ // DemData = (float[])(object)demFile; // //todo get dem from parent // return true; //} protected void CalcSphere() { Vector3d[] corners = new Vector3d[4]; corners[0] = TopLeft; corners[1] = BottomRight; corners[2] = TopRight; corners[3] = BottomLeft; SphereHull result = ConvexHull.FindEnclosingSphere(corners); sphereCenter = result.Center; sphereRadius = result.Radius; }
public static void SphereSphereCollision(CollisionManager.HullCollision col) { // *IMPORTANT* for circle and square the collision only wirks with obejct1 - object 2 and not viceversa, must be a prob in clollision resolution SphereHull hull1 = col.a.GetComponent <SphereHull>(); SphereHull hull2 = col.b.GetComponent <SphereHull>(); Vector3 range = (hull2.transform.position + hull2.localCenter) - (hull1.transform.position + hull1.localCenter); // make sure offsets arent screwing things up float overlap = (hull2.radius + hull1.radius) - range.magnitude; //HullCollision col = new CollisionManager.HullCollision(); //col.a = hull1; //col.b = hull2; col.penetration = range * overlap; CollisionManager.HullCollision.Contact con0 = new CollisionManager.HullCollision.Contact(); con0.point = (range.normalized * hull1.radius) + hull1.transform.position; con0.normal = range.normalized; con0.restitution = Mathf.Min(hull1.restitution, hull2.restitution); col.contacts[0] = con0; Particle3D c1 = hull1.GetComponentInParent <Particle3D>(); Particle3D c2 = hull2.GetComponentInParent <Particle3D>(); Vector3 closingVel = c2.velocity - c1.velocity; // started as c1 -c2 col.closingVelocity = closingVel; if (overlap >= 0) { col.status = true; //Debug.Log("touch"); } else { col.status = false; } }