Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

P_VRPNTracker.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: P_VRPNTracker.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.29 $       $Date: 2019/01/17 21:21:01 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  * This is Paul's new Tracker code -- pgrayson@ks.uiuc.edu
00019  *
00020  *
00021  ***************************************************************************/
00022 
00023 #if defined(VMDVRPN)
00024 
00025 #include "P_VRPNTracker.h"
00026 
00027 #include "quat.h"
00028 #include "Matrix4.h"
00029 #include "utilities.h"
00030 
00031 /* Newer revs of VRPN require a calling convention macro */
00032 #if !defined(VRPN_CALLBACK)
00033 #define VRPN_CALLBACK
00034 #endif
00035 
00036 
00037 static void VRPN_CALLBACK handle_vrpn_tracker(void *userdata, const vrpn_TRACKERCB t) {
00038   VRPNTrackerUserData *data = (VRPNTrackerUserData *)userdata;
00039 
00040   data->pos[0] = (float) t.pos[0];
00041   data->pos[1] = (float) t.pos[1];
00042   data->pos[2] = (float) t.pos[2];
00043 
00044   double q[4]; /* we need to swap X and Z to make it work right */
00045   q[0] = -t.quat[Q_Z];
00046   q[1] =  t.quat[Q_Y];
00047   q[2] =  t.quat[Q_X];
00048   q[3] =  t.quat[Q_W];
00049 
00050   double rotation[16];
00051   Matrix4 *orient = data->orient;
00052   int i;
00053   q_to_ogl_matrix(rotation, q);
00054   for(i=0;i<4;i++) orient->mat[4*0+i]=(float)rotation[i];
00055   for(i=0;i<4;i++) orient->mat[4*1+i]=(float)rotation[i+4];
00056   for(i=0;i<4;i++) orient->mat[4*2+i]=(float)rotation[i+8];
00057   for(i=0;i<4;i++) orient->mat[4*3+i]=(float)rotation[i+12];
00058 }
00059 
00060 VRPNTracker::VRPNTracker() {
00061   tkr = NULL;
00062 
00063   // set userdata to point to parent class data 
00064   userdata.pos = pos;
00065   userdata.orient = orient;
00066 }
00067 
00068 int VRPNTracker::do_start(const SensorConfig *config) {
00069   if (tkr) return 0;
00070   if (!config->have_one_sensor()) return 0;
00071 
00072   char myUSL[100];
00073   config->make_vrpn_address(myUSL);
00074   int mysensor = (*config->getsensors())[0];
00075 
00076   // create new tracker connection
00077   tkr = new vrpn_Tracker_Remote(myUSL);
00078 
00079   // register callback for position and orientation updates
00080   tkr->register_change_handler(&userdata, handle_vrpn_tracker, 
00081                                mysensor);
00082   return 1;
00083 }
00084 
00085 VRPNTracker::~VRPNTracker(void) {
00086   delete tkr;
00087 }
00088 
00089 void VRPNTracker::update() {
00090 
00091   if(!alive()) { // insert hack here to fix VRPN's connection bug someday
00092     moveto(0,0,0);
00093     orient->identity();
00094     return;
00095   }
00096   tkr->mainloop(); // clear out old data
00097 }
00098 
00099 #endif
00100 
00101 

Generated on Fri Oct 11 02:44:28 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002