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 abstract void callAdjustPose(smartar.Vector3 srcPosition, smartar.Quaternion srcRotation, out smartar.Vector3 rotPosition, out smartar.Quaternion rotRotation);
protected override void callAdjustPose(smartar.Vector3 srcPosition, smartar.Quaternion srcRotation, out smartar.Vector3 rotPosition, out smartar.Quaternion rotRotation) { smartar.Rotation screenRotation = GetScreenRotation(); smartar.Rotation cameraRotation = GetCameraRotation(); SmartARController.adjustPose(cameraRotation, screenRotation, IsFlipX(), IsFlipY(), srcPosition, srcRotation, out rotPosition, out rotRotation); }
private static extern void sarSmartar_SarSmartARController_sarAdjustPose(IntPtr self, ref smartar.Vector3 fromPosition, ref smartar.Quaternion fromRotation, out smartar.Vector3 toPosition, out smartar.Quaternion toRotation);
void OnPreRender() { if (smartInitFailed_) { return; } if (self_ == IntPtr.Zero) { return; } drawStartTimeSec_ = Time.realtimeSinceStartup; #if UNITY_5_0 #if UNITY_ANDROID && !UNITY_EDITOR GL.IssuePluginEvent(0); #elif UNITY_IOS && !UNITY_EDITOR GL.Clear(true, false, Color.green); #endif #else GL.IssuePluginEvent(GetRenderEventFunc(), 0); GL.InvalidateState(); #endif // Draw landmarks if (miscSettings.showLandmarks) { // Get result var result = new smartar.RecognitionResult(); result.maxLandmarks_ = smartar.Recognizer.MAX_NUM_LANDMARKS; result.landmarks_ = landmarkBuffer_; result.maxNodePoints_ = smartar.Recognizer.MAX_NUM_NODE_POINTS; result.nodePoints_ = nodePointBuffer_; result.maxInitPoints_ = smartar.Recognizer.MAX_NUM_INITIALIZATION_POINTS; result.initPoints_ = initPointBuffer_; GetResult(null, ref result); // Draw landmarks var adjustedPosition = new smartar.Vector3(); var adjustedRotation = new smartar.Quaternion(); sarSmartar_SarSmartARController_sarAdjustPose(self_, ref result.position_, ref result.rotation_, out adjustedPosition, out adjustedRotation); var mvMatrix = new smartar.Matrix44(); smartar.Utility.convertPose2Matrix(adjustedPosition, adjustedRotation, out mvMatrix); var projMatrix = getProjMatrix(); var initPointMatrix = sarSmartar_SarSmartARController_sarGetInitPointMatrix(self_); var pmvMatrix = projMatrix * mvMatrix; // Draw Preview, landmarks, node points, init points sarSmartar_SarSmartARController_sarSetDrawData(Screen.width, Screen.height, miscSettings.showCameraPreview); sarSmartar_SarSmartARController_sarSetLandmarkDrawerDrawLandmarkData(self_, landmarkDrawer_.self_, ref pmvMatrix, result.landmarks_, result.numLandmarks_); sarSmartar_SarSmartARController_sarSetLandmarkDrawerDrawNodePointData(self_, landmarkDrawer_.self_, ref pmvMatrix, result.nodePoints_, result.numNodePoints_); sarSmartar_SarSmartARController_sarSetLandmarkDrawerDrawInitPointData(self_, landmarkDrawer_.self_, ref initPointMatrix, result.initPoints_, result.numInitPoints_); GL.IssuePluginEvent(GetRenderEventFunc(), (int)RenderEventID.DoDraw); GL.InvalidateState(); } else { sarSmartar_SarSmartARController_sarSetDrawData(Screen.width, Screen.height, miscSettings.showCameraPreview); GL.IssuePluginEvent(GetRenderEventFunc(), (int)RenderEventID.DoDraw); GL.InvalidateState(); } }