static public void adjustPose(smartar.Rotation cameraRotation, smartar.Rotation screenRotation, bool isFlipX, bool isFlipY, smartar.Vector3 srcPosition, smartar.Quaternion srcRotation, out smartar.Vector3 rotPosition, out smartar.Quaternion rotRotation) { smartar.Rotation rotation = (smartar.Rotation)((cameraRotation - screenRotation + 360) % 360); rotPosition = srcPosition; rotRotation = srcRotation; if (isFlipX) { rotPosition.x_ = -rotPosition.x_; rotRotation.y_ = -rotRotation.y_; rotRotation.z_ = -rotRotation.z_; } if (isFlipY) { rotPosition.y_ = -rotPosition.y_; rotRotation.x_ = -rotRotation.x_; rotRotation.z_ = -rotRotation.z_; } if (rotation != smartar.Rotation.ROTATION_0) { float rad; switch (rotation) { case smartar.Rotation.ROTATION_90: { rad = Mathf.PI * 0.5f * 0.5f; break; } case smartar.Rotation.ROTATION_180: { rad = Mathf.PI * 1.0f * 0.5f; break; } case smartar.Rotation.ROTATION_270: { rad = Mathf.PI * 1.5f * 0.5f; break; } default: throw new InvalidOperationException("unexpected value: " + rotation); } // rotate pose around z axis Quaternion quat0 = new Quaternion(rotRotation.x_, rotRotation.z_, rotRotation.y_, rotRotation.w_); Quaternion quat1 = new Quaternion(0.0f, Mathf.Sin(rad), 0.0f, Mathf.Cos(rad)); quat0 = quat0 * quat1; rotRotation.x_ = quat0.x; rotRotation.y_ = quat0.z; rotRotation.z_ = quat0.y; rotRotation.w_ = quat0.w; } }
protected virtual void Update() { if (!showLandmarks) { disableLandmarkAndNodes(); return; } // Get recognition result GetResult(ref result_); // Set pose if (result_.isRecognized_) { smartar.Vector3 rotPosition; smartar.Quaternion rotRotation; smartar.Rotation screenRotation = GetScreenRotation(); smartar.Rotation cameraRotation = GetCameraRotation(); SmartARController.adjustPose( cameraRotation, screenRotation, IsFlipX(), IsFlipY(), result_.position_, result_.rotation_, out rotPosition, out rotRotation); // Draw nodePoints in unity if (result_.numNodePoints_ > 0) { IntPtr nodePointPtr = result_.nodePoints_; // for drawing Color nodePointColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); for (int i = 0; i < result_.maxNodePoints_; i++) { // get a current nodePoint smartar.NodePoint curNodePoint = (smartar.NodePoint)Marshal.PtrToStructure(nodePointPtr, typeof(smartar.NodePoint)); if (i < result_.numNodePoints_) { // set position and rotation for nodePoint smartar.Vector3 rotNodePosition; smartar.Quaternion rotNodeRotation; SmartARController.adjustPose( GetCameraRotation(), screenRotation, IsFlipX(), IsFlipY(), curNodePoint.position_, result_.rotation_, out rotNodePosition, out rotNodeRotation); SetPose(nodePointObjects_[i].transform, result_, rotNodePosition); nodePointObjects_[i].GetComponent <Renderer>().material.SetColor("_Color", nodePointColor); nodePointObjects_[i].SetActive(true); //Debug.Log ("nodePointObjects_[" + i + "].transform.position = " + nodePointObjects_[i].transform.position); } else { nodePointObjects_[i].SetActive(false); } // go to a next ptr nodePointPtr = new IntPtr(nodePointPtr.ToInt64() + (Int64)Marshal.SizeOf(curNodePoint)); } } // Draw landmarks in unity if (result_.numLandmarks_ > 0) { IntPtr landmarkPtr = result_.landmarks_; // for drawing Color landmarkColor; for (int i = 0; i < result_.maxLandmarks_; i++) { // get a current landmark smartar.Landmark curLandmark = (smartar.Landmark)Marshal.PtrToStructure(landmarkPtr, typeof(smartar.Landmark)); if (i < result_.numLandmarks_) { // set position and rotation for landmarks smartar.Vector3 rotLandmarkPosition; smartar.Quaternion rotLandmarkRotation; SmartARController.adjustPose( GetCameraRotation(), screenRotation, IsFlipX(), IsFlipY(), curLandmark.position_, result_.rotation_, out rotLandmarkPosition, out rotLandmarkRotation); SetPose(landmarkObjects_[i].transform, result_, rotLandmarkPosition); // set color switch (curLandmark.state_) { case smartar.LandmarkState.LANDMARK_STATE_TRACKED: landmarkColor = new Color(0.0f, 1.0f, 0.0f, 1.0f); break; case smartar.LandmarkState.LANDMARK_STATE_LOST: landmarkColor = new Color(1.0f, 0.0f, 0.0f, 1.0f); break; case smartar.LandmarkState.LANDMARK_STATE_SUSPENDED: landmarkColor = new Color(0.0f, 1.0f, 1.0f, 1.0f); break; case smartar.LandmarkState.LANDMARK_STATE_MASKED: landmarkColor = new Color(1.0f, 1.0f, 0.0f, 1.0f); break; default: landmarkColor = new Color(0.0f, 0.0f, 0.0f, 1.0f); break; } landmarkObjects_[i].GetComponent <Renderer>().material.SetColor("_Color", landmarkColor); landmarkObjects_[i].SetActive(true); //Debug.Log ("landmarkObjects_[" + i + "].transform.position = " + landmarkObjects_[i].transform.position); } else { landmarkObjects_[i].SetActive(false); } // go to a next ptr landmarkPtr = new IntPtr(landmarkPtr.ToInt64() + (Int64)Marshal.SizeOf(curLandmark)); } } } else { disableLandmarkAndNodes(); } }