Closed wkl-coder closed 6 years ago
private class ARHitTestListenerCrossHair implements ARHitTestListener { @Override public void onHitTestFinished(ARHitTestResult[] arHitTestResults) { if (current_state == 0) {
// If we have found intersected AR Hit points, update views as needed, reset miss count.
ViroViewARCore viewARView = (ViroViewARCore) mViroView;
final Vector cameraPos = viewARView.getLastCameraPositionRealtime();
// Grab the closest ar hit target
float closestsDistance = Float.MAX_VALUE;
ARHitTestResult result = null;
if (arHitTestResults.length > 0) {
for (int i = 0; i < arHitTestResults.length; i++) {
ARHitTestResult currentResult = arHitTestResults[i];
float distance = currentResult.getPosition().distance(cameraPos);
if (distance < closestsDistance && distance > .3 && distance < 5) {
result = currentResult;
closestsDistance = distance;
}
}
}
// Update the cross hair target location with the closest target.
if (mCrosshairModel != null ) {
mCrosshairModel.setOpacity(1.0f);
}
Log.i("dddww","a");
animateCrossHairToPosition(result);
// Update State based on hit target
//ToastUtils.showToast(getActivity(),"bbbbbb");
}
}
}
private void animateCrossHairToPosition(ARHitTestResult result) {
if (result == null) {
if (current_state == 0) {
if (mCrosshairModel != null) {
AnimationTransaction.begin();
AnimationTransaction.setAnimationDuration(70);
AnimationTransaction.setTimingFunction(AnimationTimingFunction.EaseOut);
final Vector cameraPos = mViroView.getLastCameraPositionRealtime();
Vector add = mViroView.getLastCameraForwardRealtime().normalize().add(cameraPos);
positionRealtime = mViroView.getLastCameraForwardRealtime().normalize().add(cameraPos);
mCrosshairModel.setPosition(add);
AnimationTransaction.commit();
}else {
initARCrossHair(mScene);
}
}
return;
}
if (current_state == 0) {
if (mCrosshairModel != null) {
AnimationTransaction.begin();
AnimationTransaction.setAnimationDuration(70);
AnimationTransaction.setTimingFunction(AnimationTimingFunction.EaseOut);
mCrosshairModel.setPosition(result.getPosition());
mCrosshairModel.setRotationPivot(result.getRotation());
positionRealtime = result.getPosition();
AnimationTransaction.commit();
}
else {
initARCrossHair(mScene);
}
}
}
when I do this , some time the mCrosshaiModel not show , but the positon is work , can create 3d model
before version okay ,1.7.0 happend this
1.7.1 also
Hey @544531645, thanks for reaching out. Can you please describe what you are trying to achieve with the code above:
If its your own application, to better diagnose the issue, can you please clarify from the above:
Finally, can you show a video recording of the cursor appearing disappearing so that we can verify this visually - ezscreen recorder should do the trick here.
the current_state is my project state , 1. returned , because the animateCroossHaire is used ,if result null , I use lastcamera positioon
Hm that is weird, I've just verified that the ARRetail demo still works with it's animation cross hair code. Can you take a video of the bug you are seeing and send it to us? You can use the free screen recorder app here. Also, would it be possible to send us your project?
Closing this issue due to inactivity. If you are still having issues, please re-open with the additional information requested. Thanks
private void initARCrossHair(ARScene scene) { if (mCrosshairModel == null) { mCrosshairModel = new Object3D();