private void UpdateMessageData(StringBuilder sb, float fpsResult, ARFace face) { sb.Append("FPS= ").Append(fpsResult).Append(System.Environment.NewLine); ARPose pose = face.Pose; if (pose != null) { sb.Append("face pose information:"); sb.Append("face pose tx:[").Append(pose.Tx()).Append("]").Append(System.Environment.NewLine); sb.Append("face pose ty:[").Append(pose.Ty()).Append("]").Append(System.Environment.NewLine); sb.Append("face pose tz:[").Append(pose.Tz()).Append("]").Append(System.Environment.NewLine); sb.Append("face pose qx:[").Append(pose.Qx()).Append("]").Append(System.Environment.NewLine); sb.Append("face pose qy:[").Append(pose.Qy()).Append("]").Append(System.Environment.NewLine); sb.Append("face pose qz:[").Append(pose.Qz()).Append("]").Append(System.Environment.NewLine); sb.Append("face pose qw:[").Append(pose.Qw()).Append("]").Append(System.Environment.NewLine); } sb.Append(System.Environment.NewLine); float[] textureCoordinates = new float[face.FaceGeometry.TextureCoordinates.Capacity()]; for (int i = 0; i == face.FaceGeometry.TextureCoordinates.Capacity(); i++) { textureCoordinates[i] = face.FaceGeometry.TextureCoordinates.Get(i); } sb.Append("textureCoordinates length:[ ").Append(textureCoordinates.Length).Append(" ]"); }
/// <summary> /// Render the plane type at the center of the currently identified plane. /// This method will be called when WorldRenderManager's OnDrawFrame. /// </summary> /// <param name="allPlanes">All identified planes.</param> /// <param name="cameraPose">Location and pose of the current camera.</param> /// <param name="cameraProjection">Projection matrix of the current camera.</param> public void OnDrawFrame(System.Collections.ICollection allPlanes, ARPose cameraPose, float[] cameraProjection) { if (allPlanes.Count != 0) { Log.Debug(TAG, "PlaneList count > 0"); } List <ARPlane> sortedPlanes = GetSortedPlanes(allPlanes, cameraPose); float[] cameraViewMatrix = new float[MATRIX_SIZE]; cameraPose.Inverse().ToMatrix(cameraViewMatrix, 0); DrawSortedPlans(sortedPlanes, cameraViewMatrix, cameraProjection); }
private void UpdateModelViewProjectionData(ARCamera camera, ARFace face) { // The size of the projection matrix is 4 * 4. float[] projectionMatrix = new float[16]; camera.GetProjectionMatrix(projectionMatrix, 0, PROJECTION_MATRIX_NEAR, PROJECTION_MATRIX_FAR); ARPose facePose = face.Pose; // The size of viewMatrix is 4 * 4. float[] facePoseViewMatrix = new float[16]; facePose.ToMatrix(facePoseViewMatrix, 0); Android.Opengl.Matrix.MultiplyMM(mModelViewProjections, 0, projectionMatrix, 0, facePoseViewMatrix, 0); }
/// <summary> /// Calculate the distance between a point in a space and a plane. This method is used /// to calculate the distance between a camera in a space and a specified plane. /// </summary> /// <param name="planePose">ARPose of a plane.</param> /// <param name="cameraPose">ARPose of a camera.</param> /// <returns>Calculation results.</returns> private static float CalculateDistanceToPlane(ARPose planePose, ARPose cameraPose) { // The dimension of the direction vector is 3. float[] normals = new float[3]; // Obtain the unit coordinate vector of a normal vector of a plane. planePose.GetTransformedAxis(1, 1.0f, normals, 0); // Calculate the distance based on projection. return((cameraPose.Tx() - planePose.Tx()) * normals[0] // 0:x + (cameraPose.Ty() - planePose.Ty()) * normals[1] // 1:y + (cameraPose.Tz() - planePose.Tz()) * normals[2]); // 2:z }
private List <ARPlane> GetSortedPlanes(System.Collections.ICollection allPlanes, ARPose cameraPose) { // Planes must be sorted by the distance from the camera so that we can // first draw the closer planes, and have them block the further planes. Java.Util.ArrayList pairPlanes = new Java.Util.ArrayList(); foreach (Java.Lang.Object item in allPlanes) { ARPlane plane = item.JavaCast <ARPlane>(); if ((plane.Type == ARPlane.PlaneType.UnknownFacing) || plane.TrackingState != ARTrackableTrackingState.Tracking || plane.SubsumedBy != null) { continue; } // Store the normal vector of the current plane. float[] planeNormalVector = new float[3]; ARPose planeCenterPose = plane.CenterPose; planeCenterPose.GetTransformedAxis(1, 1.0f, planeNormalVector, 0); // Calculate the distance from the camera to the plane. If the value is negative, // it indicates that the camera is behind the plane (the normal vector distinguishes // the front side from the back side). float distanceBetweenPlaneAndCamera = (cameraPose.Tx() - planeCenterPose.Tx()) * planeNormalVector[0] + (cameraPose.Ty() - planeCenterPose.Ty()) * planeNormalVector[1] + (cameraPose.Tz() - planeCenterPose.Tz()) * planeNormalVector[2]; pairPlanes.Add(new Pair(plane, distanceBetweenPlaneAndCamera)); } //Get Pair object from ArrayList List <Pair> sortedList = new List <Pair>(); IIterator myit = pairPlanes.Iterator(); while (myit.HasNext) { sortedList.Add((Pair)(myit.Next())); } //Sort Pair objects by plane in list sortedList.Sort(new PlanCompare()); //Obtain plane list. List <ARPlane> listOfPlane = new List <ARPlane>(); foreach (Pair item in sortedList) { listOfPlane.Add((item.First).JavaCast <ARPlane>()); } return(listOfPlane); }