Skip to content

Commit

Permalink
Update LineManager.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
lightlessdays committed Aug 16, 2022
1 parent 9e5e2f3 commit f6ab42d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Assets/Scripts/LineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,44 @@ void DrawLine(ARObjectPlacementEventArgs args) {
//The coordinates of the last point of line renderer would be set to the placement position of the sphere.
_lineRenderer.SetPosition(_lineRenderer.positionCount - 1,args.placementObject.transform.position);

//if the points of lineRenderer are more than 1, only then we can measure objects.
if (_lineRenderer.positionCount > 1)
{
//we will get vector positions of the last two points of the line renderer and store them as Vector A and Vector B.
Vector3 pointA = _lineRenderer.GetPosition(_lineRenderer.positionCount - 1);
Vector3 pointB = _lineRenderer.GetPosition(_lineRenderer.positionCount - 2);

//then we use the distance formula to calculate the distance between vectors a and b. Let us say the distance is D.
float dist=Vector3.Distance(pointA,pointB);
TextMeshPro distText = Instantiate(_textMeshPro);

//Next we instantiate the textMeshPro gameObject and store it in a variable called distText.
TextMeshPro distText = Instantiate(_textMeshPro);

//We set the value of distText equal to D. We also shorten it down to two decimal places and convert it from meters to centimeters.
distText.text = (dist * 100f).ToString("F2")+" cm";

//next, we need to align our distText with the line. we need to make sure its angle aligns with the line and that it is clearly visible to the users.
//directionVector stores the difference between pointB and pointA.
Vector3 directionVector = (pointB - pointA);

//normal stores the direction of the normal of the sphere.
Vector3 normal = args.placementObject.transform.up;

//We get the cross product of the directionVector and the normal and then use Quaternions to set the rotation of the text.
Vector3 upd=Vector3.Cross(directionVector, normal).normalized;
Quaternion rotation = Quaternion.LookRotation(-normal,upd);

distText.transform.rotation = rotation;

//the i=only thing we have to do now is to set the size of the text and center the text between the lines.
distText.transform.position = (pointA + directionVector * 0.5f) + upd * 0.008f;
}


}

void Reload()
{


SceneManager.LoadScene(SceneManager.GetActiveScene().name); // loads current scene

void Reload(){
SceneManager.LoadScene(SceneManager.GetActiveScene().name); // reloads current scene
}

}

0 comments on commit f6ab42d

Please sign in to comment.