OpenHaptics를 사용하기 HIP위치 정보 얻어오기
- 개발관련팁
- 2007. 3. 5.
샘플 코드
#include <stdio.h>
#include <assert.h>
#if defined(WIN32)
# include <conio.h>
#else
# include "conio.h"
#endif
#include <HD/hd.h>
#include <HL/hl.h>
#include <HDU/hduError.h>
int main(int argc, char *argv[])
{
HHD hHD;
HHLRC hHLRC;
HDErrorInfo error;
HLerror frameError;
double proxyPos[3];
hHD = hdInitDevice(HD_DEFAULT_DEVICE);
if (HD_DEVICE_ERROR(error = hdGetError()))
{
hduPrintError(stderr, &error, "Failed to initialize haptic device");
fprintf(stderr, "\nPress any key to quit.\n");
getch();
return -1;
}
hdMakeCurrentDevice(hHD);
hHLRC = hlCreateContext(hHD);
hlMakeCurrent(hHLRC);
hlDisable(HL_USE_GL_MODELVIEW);
/* Run the main loop. */
while (!_kbhit())
{
hlBeginFrame();
hlGetDoublev(HL_PROXY_POSITION, proxyPos);
printf("%f %f %f\n", proxyPos[0], proxyPos[1], proxyPos[2]);
hlEndFrame();
/* Check for any errors. */
while (HL_ERROR(frameError = hlGetError()))
{
fprintf(stderr, "HL Error: %s\n", frameError.errorCode);
if (frameError.errorCode == HL_DEVICE_ERROR)
{
hduPrintError(stderr, &frameError.errorInfo,
"Error during haptic rendering\n");
}
}
}
hlDeleteContext(hHLRC);
hdDisableDevice(hHD);
return 0;
}