I'm currently working on an AR application that is able to measure volume. The functionality is required to draw a box is in the gif attached to this. I have tried to generate instantiating 3 points in a horizontal plane and then calculate the 4th point by vector calculations by this function.
Vector3 GetFourthPointPosition(Vector3 p1Transform, Vector3 p2Transform, Vector3 p3Transform)
{
var OA = p1Transform;
var OB = p2Transform;
var OC = p3Transform;
var OD = OC + OA - OB;
GetFourthPoint(OA, OB, OC, OD);
return OD;
}
Then, after that, I'm enabling a vertical plane and disable the horizontal plane to avoid adding points on the same axis. The last point is to calculate the height. After that, I'm instantiating 3 other points to generate the point view.
private void GetCompleteCube(Vector3 p1Transformation, Vector3 p2Transformation, Vector3 p3Transformation, Vector3 p4Transformation)
{
var height = Vector3.Distance(p3Transformation, p4Transformation);
var length = Vector3.Distance(p1Transformation, p2Transformation);
var width = Vector3.Distance(p2Transformation, p3Transformation);
var invPointTransform = clone.transform.position;
var p5Transformation = new Vector3(p1Transformation.x, p1Transformation.y + height, p1Transformation.z);
var p6Transformation = new Vector3(p2Transformation.x, p1Transformation.y + height, p1Transformation.z);
var p8Transformation = new Vector3(invPointTransform.x, invPointTransform.y + height, invPointTransform.z);
InstantiatePoints(p1Transformation, p1Transformation, p3Transformation, p4Transformation, p5Transformation, p6Transformation, invPointTransform, p8Transformation);
}
private void DrawCubeLineRendere(Vector3 p1Transformation, Vector3 p2Transformation, Vector3 p3Transformation, Vector3 p4Transformation, Vector3 p5Transformation, Vector3 p6Transformation, Vector3 p7Transformation, Vector3 p8Transformation)
{
Vector3[] vertexPositions = new Vector3[] { p1Transformation, p2Transformation, p3Transformation, p7Transformation, p4Transformation, p5Transformation, p6Transformation, p8Transformation };
lineRenderer.positionCount = vertexPositions.Length;
lineRenderer.SetPositions(vertexPositions);
}
I'm tried using a line renderer t0 visualize the cube but the outcome is very odd. Does not lining to form a cuboid. it looks like this.
Can anybody help me to figure out what I have done wrong?
GetFourthPoint(OA, OB, OC, OD);
and your image of your line renderer - besides the all over the place points - is a continious line, you have to at least tell them which other point they have to connect, each corner connects to three dots, not only 2. \$\endgroup\$var OD = OC + OA - OB
returns you already the forth point. \$\endgroup\$