【发布时间】:2019-02-16 10:26:15
【问题描述】:
我正在使用 LeanTouch+ 平移对象,但它只能在基于 android 屏幕的 Y 上移动,所以在相机上对象只能上下移动。我想要实现的是能够将对象移动得更远或更靠近相机视图。在 ARCore 中,您首先检测环境,然后将其生成为平面,这就是我需要对象移动到的平面。
如果可能的话,我想在“检测到的平面”上使用 Clamp 来限制比检测到的平面更远的移动
这是我使用 LeanFingerTap 生成 obj 的代码
public void Spawn(LeanFinger finger)
{
if (AndyPlanePrefab != null && finger != null)
{
// Raycast against the location the player touched to search for planes.
TrackableHit hit;
TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
TrackableHitFlags.FeaturePointWithSurfaceNormal;
if (Frame.Raycast(finger.ScreenPosition.x, finger.ScreenPosition.y, raycastFilter, out hit))
{
if(currentNumberofPrefab<numberOfPrefabsAllowed)
{
currentNumberofPrefab = currentNumberofPrefab + 1;
// 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
{
// Choose the Andy model for the Trackable that got hit.
if (hit.Trackable is FeaturePoint)
{
AndyPrefab = AndyPointPrefab;
}
else
{
getValue = ItemScrollList.valuePrefab;
if (getValue == 1)
{
AndyPrefab = AndyPlanePrefab[0];
Debug.Log("value 1");
}
else if (getValue == 2)
{
AndyPrefab = AndyPlanePrefab[1];
Debug.Log("value 2");
}
else if (getValue == 3)
{
AndyPrefab = AndyPlanePrefab[2];
Debug.Log("value 3");
}
else if (getValue == 4)
{
AndyPrefab = AndyPlanePrefab[3];
Debug.Log("value 4");
}
else if (getValue == 5)
{
AndyPrefab = AndyPlanePrefab[4];
Debug.Log("value 5");
}
}
// Instantiate Andy model at the hit pose.
var andyObject = Instantiate(AndyPrefab, hit.Pose.position, hit.Pose.rotation);
//adding tag to andyObject for destroying spawn purposes
andyObject.tag = "HomePrefab";
// Compensate for the hitPose rotation facing away from the raycast (i.e. camera).
andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self);
// Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
// world evolves.
var anchor = hit.Trackable.CreateAnchor(hit.Pose);
// Make Andy model a child of the anchor.
andyObject.transform.parent = anchor.transform;
}
}
}
}
}
【问题讨论】: