अपने Android एनडीके ऐप्लिकेशन में हिट-टेस्ट करना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
अपने सीन में 3D ऑब्जेक्ट का सही प्लेसमेंट पता करने के लिए, हिट-टेस्ट करें. सही प्लेसमेंट से यह पक्का होता है कि एआर कॉन्टेंट सही (बेहतर) साइज़ में रेंडर हो.
हिट के नतीजे के टाइप
हिट-टेस्ट से चार अलग-अलग तरह के हिट मिल सकते हैं, जैसा कि नीचे दी गई टेबल में दिखाया गया है.
हिट के नतीजे का टाइप |
ब्यौरा |
ओरिएंटेशन |
इस्तेमाल का उदाहरण |
मेथड कॉल |
गहराई (AR_TRACKABLE_DEPTH_POINT ) |
किसी पॉइंट की सही गहराई और ओरिएंटेशन पता करने के लिए, पूरे सीन की डेप्थ की जानकारी का इस्तेमाल किया जाता है
|
3D सतह के लंबवत
|
किसी भी सतह पर वर्चुअल ऑब्जेक्ट रखें (न कि सिर्फ़ फ़्लोर और दीवारों पर)
|
यह सुविधा काम करे, इसके लिए ArDepthMode चालू होना चाहिए.
ArFrame_hitTest , लौटाए गए सामान की सूची में ArDepthPoint देखें
|
हवाई जहाज़ (AR_TRACKABLE_PLANE ) |
पॉइंट की सही गहराई और ओरिएंटेशन का पता लगाने के लिए, हॉरिज़ॉन्टल और/या वर्टिकल सतहों पर हिट करें
|
3D सतह के लंबवत
|
हवाई जहाज़ की पूरी ज्यामिति का इस्तेमाल करके हवाई जहाज़ (फ़्लोर या दीवार) पर कोई चीज़ रखें. सही स्केल तुरंत चाहिए. डेप्थ हिट-टेस्ट के लिए फ़ॉलबैक
|
ArFrame_hitTest , लौटाए गए सामान की सूची में ArPlane देखें
|
फ़ीचर पॉइंट (AR_TRACKABLE_POINT ) |
पॉइंट की सही पोज़िशन और ओरिएंटेशन का पता लगाने के लिए, उपयोगकर्ता की ओर से टैप किए जाने वाले हिस्से के आस-पास मौजूद विज़ुअल सुविधाओं की मदद ली जाती है
|
3D सतह के लंबवत
|
किसी भी सतह पर (न कि सिर्फ़ फ़्लोर और दीवार पर) ऑब्जेक्ट को रखें
|
ArFrame_hitTest , लौटाए गए सामान की सूची में ArPoint देखें
|
झटपट प्लेसमेंट (AR_TRACKABLE_INSTANT_PLACEMENT_POINT ) |
कॉन्टेंट को जगह की जानकारी देने के लिए स्क्रीन स्पेस का इस्तेमाल किया जाता है. शुरुआत में, ऐप्लिकेशन से मिली अनुमानित डेप्थ का इस्तेमाल किया जाता है. यह तुरंत काम करता है. हालांकि, जब ARCore किसी सीन की असल ज्यामिति तय कर लेता है, तो पोज़ और असल डेप्थ बदल जाती है
|
+Y ऊपर की ओर इशारा करता है, गुरुत्वाकर्षण के उलट है
|
हवाई जहाज़ की पूरी ज्यामिति का इस्तेमाल करके, किसी चीज़ को हवाई जहाज़ (फ़्लोर या दीवार) पर रखें, जहां वीडियो को तेज़ी से लगाने की ज़रूरत हो. ऐसा करने से अनुभव, अज्ञात शुरुआती गहराई और स्केल को सहन कर सकता है
|
ArFrame_hitTestInstantPlacement
|
हिट टेस्ट करने के लिए, ArFrame_hitTest
को कॉल करें.
ArHitResultList* hit_result_list = NULL;
ArHitResultList_create(ar_session, &hit_result_list);
CHECK(hit_result_list);
if (is_instant_placement_enabled) {
ArFrame_hitTestInstantPlacement(ar_session, ar_frame, x, y,
k_approximate_distance_meters,
hit_result_list);
} else {
ArFrame_hitTest(ar_session, ar_frame, x, y, hit_result_list);
}
अपनी पसंद के हिसाब से हिट के नतीजों को फ़िल्टर करें. उदाहरण के लिए, अगर आपको ArPlane
पर फ़ोकस करना है:
int32_t hit_result_list_size = 0;
ArHitResultList_getSize(ar_session, hit_result_list, &hit_result_list_size);
// Returned hit-test results are sorted by increasing distance from the camera
// or virtual ray's origin. The first hit result is often the most relevant
// when responding to user input.
ArHitResult* ar_hit_result = NULL;
for (int32_t i = 0; i < hit_result_list_size; ++i) {
ArHitResult* ar_hit = NULL;
ArHitResult_create(ar_session, &ar_hit);
ArHitResultList_getItem(ar_session, hit_result_list, i, ar_hit);
if (ar_hit == NULL) {
LOGE("No item was hit.");
return;
}
ArTrackable* ar_trackable = NULL;
ArHitResult_acquireTrackable(ar_session, ar_hit, &ar_trackable);
ArTrackableType ar_trackable_type = AR_TRACKABLE_NOT_VALID;
ArTrackable_getType(ar_session, ar_trackable, &ar_trackable_type);
// Creates an anchor if a plane was hit.
if (ar_trackable_type == AR_TRACKABLE_PLANE) {
// Do something with this hit result. For example, create an anchor at
// this point of interest.
ArAnchor* anchor = NULL;
ArHitResult_acquireNewAnchor(ar_session, ar_hit, &anchor);
// TODO: Use this anchor in your AR experience.
ArAnchor_release(anchor);
ArHitResult_destroy(ar_hit);
ArTrackable_release(ar_trackable);
break;
}
ArHitResult_destroy(ar_hit);
ArTrackable_release(ar_trackable);
}
ArHitResultList_destroy(hit_result_list);
आर्बिट्रेरी किरण और दिशा का इस्तेमाल करके हिट-टेस्ट करना
हिट-टेस्ट को आम तौर पर, डिवाइस या डिवाइस के कैमरे से ली गई किरणों के तौर पर देखा जाता है. हालांकि, दुनिया के अंतरिक्ष निर्देशांकों में, स्क्रीन-स्पेस पॉइंट के बजाय आर्बिट्रेरी किरण का इस्तेमाल करके हिट-टेस्ट करने के लिए ArFrame_hitTestRay
का इस्तेमाल किया जा सकता है.
हिट के नतीजे में ऐंकर अटैच करना
कोई हिट नतीजा मिलने के बाद, सीन में एआर (ऑगमेंटेड रिएलिटी) कॉन्टेंट रखने के लिए, इसके पोज़ को इनपुट के तौर पर इस्तेमाल किया जा सकता है. हिट स्थान पर नया एंकर बनाने के लिए ArHitResult_acquireNewAnchor
का उपयोग करें.
आगे क्या होगा
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-07-26 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-07-26 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eUse hit-tests to accurately place 3D objects in your AR scene by determining their correct position and orientation in the real world.\u003c/p\u003e\n"],["\u003cp\u003eHit-tests offer four types of results: Depth, Plane, Feature Point, and Instant Placement, each suited for different placement scenarios and surface types.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eArFrame_hitTest\u003c/code\u003e and \u003ccode\u003eArFrame_hitTestInstantPlacement\u003c/code\u003e are the primary methods used to perform hit-tests, with the former focusing on precision and the latter on speed.\u003c/p\u003e\n"],["\u003cp\u003eOnce a hit-test is performed, filter the results based on your desired trackable type (e.g., planes) and create an anchor to attach your AR content to the hit location.\u003c/p\u003e\n"],["\u003cp\u003eAnchors are created from successful hit-tests using \u003ccode\u003eArHitResult_acquireNewAnchor\u003c/code\u003e, allowing virtual objects to remain persistently placed in the real world.\u003c/p\u003e\n"]]],["Hit-tests determine 3D object placement in AR scenes, ensuring correct size. Four result types exist: Depth (for arbitrary surfaces), Plane (for floors/walls), Feature Point (for user-tapped surfaces), and Instant Placement (for rapid, initially estimated placement). Use `ArFrame_hitTest` or `ArFrame_hitTestInstantPlacement` to perform hit tests and filter results based on `ArTrackableType`. `ArFrame_hitTestRay` enables tests with arbitrary rays. `ArHitResult_acquireNewAnchor` creates an Anchor at the hit location for AR content placement.\n"],null,["# Perform hit-tests in your Android NDK app\n\nPerform a [hit-test](/ar/develop/hit-test) to determine the correct placement of a 3D object in your scene. Correct placement ensures that the AR content is rendered at the appropriate (apparent) size.\n\nHit result types\n----------------\n\nA hit-test can yield four different types of hit results, as shown by the following table.\n\n| Hit result type | Description | Orientation | Use case | Method calls |\n|---------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Depth ([`AR_TRACKABLE_DEPTH_POINT`](/ar/reference/c/group/ar-trackable#ar_trackable_depth_point)) | Uses depth information from the entire scene to determine a point's correct depth and orientation | Perpendicular to the 3D surface | Place a virtual object on an arbitrary surface (not just on floors and walls) | **[`ArDepthMode`](/ar/reference/c/group/ar-config#ardepthmode) must be enabled for this to work.** [`ArFrame_hitTest`](/ar/reference/c/group/ar-frame#arframe_hittest), check for [`ArDepthPoint`](/ar/reference/c/group/ar-depth-point#ardepthpoint)s in the return list |\n| Plane ([`AR_TRACKABLE_PLANE`](/ar/reference/c/group/ar-trackable#ar_trackable_plane)) | Hits horizontal and/or vertical surfaces to determine a point's correct depth and orientation | Perpendicular to the 3D surface | Place an object on a plane (floor or wall) using the plane's full geometry. Need correct scale immediately. Fallback for the Depth hit-test | [`ArFrame_hitTest`](/ar/reference/c/group/ar-frame#arframe_hittest), check for [`ArPlane`](/ar/reference/c/group/ar-plane)s in the return list |\n| Feature point ([`AR_TRACKABLE_POINT`](/ar/reference/c/group/ar-trackable#ar_trackable_point)) | Relies on visual features around the point of a user tap to determine a point's correct position and orientation | Perpendicular to the 3D surface | Place an object on an arbitrary surface (not just on floors and walls) | [`ArFrame_hitTest`](/ar/reference/c/group/ar-frame#arframe_hittest), check for [`ArPoint`](/ar/reference/c/group/ar-point)s in the return list |\n| Instant Placement ([`AR_TRACKABLE_INSTANT_PLACEMENT_POINT`](/ar/reference/c/group/ar-trackable#ar_trackable_instant_placement_point)) | Uses screen space to place content. Initially uses estimated depth provided by the app. Works instantly, but pose and actual depth will change once ARCore is able to determine actual scene geometry | +Y pointing up, opposite to gravity | Place an object on a plane (floor or wall) using the plane's full geometry where fast placement is critical, and the experience can tolerate unknown initial depth and scale | [`ArFrame_hitTestInstantPlacement`](/ar/reference/c/group/ar-frame#arframe_hittestinstantplacement) |\n\nPerform a standard hit-test\n---------------------------\n\nCall [`ArFrame_hitTest`](/ar/reference/c/group/ar-frame#arframe_hittest) to perform a hit test. \n\n```c\nArHitResultList* hit_result_list = NULL;\nArHitResultList_create(ar_session, &hit_result_list);\nCHECK(hit_result_list);\nif (is_instant_placement_enabled) {\n ArFrame_hitTestInstantPlacement(ar_session, ar_frame, x, y,\n k_approximate_distance_meters,\n hit_result_list);\n} else {\n ArFrame_hitTest(ar_session, ar_frame, x, y, hit_result_list);\n}\n```\n\nFilter hit results based on the type you're interested in. For example, if you'd like to focus on `ArPlane`s: \n\n```c\nint32_t hit_result_list_size = 0;\nArHitResultList_getSize(ar_session, hit_result_list, &hit_result_list_size);\n\n// Returned hit-test results are sorted by increasing distance from the camera\n// or virtual ray's origin. The first hit result is often the most relevant\n// when responding to user input.\nArHitResult* ar_hit_result = NULL;\nfor (int32_t i = 0; i \u003c hit_result_list_size; ++i) {\n ArHitResult* ar_hit = NULL;\n ArHitResult_create(ar_session, &ar_hit);\n ArHitResultList_getItem(ar_session, hit_result_list, i, ar_hit);\n\n if (ar_hit == NULL) {\n LOGE(\"No item was hit.\");\n return;\n }\n\n ArTrackable* ar_trackable = NULL;\n ArHitResult_acquireTrackable(ar_session, ar_hit, &ar_trackable);\n ArTrackableType ar_trackable_type = AR_TRACKABLE_NOT_VALID;\n ArTrackable_getType(ar_session, ar_trackable, &ar_trackable_type);\n // Creates an anchor if a plane was hit.\n if (ar_trackable_type == AR_TRACKABLE_PLANE) {\n // Do something with this hit result. For example, create an anchor at\n // this point of interest.\n ArAnchor* anchor = NULL;\n ArHitResult_acquireNewAnchor(ar_session, ar_hit, &anchor);\n\n // TODO: Use this anchor in your AR experience.\n\n ArAnchor_release(anchor);\n ArHitResult_destroy(ar_hit);\n ArTrackable_release(ar_trackable);\n break;\n }\n ArHitResult_destroy(ar_hit);\n ArTrackable_release(ar_trackable);\n}\nArHitResultList_destroy(hit_result_list);\n```\n\nConduct a hit-test using an arbitrary ray and direction\n-------------------------------------------------------\n\nHit-tests are typically treated as rays from the device or device camera, but you can use [`ArFrame_hitTestRay`](/ar/reference/c/group/ar-frame#arframe_hittestray) to conduct a hit-test using an arbitrary ray in world space coordinates instead of a screen-space point.\n\nAttach an Anchor to a HitResult\n-------------------------------\n\nOnce you have a hit result, you can use its pose as input to [place AR content](/ar/develop/anchors) in your scene. Use [`ArHitResult_acquireNewAnchor`](/ar/reference/c/group/ar-hit-result#arhitresult_acquirenewanchor) to create a new [Anchor](/ar/develop/anchors) at the hit location.\n\nWhat's next\n-----------\n\n- Check out the [`hello_ar_c`](https://github.com/google-ar/arcore-android-sdk/tree/master/samples/hello_ar_c) sample app on GitHub."]]