protected override void Update() { if (smartARController_ == null) { return; } if (!smartARController_.enabled_) { return; } if (smartARController_.smart_.isConstructorFailed()) { return; } var targetEffectors = FindObjectsOfType <TargetEffector>(); if (targetEffectors == null || targetEffectors.Length <= 0) { return; } for (int i = 0; i < targetEffectors.Length; i++) { smartARController_.GetResult(targetEffectors[i].targetID, ref targetEffectors[i].result_); if (targetEffectors[i].result_.isRecognized_) { if (lastRecognizedObject_ == null || SmartAREffectorBase.IsLastRecognizedGameObject(targetEffectors[i].gameObject)) { targetEffectors[i].transform.position = new UnityEngine.Vector3(0, 0, 0); targetEffectors[i].transform.rotation = UnityEngine.Quaternion.identity; setPose(smartARController_.transform, targetEffectors[i].result_); lastRecognizedTransform_ = smartARController_.transform; lastRecognizedObject_ = targetEffectors[i].gameObject; } else { var targetTransform = new GameObject().transform; setPose(targetTransform, targetEffectors[i].result_); targetTransform.rotation = lastRecognizedTransform_.rotation * UnityEngine.Quaternion.Inverse(targetTransform.rotation); targetTransform.position = targetTransform.rotation * targetTransform.position; targetEffectors[i].transform.position = lastRecognizedTransform_.position - targetTransform.position; targetEffectors[i].transform.rotation = targetTransform.rotation; Destroy(targetTransform.gameObject); } } else { if (SmartAREffectorBase.IsLastRecognizedGameObject(targetEffectors[i].gameObject)) { ClearLastRecognized(); } } } }
protected override void SetPose(Transform transformObject, smartar.RecognitionResult result, smartar.Vector3 rotPosition) { Transform lastRecognizedTransform = SmartAREffectorBase.GetLastRecognizedTransform(); if (lastRecognizedTransform == null) { return; } if (SmartAREffectorBase.IsLastRecognizedGameObject(targetEffector_.gameObject)) { smartAREffector_.setPose(transformObject, result, rotPosition); transformObject.position = transformObject.position - lastRecognizedTransform.position; } else { if (smartAREffector_.UseFrontCamera()) { if (smartAREffector_.GetImageSensorRotation() == smartar.Rotation.ROTATION_90) { // Nexus 6P,6,5X front camera rotPosition.x_ = -rotPosition.x_; rotPosition.y_ = -rotPosition.y_; } result.position_.x_ -= rotPosition.x_; result.position_.y_ += rotPosition.y_; result.position_.z_ -= rotPosition.z_; } else { result.position_.x_ -= rotPosition.x_; result.position_.y_ -= rotPosition.y_; result.position_.z_ -= rotPosition.z_; } smartar.Vector3 zeroVec = new smartar.Vector3(); zeroVec.x_ = zeroVec.y_ = zeroVec.z_ = 0.0f; var targetTransform = new GameObject().transform; smartAREffector_.setPose(targetTransform, result, zeroVec); targetTransform.rotation = lastRecognizedTransform.rotation * UnityEngine.Quaternion.Inverse(targetTransform.rotation); targetTransform.position = targetTransform.rotation * targetTransform.position; transformObject.position = lastRecognizedTransform.position - targetTransform.position; transformObject.rotation = targetTransform.rotation; Destroy(targetTransform.gameObject); } }