我有一个检测垂直表面的应用程序。现在,当检测到垂直表面时,ARCore会绘制出一个表面网格以匹配垂直表面的角度。
我想做的就是获得表面平面网格的旋转,因为如果我(从左侧)扫描一个看着它的表面,我在墙上的实例化模型将指向正确的方向。如果我从另一侧(从右侧)扫描表面并实例化该模型,则该模型将倒置180度。
我的想法是检查旋转量,如果旋转量达到阈值,则在实例化模型之前将偏移量添加到模型中。
if (touch.phase == TouchPhase.Began)
{
Debug.Log("Touch Began");
if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
{
if (CurrentNumberOfGameObjects < numberOfGameObjectsAllowed)
{
Instructions.SetActive(true);
Debug.Log("Screen Touched");
Destroy(ARObject);
// Use hit pose and camera pose to check if hittest is from the
// back of the plane, if it is, no need to create the anchor.
if ((hit.Trackable is DetectedPlane) &&
Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
hit.Pose.rotation * Vector3.up) < 0)
{
Debug.Log("Hit at back of the current DetectedPlane");
}
else
{
ARObject = Instantiate(ARAndroidPrefab, hit.Pose.position, hit.Pose.rotation);// Instantiate Andy model at the hit pose.
ARObject.transform.Rotate(x_ModelRotation, k_ModelRotation, z_ModelRotation, Space.Self);// Compensate for the hitPose rotation facing away from the raycast (i.e. camera).
demoscript.quad.transform.Rotate(x_ModelRotation, k_ModelRotation, z_ModelRotation, Space.Self);
//var anchor = hit.Trackable.CreateAnchor(hit.Pose);
anchor = hit.Trackable.CreateAnchor(hit.Pose);
ARObject.transform.parent = anchor.transform;
CurrentNumberOfGameObjects = CurrentNumberOfGameObjects + 1;
// Hide Plane once ARObject is Instantiated
foreach (GameObject Temp in DetectedPlaneGenerator.instance.PLANES) //RK
{
Temp.SetActive(false);
}
}
}
}
}
这是实例化统一预制件的代码的一部分。
x_ModelRotation is 0.0f;
z_ModelRotation is 0.0f;
我曾尝试检查Pose的旋转并将其结果输出到文本调试中,但是对于生成的平面,我始终会得到0,0,0,0的值。
关于如何获得垂直曲面网格旋转的任何想法?