Log in or register to post comments

How to Check Object Intersection

August 10, 2012 - 6:29pm #1

I want to check intersection with drawn object when screen is tapped? My object is a 2D plane. I tried to use Dominos example; however, it was too compicated to solve for me. I can check intersection with all trackable but I want to check intersection with drawn panel. I want to use it like a button on trackable.


My Plane.h file;


const float PLANE_SIZE = 30.0f;

static const float shapeVertices[NUM_SHAPE_OBJECT_VERTEX * 3] =

static const float shapeTexCoords[NUM_SHAPE_OBJECT_VERTEX * 3] =

    0.0f, 1.0f,
    1.0f, 1.0f,
    1.0f, 0.0f,
    0.0f, 0.0f,
    0.0f, 0.0f

static const float shapeNormals[NUM_SHAPE_OBJECT_VERTEX * 3] =
    0.0f, 0.0f, PLANE_SIZE, 
    0.0f, 0.0f, PLANE_SIZE, 
    0.0f, 0.0f, PLANE_SIZE, 
    0.0f, 0.0f, PLANE_SIZE,  
    0.0f, 0.0f, PLANE_SIZE

static const unsigned short shapeIndices[NUM_SHAPE_OBJECT_INDEX] =



My code for checking intersection;

if (tap)
                QCAR::Vec3F intersection, lineStart, lineEnd;
                projectScreenPointToPlane(QCAR::Vec2F(tapX, tapY), QCAR::Vec3F(0, 0, 0), QCAR::Vec3F(0, 0, 1), intersection, lineStart, lineEnd);

                const QCAR::ImageTarget* imageTarget = static_cast<const QCAR::ImageTarget*>(trackable);
                QCAR::Vec2F trackableSize = imageTarget->getSize();

                LOG("tap coordinates (screen space): %.2f, %.2f", tapX, tapY);
                LOG("tap coordinates (target space): %.2f, %.2f", intersection.data[0], intersection.data[1]);
                LOG("trackable size (width, height): %.2f, %.2f", trackableSize.data[0], trackableSize.data[1]);

                float planeSize = 30.0f; // x-y
                float trackableWidth = trackableSize.data[0]; //A
                float trackableHeight = trackableSize.data[1]; //B
                float a = (trackableWidth + planeSize)/2; //bottom right corner x-axis
                float b = (trackableHeight + planeSize)/2; //bottom right corner y-axis
                float c = (trackableHeight - planeSize)/2; //top left corner y-axis
                float d = (trackableWidth - planeSize)/2; //top left corner x-axis

                float intersectionX = intersection.data[0];
                float intersectionY = intersection.data[1];

                LOG("a: %.2f, b: %.2f, c: %.2f, d: %.2f, intersectionX: %.2f, intersectionY: %.2f", a,b,c,d, intersectionX,intersectionY);

                if( intersectionX < a && intersectionX > d && intersectionY < b && intersectionY > c) {
                    LOG("Tapped Target, id: %d | name: %s", trackable->getId(), trackable->getName());

                tap = false;

How to Check Object Intersection

May 13, 2016 - 3:27am #2


Any update on this thread?

Log in or register to post comments