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

MobileTracker.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: MobileTracker.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.4 $        $Date: 2019/01/17 21:21:00 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   Listen for UDP packets from WiFi mobile input devices such 
00019  *   as smartphones, tablets, etc.
00020  *
00021  ***************************************************************************/
00022 #include <stdlib.h> // for getenv(), abs() etc.
00023 #include <string.h>
00024 #include <math.h>
00025 #include "VMDApp.h"
00026 #include "MobileTracker.h"
00027 #include "Matrix4.h"
00028 #include "Inform.h"
00029 #include "utilities.h"
00030 
00031 MobileTracker::MobileTracker(VMDApp *vmdapp) {
00032   app = vmdapp; // copy VMDApp pointer for use in accessing local spaceball
00033 }
00034 
00035 int MobileTracker::do_start(const SensorConfig *config) {
00036   if (!config->require_local()) return 0;
00037   if (!config->have_one_sensor()) return 0;
00038 
00039   char *myUSL = stringdup(config->getname());
00040 
00041 printf("Mobile USL: '%s'\n", myUSL);
00042   
00043   // set the default translation and rotation increments
00044   // these really need to be made user modifiable at runtime
00045   transInc = 1.0f;
00046     rotInc = 0.01f;
00047   scaleInc = 1.0f;
00048 
00049   // reset the position
00050   moveto(0,0,0);
00051   orient->identity();
00052 
00053   delete [] myUSL;
00054 
00055   return TRUE;
00056 }
00057 
00058 MobileTracker::~MobileTracker(void) {
00059 }
00060 
00061 void MobileTracker::update() {
00062   Matrix4 temp;
00063 
00064   if(!alive()) {
00065     moveto(0,0,0);
00066     orient->identity();
00067     return;
00068   }
00069 
00070   if (app != NULL ) {
00071     float tx, ty, tz, rx, ry, rz;
00072     tx=ty=tz=rx=ry=rz=0.0f;
00073     int buttons=0;
00074 
00075 printf("polling mobile status socket..\n");
00076     app->mobile_get_tracker_status(tx, ty, tz, rx, ry, rz, buttons);
00077 
00078     temp.identity();
00079     temp.rot( ((float)rx)*rotInc, 'x' );
00080     temp.rot( ((float)ry)*rotInc, 'y' );
00081     temp.rot( ((float)rz)*rotInc, 'z' );
00082     temp.multmatrix(*orient);
00083     orient->loadmatrix(temp);
00084     pos[0] += tx * transInc;
00085     pos[1] += ty * transInc;
00086     pos[2] +=-tz * transInc;
00087   }
00088 }
00089 

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