1 #include <iostream>
2 #define _MSVC
3 #include <chai3d.h>
4
5 // a haptic device handler
6 cHapticDeviceHandler* handler;
7
8 // a pointer to a haptic device
9 cGenericHapticDevice* hapticDevice;
10
11 // haptic device info
12 cHapticDeviceInfo info;
13
14 // number of haptic devices
15 int numHapticDevices;
16
17 // last position of haptic device
18 cVector3d position;
19
20 // button status of the haptic device
21 bool buttonStatus = false;
22
23 int main(void)
24 {
25 handler = new cHapticDeviceHandler();
26
27 // read the number of haptic devices currently connected to the computer
28 numHapticDevices = handler->getNumDevices();
29 std::cout << "Chai3d: getNumDevices = " << numHapticDevices << std::endl;
30
31 if (numHapticDevices > 0)
32 {
33 std::cout << "Chai3d: using hatpic device #0" << std::endl;
34 handler->getDevice(hapticDevice, 0);
35
36 // open connection to haptic device
37 std::cout << "Chai3d: open device" << std::endl;
38 hapticDevice->open();
39
40 // initialize haptic device
41 std::cout << "Chai3d: init device" << std::endl;
42 hapticDevice->initialize();
43
44 // retrieve information about the current haptic device
45 info = hapticDevice->getSpecifications();
46 std::cout << "Chai3d: " << info.m_manufacturerName << " " << info.m_modelName << std::endl;
47
48 std::cout << "Press any button on the haptic device to exit." << std::endl;
49
50 // infinite loop reading position from haptic device
51 while (!buttonStatus)
52 {
53 cVector3d newPosition;
54
55 hapticDevice->getPosition(newPosition);
56
57 // update button status from all 4 buttons
58 hapticDevice->getUserSwitch(0, buttonStatus);
59 if (!buttonStatus) hapticDevice->getUserSwitch(1, buttonStatus);
60 if (!buttonStatus) hapticDevice->getUserSwitch(2, buttonStatus);
61 if (!buttonStatus) hapticDevice->getUserSwitch(3, buttonStatus);
62
63 // do not print the same position
64 if (!newPosition.equals(position))
65 {
66 position = newPosition;
67 std::cout << position << std::endl;
68 }
69 }
70 }
71
72 return 0;
73 }