首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >三维动画的缩进与夹出问题

三维动画的缩进与夹出问题
EN

Stack Overflow用户
提问于 2018-11-23 03:50:36
回答 1查看 89关注 0票数 1

我对这里一无所知。我正在做一个基于增强现实的项目,我正在那个应用程序中播放3D动画。我想添加一个功能,在任何3D动画的夹点和捏出应用程序。我正面临一个问题,在紧要关头和掐出来的三维动画。我已经尝试了统一形式中提供的代码,但是正交相机有一个问题。

统一站点代码

代码语言:javascript
复制
using UnityEngine;

public class PinchZoom : MonoBehaviour

{
public float perspectiveZoomSpeed = 0.5f;        // The rate of change of the field of view in perspective mode.
public float orthoZoomSpeed = 0.5f;        // The rate of change of the orthographic size in orthographic mode.


void Update()
{
    // If there are two touches on the device...
    if (Input.touchCount == 2)
    {
        // Store both touches.
        Touch touchZero = Input.GetTouch(0);
        Touch touchOne = Input.GetTouch(1);

        // Find the position in the previous frame of each touch.
        Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
        Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;

        // Find the magnitude of the vector (the distance) between the touches in each frame.
        float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
        float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;

        // Find the difference in the distances between each frame.
        float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

        // If the camera is orthographic...
        if (camera.isOrthoGraphic)
        {
            // ... change the orthographic size based on the change in distance between the touches.
            camera.orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;

            // Make sure the orthographic size never drops below zero.
            camera.orthographicSize = Mathf.Max(camera.orthographicSize, 0.1f);
        }
        else
        {
            // Otherwise change the field of view based on the change in distance between the touches.
            camera.fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed;

            // Clamp the field of view to make sure it's between 0 and 180.
            camera.fieldOfView = Mathf.Clamp(camera.fieldOfView, 0.1f, 179.9f);
        }
    }
}

}

我的尝试

代码语言:javascript
复制
using UnityEngine;

public class Pinch_MUN : MonoBehaviour {

public float perspectiveZoomSpeed = 0.5f;        // The rate of change of the field of view in perspective mode.
public float orthoZoomSpeed = 0.5f;        // The rate of change of the orthographic size in orthographic mode.


void Update()
{
    // If there are two touches on the device...
    if (Input.touchCount == 2)
    {
        // Store both touches.
        Touch touchZero = Input.GetTouch(0);
        Touch touchOne = Input.GetTouch(1);

        // Find the position in the previous frame of each touch.
        Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
        Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;

        // Find the magnitude of the vector (the distance) between the touches in each frame.
        float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
        float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;

        // Find the difference in the distances between each frame.
        float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

        // If the camera is orthographic...
        if (GetComponent<Camera>().orthographic == true)
        {
            // ... change the orthographic size based on the change in distance between the touches.
            GetComponent<Camera>().orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;

            // Make sure the orthographic size never drops below zero.
            GetComponent<Camera>().orthographicSize = Mathf.Max(GetComponent<Camera>().orthographicSize, 0.1f);
        }
        else
        {
            // Otherwise change the field of view based on the change in distance between the touches.
            GetComponent<Camera>().fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed;

            // Clamp the field of view to make sure it's between 0 and 180.
            GetComponent<Camera>().fieldOfView = Mathf.Clamp(GetComponent<Camera>().fieldOfView, 0.1f, 179.9f);
        }
    }
}

}

这对我来说并不重要,我们要么捏相机,要么简单地捏一下视图中的3D动画。根据上述情况,请帮助我找出我的错误。提前谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2018-11-24 12:26:12

不要编写自己的手势检测逻辑,而是使用现成的解决方案(我在一些项目中使用了TouchKit )。在AR中,您不能修改相机属性(位置或fov),因为它会使虚拟相机与物理摄像机不同步。您应该逐步缩放游戏对象上下调整大小。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53440455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档