1 /* 2 * Copyright 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.xr.runtime.internal 18 19 import androidx.annotation.IntDef 20 import androidx.annotation.RestrictTo 21 import androidx.xr.runtime.math.Vector3 22 23 /** 24 * Defines an intersection between a ray and the scene. 25 * 26 * This can be obtained by running [hitTest] or [hitTestAsync] on an [ActivityPose]. 27 * 28 * @property hitPosition the [Vector3] position of the intersection between a ray and the Scene. 29 * This will be null if nothing was hit 30 * @property surfaceNormal The normal of the surface of the entity that was hit. This will be null 31 * if nothing was hit 32 * @property surfaceType the [HitTestSurfaceType] that was hit. 33 * @property distance the distance from the origin to the hit location. If nothing was hit the 34 * distance will be POSITIVE_INFINITY. 35 */ 36 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) 37 public class HitTestResult( 38 public val hitPosition: Vector3?, 39 public val surfaceNormal: Vector3?, 40 @HitTestSurfaceTypeValue public val surfaceType: Int, 41 public val distance: Float, 42 ) { 43 equalsnull44 override fun equals(other: Any?): Boolean { 45 if (this === other) return true 46 if (other !is HitTestResult) return false 47 48 if (surfaceType != other.surfaceType) return false 49 if (hitPosition != other.hitPosition) return false 50 if (surfaceNormal != other.surfaceNormal) return false 51 if (distance != other.distance) return false 52 return true 53 } 54 hashCodenull55 override fun hashCode(): Int { 56 var result = surfaceType.hashCode() 57 result = 31 * result + hitPosition.hashCode() 58 result = 31 * result + surfaceNormal.hashCode() 59 result = 31 * result + distance.hashCode() 60 return result 61 } 62 63 @IntDef( 64 HitTestSurfaceType.HIT_TEST_RESULT_SURFACE_TYPE_UNKNOWN, 65 HitTestSurfaceType.HIT_TEST_RESULT_SURFACE_TYPE_PLANE, 66 HitTestSurfaceType.HIT_TEST_RESULT_SURFACE_TYPE_OBJECT, 67 ) 68 @Retention(AnnotationRetention.SOURCE) 69 @Suppress("PublicTypedef") 70 public annotation class HitTestSurfaceTypeValue 71 72 /** The type of the surface that was hit. */ 73 public object HitTestSurfaceType { 74 /** The ray hit an unknown surface or did not hit anything */ 75 public const val HIT_TEST_RESULT_SURFACE_TYPE_UNKNOWN: Int = 0 76 /** The ray hit a flat surface such as a PanelEntity. */ 77 public const val HIT_TEST_RESULT_SURFACE_TYPE_PLANE: Int = 1 78 /** The ray hit an object that is not a flat surface such as a gltfEntity. */ 79 public const val HIT_TEST_RESULT_SURFACE_TYPE_OBJECT: Int = 2 80 } 81 } 82