Stylus intersect display

I am using the command zcIntersectDisplay to get the position where the stylus intersect the display, so that I can draw a sphere at its point of intersection. However the command always returns that there is no interaction.
I have called zcCreateStereoBuffer during initialisation and zcBeginStereoBufferFrame before each display. What else have I missd out?

Ng Hern

zcIntersectDisplay appears to work fine for me. Here’s an example.

#include <iostream>

#include <Windows.h>
#include <zSpace.h>


//////////////////////////////////////////////////////////////////////////
// Macros
//////////////////////////////////////////////////////////////////////////

#define CHECK_ERROR(error)                                          \
    if (error != ZC_ERROR_OK)                                       \
    {                                                               \
        char errorString[256];                                      \
        zcGetErrorString(error, errorString, sizeof(errorString));  \
        printf("%s\n", errorString);                                \
        return -1;                                                  \
    }

//////////////////////////////////////////////////////////////////////////
// Main
//////////////////////////////////////////////////////////////////////////

int main(int argc, char* argv[])
{
    printf("Press ESC to exit...\n");

    // Initialize zSpace.
    ZCContext zSpaceContext = NULL;
    ZCError   error = zcInitialize(&zSpaceContext);
    CHECK_ERROR(error);

    // Get the stylus target.
    ZCHandle stylusHandle = NULL;
    error = zcGetTargetByType(zSpaceContext, ZC_TARGET_TYPE_PRIMARY, 0, &stylusHandle);
    CHECK_ERROR(error);

	ZCHandle displayHandle = NULL;
	error = zcGetDisplayByType(zSpaceContext, ZC_DISPLAY_TYPE_ZSPACE, 0, &displayHandle);
    CHECK_ERROR(error);

    // Run until escape is pressed.
    int isEscapePressed = 0;
    while (!isEscapePressed)
    {
		// Update zSpace.
		zcUpdate(zSpaceContext);

		ZCTrackerPose stylusPose;
		error = zcGetTargetPose(stylusHandle, &stylusPose);
		CHECK_ERROR(error);

		ZCDisplayIntersectionInfo intersectInfo;
		error = zcIntersectDisplay(displayHandle, &stylusPose, &intersectInfo);
		CHECK_ERROR(error);

		printf("Intersected: %d, %d\n", intersectInfo.x, intersectInfo.y);

#ifdef _WIN32
        if (GetConsoleWindow() == GetForegroundWindow())
        {
            isEscapePressed = (GetAsyncKeyState(VK_ESCAPE) & 0x8000);
        }
#endif
    }

    // Shutdown zSpace.
    error = zcShutDown(zSpaceContext);
    CHECK_ERROR(error);

    return 0;
}
1 Like

Thanks Alex. That helps a lot. I have misinterpreted “display” as my 3D rendering, whereas it is referring to the monitor screen.