void OnDrawGizmos() { List <Vector3> points = new List <Vector3>(parentTransform.childCount); foreach (Transform child in parentTransform) { if (child.gameObject.activeInHierarchy) { points.Add(child.position); } } if (fitType == FitType.Line) { Fit.Line(points, out origin, ref direction, 1, true); } else if (fitType == FitType.Plane) { Fit.Plane(points, out origin, out direction, 100, true); } else if (fitType == FitType.OrdinaryLine) { Fit.Polynomial(points, 1, true); } else if (fitType == FitType.OrdinaryParabola) { Fit.Polynomial(points, 2, true); } else if (fitType == FitType.OrdinaryCubic) { Fit.Polynomial(points, 3, true); } }
void OnDrawGizmos() { List <Vector3> points = new List <Vector3>(parentTransform.childCount); for (int i = 0; i < parentTransform.childCount; i++) { points.Add(parentTransform.GetChild(i).position); } if (doPlaneFit) { Fit.Plane(points, out position, out direction, 100, true); } else { Fit.Line(points, out position, ref direction, 100, true); } }
public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer) { Quaternion beginningRot = transform.rotation; if (curFocalPoint.ContainsNaN()) { curFocalPoint = Vector3.zero; } averagedInterSectionPoints = new List <Vector3>(); ARRaytracer.OpticalSystem optics = raytracer.optics; curDrawing = 0; for (float yRot = -30f; yRot < 30f; yRot += 5f) { for (float xRot = -20f; xRot < 70f; xRot += 5f) { //for (float yRot = -0f; yRot < 25f; yRot += 5f) { // for (float xRot = 5f; xRot < 35f; xRot += 5f) { List <Ray> intersectRayList = new List <Ray>(); for (float i = 0f; i < 91; i += 90) { transform.rotation = Quaternion.Euler(0, 0, i);// Quaternion.Euler(xRot, yRot, i); Vector3 convergencePoint = transform.position + ((Vector3.forward) + (Vector3.up * -xRot * 0.01f) + (Vector3.right * yRot * 0.01f)) * focalDistance; optics.eyePosition = transform.position + (transform.right * 0.001f); Ray firstBounceRay = traceRay((convergencePoint - optics.eyePosition).normalized, optics, whichToDraw == curDrawing ? drawer : null); intersectRayList.Add(firstBounceRay); transform.rotation = Quaternion.Euler(0, 0, i + 180f); //Quaternion.Euler(xRot, yRot, i+180f); optics.eyePosition = transform.position + (transform.right * 0.001f); firstBounceRay = traceRay((convergencePoint - optics.eyePosition).normalized, optics, whichToDraw == curDrawing ? drawer : null); intersectRayList.Add(firstBounceRay); } Vector3 intersectSum = Vector3.zero; int numPoints = 0; for (int i = 0; i < (intersectRayList.Count - 1); i += 2) { Vector3 tmp = Fit.ClosestPointOnRayToRay(intersectRayList[i], intersectRayList[i + 1]); drawer.color = i == 0 ? LeapColor.coral : LeapColor.forest; drawer.DrawSphere(tmp, 0.0005f); intersectSum += tmp; numPoints++; } Vector3 ptAverage = intersectSum / numPoints; averagedInterSectionPoints.Add(ptAverage); /*for (int i = 0; i < (intersectRayList.Count - 1); i += 2) { * Vector3 tmp = ClosestPointOnRayToRay(intersectRayList[i], intersectRayList[i + 1]); * drawer.color = LeapColor.red; * drawer.DrawLine(tmp, ptAverage); * }*/ //Debug.Log("Average: " + ptAverage); curDrawing++; } } optics.eyePosition = raytracer.eyePerspective.transform.position; //drawer.color = LeapColor.periwinkle; //for (int i = 0; i < averagedInterSectionPoints.Count; i++) drawer.DrawSphere(averagedInterSectionPoints[i], .0005f); Vector3 position = Vector3.zero; Vector3 normal = Vector3.zero; Fit.Plane(averagedInterSectionPoints, out position, out normal, 200, drawer); newScreen.position = Vector3.ProjectOnPlane(newScreen.position - position, normal) + position; newScreen.rotation = Quaternion.FromToRotation(newScreen.forward, normal) * newScreen.rotation; //log the continous fit to the console ///Debug.Log("Position is " + position + " normal is " + normal); transform.rotation = beginningRot; Vector2 CornerOneUV = ARRaytracer.DisplayUVToRenderUV(new Vector2(0f, 0f), optics, 80); Vector2 CornerTwoUV = ARRaytracer.DisplayUVToRenderUV(new Vector2(1f, 0f), optics, 80); Vector2 CornerThreeUV = ARRaytracer.DisplayUVToRenderUV(new Vector2(0f, 1f), optics, 80); Vector2 CornerFourUV = ARRaytracer.DisplayUVToRenderUV(new Vector2(1f, 1f), optics, 80); drawer.matrix = Matrix4x4.identity; traceRay(ARRaytracer.ViewportPointToRayDirection(new Vector3(CornerOneUV.x, CornerOneUV.y, 1f), raytracer.eyePerspective.transform.position, optics.clipToWorld), optics, drawer); traceRay(ARRaytracer.ViewportPointToRayDirection(new Vector3(CornerTwoUV.x, CornerTwoUV.y, 1f), raytracer.eyePerspective.transform.position, optics.clipToWorld), optics, drawer); traceRay(ARRaytracer.ViewportPointToRayDirection(new Vector3(CornerThreeUV.x, CornerThreeUV.y, 1f), raytracer.eyePerspective.transform.position, optics.clipToWorld), optics, drawer); traceRay(ARRaytracer.ViewportPointToRayDirection(new Vector3(CornerFourUV.x, CornerFourUV.y, 1f), raytracer.eyePerspective.transform.position, optics.clipToWorld), optics, drawer); }