Log in or register to post comments

how can we give touch event on 2d image which comes after detection in image target sample

March 14, 2013 - 9:17pm #1

Hi,

how can i give touch event to 2d image drawn over image target after detection.I want to give various touch over one image according to posion of touch.

i followed https://developer.vuforia.com/resources/dev-guide/textured-plane-target link  to draw 2d image in place of teapot image over image target in image target sample.now i am able to draw the image over target image.

how can we give touch event on 2d image which comes after detect

May 28, 2014 - 5:10pm #22

Hi,

I am  developing a mix of Frame Markers and VideoPlayback. i have created four markers. 

Initially the first marker show  the letterQ model 3D like in the Frame markers sample and in the second marker show a video inside the marker.

The video play correctly in the marker and the model 3D is shown correctly too.

My problem is in method isTapOnScreenInsideTarget because when a motion event occurs in the second marker, the video run but when a motion event occurs in first marker anything occurs ( I have created an intent in first marker in order to when a motion event occurs open a web page).  The variable intersection don't work fine.

i am very confused what i need to use in order to intersection in normal frame marker an the motion event work fine.

 

Thanks!!

how can we give touch event on 2d image which comes after detect

March 23, 2013 - 1:18am #21

you're welcome

how can we give touch event on 2d image which comes after detect

March 22, 2013 - 7:11pm #20

hj  AlessandroB.

I fixed this error!

Thank you very much!

how can we give touch event on 2d image which comes after detect

March 22, 2013 - 11:56am #19

Hi congthien,

you have commented this line:

 

//mGestureDetector = new GestureDetector(this, new GestureListener());
        
so, you get a null pointer exception when you add your listener because since mGestureDetector is null.
 

how can we give touch event on 2d image which comes after detect

March 22, 2013 - 9:59am #18

Hj all.

I receive error when i add event to code:

 

 protected void onCreate(Bundle savedInstanceState)
    {
        DebugLog.LOGD("ImageTargets::onCreate");
        super.onCreate(savedInstanceState);
 
        // Load any sample specific textures:
        mTextures = new Vector<Texture>();
        loadTextures();
 
        // Query the QCAR initialization flags:
        mQCARFlags = getInitializationFlags();
 
        // Creates the GestureDetector listener for processing double tap
        //mGestureDetector = new GestureDetector(this, new GestureListener());
        
        // Update the application status to start initializing application:
        updateApplicationStatus(APPSTATUS_INIT_APP);
        
       mGestureDetector.setOnDoubleTapListener(new OnDoubleTapListener() {
 
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
 
public boolean onDoubleTapEvent(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
 
public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
});

 

ERROR:

 

03-22 23:49:20.631: ERROR/AndroidRuntime(561): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.qualcomm.QCARSamples.ImageTargets/com.qualcomm.QCARSamples.ImageTargets.ImageTargets}: java.lang.NullPointerException
 
Help me.
Thanks all.
 

how can we give touch event on 2d image which comes after detect

March 22, 2013 - 3:12am #17

ok, so now you have a compile error.What is the code where you get this error ?

(can you share a snippet ?)

how can we give touch event on 2d image which comes after detect

March 22, 2013 - 12:45am #16

Now i am geting the error as

request for member 'data' in 'modelViewMatri,  which is of non-class type 'QCAR::Matrix44F [3].

while i am compiling the cpp file.

 

 

how can we give touch event on 2d image which comes after detect

March 21, 2013 - 6:22am #15

Well, normally the 1st image would have index "0", the second image index "1"; have you tried with index 0 ?

 

how can we give touch event on 2d image which comes after detect

March 21, 2013 - 4:56am #14

yes although i have given index 1, but i am testing for 1th image.i also tested for all images

how can we give touch event on 2d image which comes after detect

March 21, 2013 - 3:54am #13

Ok, looking at your code:

if (isTapOnScreenInsideTarget(1, e.getX(), e.getY()))
            {
            System.out.println("Touched for new screen");
            Intent i=new Intent(ImageTargets.this,NextScreen.class);
            startActivity(i);
            }

Why are you passing "1" as first paramater (and not "0" for instance) ? are you sure that it correspond to the right target index ?

how can we give touch event on 2d image which comes after detect

March 21, 2013 - 3:41am #12

yes this is my java file,

-------------------------------------------------------------------------------------

    protected void onCreate(Bundle savedInstanceState)
    {
     
        super.onCreate(savedInstanceState);

        mTextures = new Vector<Texture>();
        loadTextures();
        mQCARFlags = getInitializationFlags();
        updateApplicationStatus(APPSTATUS_INIT_APP);
        mSimpleListener = new SimpleOnGestureListener();
        mGestureDetector = new GestureDetector(getApplicationContext(), mSimpleListener);
        mGestureDetector.setOnDoubleTapListener(new OnDoubleTapListener()
        {

            public boolean onDoubleTap(MotionEvent e)
            {
               
                 System.out.println("Hello double tap");
                 if (isTapOnScreenInsideTarget(1, e.getX(), e.getY()))
                 {
                 System.out.println("Touched for new screen");
                 Intent i=new Intent(ImageTargets.this,NextScreen.class);
                 startActivity(i);
                 }
                 else
                 {
                     System.out.println("Else touched");
                 }
                 return true;
            }

            public boolean onDoubleTapEvent(MotionEvent e)
            {
            return false;
            }

            
            /** Handle the single tap */
            public boolean onSingleTapConfirmed(MotionEvent e)
            {
            //System.out.println("Single tap it is confirmed");
            System.out.println("X Coordinate: "+e.getX());
            System.out.println("Y Coordinate: "+e.getY());
            if (isTapOnScreenInsideTarget(1, e.getX(), e.getY()))
            {
            System.out.println("Touched for new screen");
            Intent i=new Intent(ImageTargets.this,NextScreen.class);
            startActivity(i);
            }
            return true;
            }
        });
        /////////////////////////////////////////////////////////////////////////////////////////////

    }

 

 

 

 

how can we give touch event on 2d image which comes after detect

March 21, 2013 - 1:00am #11

Can you share the Java code from which you call that native function ?

 

how can we give touch event on 2d image which comes after detect

March 20, 2013 - 11:49pm #10

Hi,

Sorry i was confused actually isTapOnScreenInsideTarget always returing false value..am i mistaking in computing touch point of image after detecting the target image. ?

how can we give touch event on 2d image which comes after detect

March 20, 2013 - 6:11am #9

So, you are saying that the isTapOnScreenInsideTarget always return true ?

This could be due to many reasons:

  1. do you compute the inverseProjMatrix in your VideoPlayback.cpp code (like in the original VP sample) ?
  2. do you compute the targetPositiveDimensions (like in the original VP sample) ?

how can we give touch event on 2d image which comes after detect

March 20, 2013 - 5:16am #8

Hi, I got the touch event but the touch is for whole screen, wherever i touch the screen, it takes action.

But i want the touch event only for the image which appears after image detection.Means if i touch then ontapconfirmed action should happen.

here is my cpp method for action. Please tell me what i am missing.?

JNIEXPORT bool JNICALL
Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlayback_isTapOnScreenInsideTarget(JNIEnv *env, jobject, jint target, jfloat x, jfloat y)
{
    //LOG("Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlayback_isTapOnScreenInsideTarget");
    // Here we calculate that the touch event is inside the target
    QCAR::Vec3F intersection, lineStart, lineEnd;

    SampleMath::projectScreenPointToPlane(inverseProjMatrix, modelViewMatrix[target], screenWidth, screenHeight,
                              QCAR::Vec2F(x, y), QCAR::Vec3F(0, 0, 0), QCAR::Vec3F(0, 0, 1), intersection, lineStart, lineEnd);

    // The target returns as pose the center of the trackable. The following if-statement simply checks that the tap is within this range
    if ( (intersection.data[0] >= -(targetPositiveDimensions[target].data[0])) && (intersection.data[0] <= (targetPositiveDimensions[target].data[0])) &&
         (intersection.data[1] >= -(targetPositiveDimensions[target].data[1])) && (intersection.data[1] <= (targetPositiveDimensions[target].data[1])))
        return true;
    else
        return false;
}
 

how can we give touch event on 2d image which comes after detect

March 20, 2013 - 3:10am #7

It was great help of you for me, thanks, for rest i will let you know

how can we give touch event on 2d image which comes after detect

March 20, 2013 - 2:58am #6

From the error it looks like if you have not added this line in ImageTargets.cpp:

  #include "SampleMath.h"

(also, just to be sure, you need to have SampleMath.cpp in Android.mk, like here below:

LOCAL_SRC_FILES := VideoPlayback.cpp SampleUtils.cpp Texture.cpp SampleMath.cpp)

Can you confirm the above ?

 

how can we give touch event on 2d image which comes after detect

March 20, 2013 - 1:56am #5

yes i have included samplemath.cpp and samplemath.h.

how can we give touch event on 2d image which comes after detect

March 19, 2013 - 2:43am #4

Have you included the SampleMath.h header ?

 

how can we give touch event on 2d image which comes after detect

March 15, 2013 - 3:31am #3

i followed the things from videoplayback sample and included  samplemath.cpp and samplemath.m.but i got the error as

C:\Developement\adt-bundle-windows\vuforia-sdk-android-2-0-29\samples\ImageTarge
ts-2-0-7>C:\Developement\adt-bundle-windows\android-ndk-r8c\ndk-build
"Compile++ arm  : ImageTargets <= ImageTargets.cpp
"Compile++ arm  : ImageTargets <= SampleUtils.cpp
StaticLibrary  : libstdc++.a
Prebuilt       : libQCAR.so <= jni/../../../build/lib/armeabi/
SharedLibrary  : libImageTargets.so
c:/developement/adt-bundle-windows/android-ndk-r8c/toolchains/arm-linux-androide
abi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../ar
m-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/ImageTargets/ImageTarge
ts.o: in function Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlayback_setP
rojectionMatrix:jni/ImageTargets.cpp:345: error: undefined reference to 'SampleM
ath::Matrix44FInverse(QCAR::Matrix44F&)'
c:/developement/adt-bundle-windows/android-ndk-r8c/toolchains/arm-linux-androide
abi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../ar
m-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/ImageTargets/ImageTarge
ts.o: in function Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlayback_isTa
pOnScreenInsideTarget:jni/ImageTargets.cpp:356: error: undefined reference to 'S
ampleMath::projectScreenPointToPlane(QCAR::Matrix44F, QCAR::Matrix44F, float, fl
oat, QCAR::Vec2F, QCAR::Vec3F, QCAR::Vec3F, QCAR::Vec3F&, QCAR::Vec3F&, QCAR::Ve
c3F&)'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libImageTargets.so] Error 1

---------------------------------------------------------------------------------------------------------------------------------------------

how can we give touch event on 2d image which comes after detect

March 15, 2013 - 12:44am #2

Hi,

if you look at the VideoPlayback sample you can find some code that should allow you to achieve that effect; in VideoPlayback.cpp you see this function:

JNIEXPORT bool JNICALL
Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlayback_isTapOnScreenInsideTarget(JNIEnv *env, jobject, jint target, jfloat x, jfloat y)
{
      // Here we calculate that the touch event is inside the target
    QCAR::Vec3F intersection, lineStart, lineEnd;

    SampleMath::projectScreenPointToPlane(inverseProjMatrix, modelViewMatrix[target], screenWidth, screenHeight,
                              QCAR::Vec2F(x, y), QCAR::Vec3F(0, 0, 0), QCAR::Vec3F(0, 0, 1), intersection, lineStart, lineEnd);

    // The target returns as pose the center of the trackable. The following if-statement simply checks that the tap is within this range
    if ( (intersection.data[0] >= -(targetPositiveDimensions[target].data[0])) && (intersection.data[0] <= (targetPositiveDimensions[target].data[0])) &&
         (intersection.data[1] >= -(targetPositiveDimensions[target].data[1])) && (intersection.data[1] <= (targetPositiveDimensions[target].data[1])))
        return true;
    else
        return false;
}

You can basically reuse that code (by passing your touch screen coordinates) to compute the coordinates on the target reference frame, for instance:

float posXInTargetRef = intersection.data[0] / targetPositiveDimensions[target].data[0];// range is [-1, 1]
float posYInTargetRef = intersection.data[1] / targetPositiveDimensions[target].data[1];// range is [-1, 1]

 

 

Log in or register to post comments