我正在 Unity 开发一个 tan-gram 游戏。我想将对象旋转 360 度,但它不起作用。我想通过网络摄像头旋转我的对象。意味着当我旋转现实世界对象时,我希望游戏对象随着现实世界对象的旋转而旋转。我正在使用标记作为现实世界的对象。它与上面的代码一起旋转。但它并不准确。它比真正的旋转更快。
void Update ()
{
if (NyARWebCam == null) {
return;
}
NyARWebCam.update ();
NyARMarker.update (NyARWebCam);
bool checkMarker = NyARMarker.isExistMarker (mId);
bool checkMarker2 = NyARMarker.isExistMarker (mId2);
string s = "", pos = "", p = "";
float firstMarker = 0f, secondMarker = 0f;
if (checkMarker) {
NyARMarker.getMarkerTransform (mId, ref markerPosition1, ref markerRotation);
if (count1 == 0) {
float temp = (markerPosition1.z + actualZ);
applyZ1 = (markerPosition1.z - temp) + 50;
newZ1 = temp;
count1++;
} else {
applyZ1 = (markerPosition1.z - newZ1) + 50;
}
applyX1 = markerPosition1.x/2;
b.transform.position = Vector3.Lerp (b.transform.position, new Vector3 (-applyX1, 36.98051f, 36.98051f), 0.5f * Time.deltaTime);
float n = 1.0f;
n =(float) (markerRotation.x* Mathf.Rad2Deg);
Debug.Log (n);
b.transform.rotation = Quaternion.Euler (n*(n/8), 90, 0);
pos = "" + applyZ1;
firstMarker = applyX1;
}