Skip to content
Snippets Groups Projects
Commit cf14ee66 authored by Tobias Schöner's avatar Tobias Schöner
Browse files

Ring snapping is now smooth

parent a29d709d
No related branches found
No related tags found
1 merge request!1feat: added visualisation for CircleFact; added Torus- and ConeGenerator
...@@ -168,25 +168,34 @@ void Update() ...@@ -168,25 +168,34 @@ void Update()
#region Ring #region Ring
var id = multipleHits[i].transform.GetComponent<FactObject>().URI; var id = multipleHits[i].transform.GetComponent<FactObject>().URI;
CircleFact circleFact = StageStatic.stage.factState[id] as CircleFact; CircleFact circleFact = StageStatic.stage.factState[id] as CircleFact;
PointFact middlePoint = StageStatic.stage.factState[circleFact.Pid1] as PointFact; Vector3 middlePoint = ((PointFact)StageStatic.stage.factState[circleFact.Pid1]).Point;
Vector3 edgePoint = ((PointFact)StageStatic.stage.factState[circleFact.Pid2]).Point;
var normal = circleFact.normal; var normal = circleFact.normal;
var radius = circleFact.radius;
// generate circle // project p on circlePlane
int pointCount = multipleHits[i].transform.GetComponentInParent<TorusGenerator>().ringSegmentCount; var q = multipleHits[i].point - middlePoint;
Vector3[] circle = new Vector3[pointCount]; var dist = Vector3.Dot(q, normal);
float slice = (2f * Mathf.PI) / pointCount; var pPlane = multipleHits[i].point - (normal * dist); // p on circlePlane
for (int j = 0; j < pointCount; j++)
{
// generate possible snappoints one the "corners" of the torus mesh
float angle = j * slice;
circle[j] = new Vector3(circleFact.radius * Mathf.Sin(angle), 0, circleFact.radius * Mathf.Cos(angle)) + middlePoint.Point;
// rotate snappoint according to circle normal // check if projectedPoint and circleCenter are identical
circle[j] = Quaternion.LookRotation(new Vector3(-normal.z, 0, normal.x), normal) * circle[j]; // should never happen in practice due to floating point precision
if (pPlane == middlePoint)
{
// can be set to any point on the ring -> set to edgePoint
multipleHits[i].point = edgePoint;
return;
} }
else
// get closest cornerPoint {
multipleHits[i].point = circle.OrderBy(p => Vector3.Distance(p, multipleHits[i].point)).First(); var direction = (pPlane - middlePoint).normalized;
multipleHits[i].point = middlePoint + direction * radius;
}
// cursor orientation should match circle orientation; dont face downwards
if (normal.y < 0) // if normal faces downwards use inverted normal instead
multipleHits[i].normal = -normal;
else
multipleHits[i].normal = normal;
#endregion Ring #endregion Ring
} }
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment