Space Navigator and VRPN - Simple Example Code

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
yoursort
Posts: 4
Joined: Mon Dec 10, 2007 8:41 am

Space Navigator and VRPN - Simple Example Code

Post by yoursort »

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:

The Server:

Code: Select all

// 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
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Hi,

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.

Thanks.
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Hi,

The example of client side do not compile! The compiler shows some errors of compilation...
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

The condition of command "for" is not wrong? I think is missing something...
jwar8
Posts: 1
Joined: Wed Aug 13, 2008 10:40 am

Space Navigator and VRPN - Simple Example Code

Post by jwar8 »

This is exactly what I have been looking for. However, the code appears to have been chopped, could you either repost or add attachment.

Thanks in advance
yoursort
Posts: 4
Joined: Mon Dec 10, 2007 8:41 am

The code aagain

Post by yoursort »

So because it seems my code from the first post is lost here it is again (i post it in normal text because the code-markup works not right):

// SpaceNavigatorServer.cpp
// A small example server for the 3D-Connexion Space Navigator
//
// Author: Lars Bilke

#include <vrpn_3DConnexion>

vrpn_Connection *connection;
vrpn_3DConnexion_Navigator *nav;

void shutdown()
{
if(connection) {connection->removeReference(); connection = NULL; }
}

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

// Author: Lars Bilke

#include "vrpn_Button.h"
#include "vrpn_Analog.h"

// Button callback
void CALLBACK handleButtons(void *, vrpn_BUTTONCB buttonData)
{
printf("Button: %d, Button state: %d\n\n", buttonData.button, buttonData.state);
}

// 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();
}
}
yoursort
Posts: 4
Joined: Mon Dec 10, 2007 8:41 am

Post by yoursort »

Sorry but the code is not inserted correct in this forum. I don´t know why so here is the download to a textfile:
http://rapidshare.com/files/157059949/V ... e.txt.html
Post Reply