Created
February 16, 2020 05:24
-
-
Save shibuiwilliam/7091e31bf57c49756b2e89d091d4d0d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun measureDistanceFromCamera(){ | |
val frame = arFragment!!.arSceneView.arFrame | |
if (placedAnchorNodes.size >= 1) { | |
val distanceMeter = calculateDistance( | |
placedAnchorNodes[0].worldPosition, | |
frame!!.camera.pose) | |
measureDistanceOf2Points(distanceMeter) | |
} | |
} | |
private fun measureDistanceOf2Points(distanceMeter: Float){ | |
val distanceTextCM = makeDistanceTextWithCM(distanceMeter) | |
val textView = (distanceCardViewRenderable!!.view as LinearLayout) | |
.findViewById<TextView>(R.id.distanceCard) | |
textView.text = distanceTextCM | |
Log.d(TAG, "distance: ${distanceTextCM}") | |
} | |
private fun calculateDistance(x: Float, y: Float, z: Float): Float{ | |
return sqrt(x.pow(2) + y.pow(2) + z.pow(2)) | |
} | |
private fun calculateDistance(objectPose0: Vector3, objectPose1: Pose): Float{ | |
return calculateDistance( | |
objectPose0.x - objectPose1.tx(), | |
objectPose0.y - objectPose1.ty(), | |
objectPose0.z - objectPose1.tz() | |
) | |
} | |
private fun changeUnit(distanceMeter: Float, unit: String): Float{ | |
return when(unit){ | |
"cm" -> distanceMeter * 100 | |
"mm" -> distanceMeter * 1000 | |
else -> distanceMeter | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment