如何使用Kudan Markerless增强现实防止对象在Unity 3D中旋转?

时间:2016-03-06 15:16:32

标签: android unity3d augmented-reality android-augmented-reality

我一直致力于增强现实Kudan的统一SDK。我已经看过这些教程,其中对象似乎是静态的,但当我尝试旋转的对象不符合我的要求时,我无法停止旋转。如果你帮助停止轮换,那么我将继续感谢你!

2 个答案:

答案 0 :(得分:0)

您的意思是对象相对于您自己的手机旋转旋转吗?我遇到了这个问题,希望在Kudan中放置一个垂直于相机的2D平面,并进行无标记跟踪。根据我自己的旋转,它会使飞机保持在相同的世界方向,因此在不同的旋转时它不会垂直。当使用MarkerlessTransformDriver激活Augment对象时,我通过硬编码方向转换来解决它。

答案 1 :(得分:0)

我认为你应该使用无标记增强现实 并且它不需要任何sdk只需一行代码

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class WebCamScript : MonoBehaviour {

    public GameObject WebcamPlane;
    public Button FireButton;
    // Use this for initialization
    void Start () {
        if(Application.isMobilePlatform)
        {
            GameObject cameraParent = new GameObject("camParent");
            cameraParent.transform.position = this.transform.position;
            this.transform.parent = cameraParent.transform;
            cameraParent.transform.Rotate(Vector3.right, 90);
        }

        Input.gyro.enabled = true;

        WebCamTexture webCameraTexture = new WebCamTexture();
        WebcamPlane.GetComponent<MeshRenderer>().material.mainTexture = webCameraTexture;
        webCameraTexture.Play();

        FireButton.onClick.AddListener(OnButtonDown);

    }

    void OnButtonDown()
    {
        GameObject bullet = Instantiate(Resources.Load("bullet", typeof(GameObject))) as GameObject;
        Rigidbody rb = bullet.GetComponent<Rigidbody>();
        bullet.transform.rotation = Camera.main.transform.rotation;
        bullet.transform.position = Camera.main.transform.position;
        rb.AddForce(Camera.main.transform.forward * 500f);
        Destroy(bullet, 3);

        GetComponent<AudioSource>().Play();
    }

    // Update is called once per frame
    void Update ()
    {
        Quaternion cameraRotation = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w);
        this.transform.localRotation = cameraRotation;

    }
}