当前位置:   article > 正文

Unity编程笔录--实现AR与3D场景结合效果_unity ar 空间环境识别

unity ar 空间环境识别

前言:大家都知道AR通过扫描识别图来显示3D效果,也可通过Vuforia扩展追踪来实现物体在空间中显示(效果不是很好),本文来实现一个AR和3D场景相结合产生的效果。具体可看效果:

准备资料:

      AR使用的是插件Vuforia:下载地址:https://developer.vuforia.com/downloads/sdk

        控制陀螺仪脚本:
  1. using UnityEngine;
  2. /// <summary>
  3. /// Gyroscope controller that works with any device orientation.
  4. /// </summary>
  5. public class GyroController : MonoBehaviour
  6. {
  7. #region [Private fields]
  8. private bool gyroEnabled = true;
  9. private const float lowPassFilterFactor = 0.2f;
  10. private readonly Quaternion baseIdentity = Quaternion.Euler(90, 0, 0);
  11. private Quaternion cameraBase = Quaternion.identity;
  12. private Quaternion calibration = Quaternion.identity;
  13. private Quaternion baseOrientation = Quaternion.Euler(90, 0, 0);
  14. private Quaternion baseOrientationRotationFix = Quaternion.identity;
  15. private Quaternion referanceRotation = Quaternion.identity;
  16. private bool debug = false;
  17. #endregion
  18. #region [Unity events]
  19. protected void Start()
  20. {
  21. AttachGyro();
  22. }
  23. protected void Update()
  24. {
  25. if (!gyroEnabled)
  26. return;
  27. transform.rotation = Quaternion.Slerp(transform.rotation,
  28. cameraBase * (ConvertRotation(referanceRotation * Input.gyro.attitude) * GetRotFix()), lowPassFilterFactor);
  29. }
  30. protec
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/535776
推荐阅读
相关标签
  

闽ICP备14008679号