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.scenecore 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 @SurfaceTypeValue 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 public object SurfaceType { 64 /** The ray hit an unknown surface or did not hit anything */ 65 public const val UNKNOWN: Int = 0 66 /** The ray hit a flat surface such as a PanelEntity. */ 67 public const val PLANE: Int = 1 68 /** The ray hit an object that is not a flat surface such as a gltfEntity. */ 69 public const val OBJECT: Int = 2 70 } 71 72 /** The type of the source of this event. */ 73 @IntDef(SurfaceType.UNKNOWN, SurfaceType.PLANE, SurfaceType.OBJECT) 74 @Retention(AnnotationRetention.SOURCE) 75 internal annotation class SurfaceTypeValue 76 } 77