Hi,
because there is no simple example for using the Space Navigator with VRPN over a network and there is no clear and simple example or tutorial about VRPN at all I post these two little programs:
// SpaceNavigatorServer.cpp
// A small example server for the 3D-Connexion Space Navigator
//
// Author: Lars Bilke
#include <vrpn_3DConnexion>
bool exiting = false;
vrpn_Connection *connection;
vrpn_3DConnexion_Navigator *nav;
static char * g_NICname = NULL;
void shutdown()
{
if(connection) {connection->removeReference(); connection = NULL; }
}
int main()
{
// values of 1.0 or higher lead to wrong outputs
double milli_sleep_time = 0.9;
int port = vrpn_DEFAULT_LISTEN_PORT_NO;
connection = new vrpn_Connection(port);
// Create new Navigator device object
// The name has to be used by the client application
if((nav = new vrpn_3DConnexion_Navigator("yourName@yourComputer", connection)) == NULL)
{
printf("Can
What kind of variable this code returns? Is returns some kind of event like "ea.getEventType()" which can be read by "osgGA::GUIEventAdapter::FRAME"???
Please, I still remain confused about example provided.
int main(int argc, char **argv)
{
// get connection string from command line argument
// Form: yourName@yourComputer
char *computerName = "";
if(argc > 1)
{
computerName = argv[1];
}
// values of 1.0 or higher lead to wrong outputs
double milli_sleep_time = 0.9;
int port = vrpn_DEFAULT_LISTEN_PORT_NO;
connection = new vrpn_Connection(port);
// Create new Navigator device object
// The name has to be used by the client application
if((nav = new vrpn_3DConnexion_Navigator(computerName, connection)) == NULL)
{
printf("Can´t create new device\n");
return -1;
}
// run the mainloops
while (true)
{
nav->mainloop();
connection->mainloop();
if(!connection->doing_okay())
shutdown();
// Sleep so we don't eat the CPU
if (milli_sleep_time >= 0.0)
vrpn_SleepMsecs(milli_sleep_time);
}
shutdown();
return 0;
}
The client code:
// A small example for client code which connects to a 3DConnexion Space Navigator
// Analog axes callback
void CALLBACK handleAnalogs(void *, vrpn_ANALOGCB analogData)
{
for(int i = 0; i <analogData>register_change_handler(NULL, (vrpn_BUTTONCHANGEHANDLER)handleButtons);
// Create new analog_remote object that connects to the corresponding server object
// at the specified computer and register the callback function
vrpn_Analog_Remote *analog = new vrpn_Analog_Remote(yourName@yourComputer);
analog->register_change_handler(NULL, (vrpn_ANALOGCHANGEHANDLER)handleAnalogs);
// run the mainloops
while (1)
{
button->mainloop();
analog->mainloop();
}
}