ARCore NDK API提供了许多C++函数和类,允许开发人员在C++中使用ARCore的核心功能。以下是示例代码:
// 创建并配置session ArSession* ar_session_; ArSession_create(env, context, &ar_session_); ArSession_setDisplayGeometry(ar_session_, display_rotation_, width_, height_);
// 获取链路指向自适应质量 ArFrame* ar_frame_; ArSession_setCameraTextureName(ar_session_, texture_id_); ArSession_setDisplayGeometry(ar_session_, display_rotation_, width_, height_); ArSession_setDisplayGeometry(ar_session_, display_rotation_, width_, height_); ArSession_setDisplayGeometry(ar_session_, display_rotation_, width_, height_); ArSession_setDisplayGeometry(ar_session_, display_rotation_, width_, height_); ArSession_update(ar_session_, ar_frame_); ArFrame_acquireCameraImage(ar_session_, ar_frame_);
// 在场景中放置对象 ArHitResultList* ar_hit_result_list_; ArHitResultList_create(env, &ar_hit_result_list_); ArFrame_hitTest(ar_session_, ar_frame_, point_x_, point_y_, ar_hit_result_list_); for (int i = 0; i < ArHitResultList_getSize(ar_session_, ar_hit_result_list_); ++i) { ArHitResult* ar_hit_result = ArHitResultList_getItem(ar_session_, ar_hit_result_list_, i); ArHitResult_acquireNewAnchor(ar_session_, ar_hit_result, &ar_anchor_); ArAnchor_getPose(ar_session_, ar_anchor_, ar_pose_); }
// 渲染帧的3D模型 ArSession_setCameraTextureName(ar_session_, texture_id_); ArFrame* ar_frame_; ArSession_update(ar_session_, ar_frame_); const ArCamera* ar_camera_; ArFrame_acquireCamera(ar_session_, ar_frame_, &ar_camera_); ArPose* ar_camera_pose_; ArPose_create(ar_session_, nullptr, &ar_camera_pose_); ArCamera_getPose(ar_session_, ar_camera_, ar_camera_pose_, &error_); ArCamera_release(ar_camera_);
// 释放资源 ArSession_destroy(ar_session_); ArPose_destroy(ar_camera_pose_); ArHitResultList_destroy(ar_hit_result_list_);
上一篇:ARCore模型大小