How to get click event of 3D object rendered using arcore SDK in android studio?
My requirement is to click that 3D object and show pop up dialog.
This has nothing to do with ARCore. The game engine / framework that you are using is actually responsible for that.
For example, if you are using Unity, you can use Raycasting.
RaycastHit hit;
Ray ray = yourARCamera.ScreenPointToRay(Input.GetTouch(0).position);
if (Physics.Raycast(ray, out hit))
{
// Check if what is hit is the desired object
if(hit.tag == "The_Tag_Of_The_Object_You_Are_Looking_For")
{
// User clicked the object.. Do something here..
}
}
Read more here:
https://unity3d.com/learn/tutorials/topics/physics/raycasting
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
ARCore is not supporting this feature. You need to do it by yourself. Most popular way is ray picking method. There is a lot of examples how to use it
In the case of Arcore - Sceneform SDK, after creating the anchor, you simple have to set a listener on your AnchorNode like so
anchorNode.setOnTapListener((hitResult,motionEvent)->{
//Your pop up
});
Related
Good afternoon, who once worked with heremap sdk premium for ios. How do I make it possible to click on the NMAMapMarker? What they have written in the documentation does not describe it, but maybe I'm wrong.
there are different option available for NMAMapMarker to use.
This represents a marker used to display an icon on a geographical position on a map. The map handles proper placement of icons on the screen as well as panning and rotation.
+mapMarkerWithGeoCoordinates:
+mapMarkerWithGeoCoordinates:icon:
+mapMarkerWithGeoCoordinates:image:
coordinates
icon
draggable
draggingOffsetEnabled
anchorOffset
-initWithGeoCoordinates:
-initWithGeoCoordinates:icon:
-initWithGeoCoordinates:image:
-setAnchorOffsetUsingLayoutPosition:
-setSize:forZoomLevel:
-setSize:forZoomRange:
-resetIconSize
Check for more details : https://developer.here.com/documentation/ios-premium/3.18/api_reference_jazzy/Classes/NMAMapMarker.html#%2Fc:objc(cs)NMAMapMarker(im)initWithGeoCoordinates.
Please revert with your code implementation in case of any further concern.
Is it possible to capture the tap event when we tap on a point marker or a data point? I can see there’s a DataPointSelectionModifier for WPF, but there’s nothing for iOS. Our goal is to show a popup (tooltip) on the point marker when the user taps on it.
Thanks,
Lazar Nikolov
Xamarin.iOS Package Version: 2.2.2.854
The API you are looking for is called the Hit-Test API.
In the latest (sciChart iOS v3) the documentation link is here:
private void HandleSingleTap(UITapGestureRecognizer recognizer)
{
// The touch point relative to the SCIChartSurface
var location = recognizer.LocationInView(recognizer.View.Superview);
// Translate the touch point relative to RenderableSeriesArea (or ModifierSurface)
var hitTestPoint = SciChartSurface.TranslatePoint(location, Surface.RenderableSeriesArea);
// Perform `Hit-Test` which will be stored in the `_hitTestInfo`
renderableSeries.HitTest(_hitTestInfo, hitTestPoint);
}
We also have an example showing how to use the Hit-Test API here. It is Swift but the principles in Xamarin are the same.
I am using the following link to display the camera preview using Custom renderers
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/view/
I was able to bring up the camera preview. But the preview is not at all clear. There is no Auto focus as well.
Screenshot for reference
How can I make the camera preview clearer, because I wish to use the same later on for OCR.
Thanks,
I think you already figured this out but I'm going to post the solution here for reference.
You need to setup the "Focus Mode" in the Camera properties.
Camera Preview = Camera.Open(1);
// Set the parameters.
if (Preview != null)
{
Camera.Parameters cameraParameters = Preview.GetParameters();
// Autofocus
cameraParameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
// Set
cameraPreview.Preview.SetParameters(cameraParameters);
}
For the example you mentioned (the one in https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/view/) you should place this code in you Android Cutom Renderer (CameraPreviewRenderer method OnElementChanged).
It worked for me. Hope this helps.
//Write logic inside the RunOnUiThread.
MainActivity.Instance.RunOnUiThread(() => { SetupUserInterface(); SetupEventHandlers(); AddView(view); cameraQuality = CameraQuality.High; });
I'm looking to track how long a person looks at an object in Unity when using Google Cardboard (building for iOS).
I'm not sure how to go about this. Would it be the same as mouse tracking?
Any direction would be greatly appreciated!
On each update, use a raycast from the position of the camera to determine what (if any) object is directly in front of the camera. Whenever this object changes, calculate the time difference.
Considering that you have already setup GvrReticlePointer and GvrViewerMain prefabs into your scene-
Create a script and add it to the GameObject from the inspector window.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class TimeCounter: MonoBehaviour
{
public float timer;
void Update ()
{
timer += Time.deltaTime;
}
}
Hit play and gaze towards the game object. You would find the Timer value in the inspector getting changed. You could also customize the above script and modify to your need.
It would be great to have library that both:
uses new 3D Touch api on iPhone 6s
on older devices emulates peek and pop with some gestures.
Advantages:
users of older devices could benefit from new interface possibilities
adoption of peek and pop would be faster - no need to wait years till everybody has newer model.
developers would not need to instantly buy new hardware to test 3D touch
Anybody knows if that is possible or knows code - please share with us.
You could perhaps emulate the behaviour by looking at the UITouch properties majorRadius and majorRadiusTolerance, available in iOS 8, which describe the approximate radius of the touch or "finger fatness".
This ought to be loosely correlated with pressure.
I'm not sure the properties change continuously / produce a stream of touchesMoved: callbacks, but it might be a start.
I have built a library to use as an alternative for devices without 3D Touch. My demo project also demonstrates how the project can support both types of devices. You can try it here: PeekView
The usage is pretty simple:
Add UILongPressGestureRecognizer to the view you want to peek (i.e
table view cell, image, hypertext, etc.)
Create a UIViewController
instance as the content of your peek view; then set your desired frame
for the content view. It's recommended to leave a 15px padding for
both left and right margin of your content view.
If you want to
include preview actions, prepare an array containing title of the
buttons and its preview style. Don't forget to prepare completion
handlers for when each button is tapped.
Sample snippet:
PeekView.viewForController(
parentViewController: self,
contentViewController: controller,
expectedContentViewFrame: frame,
fromGesture: gestureRecognizer,
shouldHideStatusBar: true,
withOptions: ["Option 1": .Destructive, "Option 2": .Default, "Option 3": .Selected],
completionHandler: { optionIndex in
switch optionIndex {
case 0:
print("Option 1 selected")
case 1:
print("Option 2 selected")
case 2:
print("Option 3 selected")
default:
break
}
})
Preview:
You can use this code to simulate peek and pop in the Simulator:
https://gist.github.com/nickfrey/07e2c6d8d2e5444fb91d
Adjust the time of the second dispatch_after between peek and pop.
Of course, this is only suitable for debugging since it uses private API.
This is what apple recommends:
"To ensure that all your users can access your app’s features, branch your code depending on whether 3D Touch is available. When it is available, take advantage of 3D Touch capabilities. When it is not available, provide alternatives such as by employing touch and hold, implemented with the UILongPressGestureRecognizer class."
Please check this link: https://goo.gl/4ez21g
Here’s an open source project that provides a neat tweak for the iPhone simulator that allows you to simulate 3D touch within the iOS simulator called SBShortcutMenuSimulator.
SBShortcutMenuSimulator allows you to test usage of the UIApplicationShortcutItem API even without a device supporting 3D touch.
This screenshot from the readme shows a demonstration of an application shortcut menu in the simulator:
STPopupPreview: https://github.com/kevin0571/STPopupPreview
An easy-integrate library for peak preview on non 3D Touch devices.