public HitObject FindEdges(CircleCollider2D collider) { // position of light source var o = transform.position; // position of circle var c = collider.transform.position; var oc = c - o; var ocn = oc.normalized; // radius of circle var r = collider.radius * collider.transform.localScale.x; var d = oc.magnitude; // sin(t) = O/H = r/d // t = sin-1(r/d) // theta var trad = Mathf.Asin(r / d); var tdeg = trad * Mathf.Rad2Deg; // distance from light source to hit edge // x = dcos(t) var x = d * Mathf.Cos(trad); // 0 left // 1 right var hits = new HitVertex[2]; var rots = new[] { Quaternion.Euler(0, 0, tdeg), Quaternion.Euler(0, 0, -tdeg) }; for (int i = 0; i < 2; i++) { var toHit = rots[i] * ocn * x; hits[i].worldPosition = o + toHit; hits[i].angleFromCentre = Vector2.SignedAngle(ocn, toHit.normalized); } return(new HitObject() { left = hits[0], right = hits[1] }); }
private void model1_MouseDown(object sender, MouseEventArgs e) { // gets the entity index entityIndex = model1.GetEntityUnderMouseCursor(e.Location); if (e.Button == MouseButtons.Right) { foreach (var item in model1.Entities) { item.Visible = true; } var foot = FindFoot(); if (structType == StructureTypes.Arrows) { DrawArrows(foot); } else if (structType == StructureTypes.Tetra) { DrawTetra(foot); } isBoneSelected = false; model1.Entities.Regen(); model1.Invalidate(); return; } else if (isBoneSelected) { if (entityIndex < 0 || model1.Entities[entityIndex] is Mesh) { entityIndex = -1; return; } } else if (!isBoneSelected) { if (entityIndex < 0 || model1.Entities[entityIndex] is PointCloud || model1.Entities[entityIndex].LayerName.EndsWith("Structure") || e.Button == MouseButtons.Middle) { entityIndex = -1; return; } } isBoneSelected = true; model1.ActionMode = actionType.None; var ent = model1.Entities[entityIndex]; if (ent is Mesh) { foreach (var item in model1.Entities) { if (item.EntityData == null) { item.Visible = false; } else if (item.EntityData.ToString() != ent.EntityData.ToString() || !(item.LayerName == ent.LayerName || item.LayerName == ent.LayerName + structType + "Points")) { item.Visible = false; } else { if (item is Mesh) { selectedBone = (Mesh)item; } } } } selectedPoint = model1.FindClosestVertex(model1.Entities[entityIndex], e.Location, 30); }