00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if defined(VMDPHONETRACKER)
00023
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <math.h>
00027 #include "VMDApp.h"
00028 #include "PhoneTracker.h"
00029 #include "Matrix4.h"
00030 #include "Inform.h"
00031 #include "utilities.h"
00032
00033
00034 #include <stdio.h>
00035 #include <arpa/inet.h>
00036 #include <fcntl.h>
00037 #include <sys/types.h>
00038 #include <unistd.h>
00039 #include <sys/socket.h>
00040 #include <time.h>
00041 #include <netinet/in.h>
00042
00043 PhoneTracker::PhoneTracker(VMDApp *vmdapp) {
00044 app = vmdapp;
00045 }
00046
00047 int PhoneTracker::do_start(const SensorConfig *config) {
00048 if (!config->require_local()) return 0;
00049 if (!config->have_one_sensor()) return 0;
00050
00051 char *myUSL = stringdup(config->getname());
00052
00053 printf("Phone USL: '%s'\n", myUSL);
00054
00055
00056
00057 transInc = 1.0f;
00058 rotInc = 0.01f;
00059 scaleInc = 1.0f;
00060
00061
00062 moveto(0,0,0);
00063 orient->identity();
00064
00065 delete [] myUSL;
00066
00067 return TRUE;
00068 }
00069
00070 PhoneTracker::~PhoneTracker(void) {
00071 }
00072
00073 void PhoneTracker::update() {
00074 Matrix4 temp;
00075
00076 if(!alive()) {
00077 moveto(0,0,0);
00078 orient->identity();
00079 return;
00080 }
00081
00082 if (app != NULL ) {
00083 float tx, ty, tz, rx, ry, rz;
00084 tx=ty=tz=rx=ry=rz=0.0f;
00085 int buttons=0;
00086
00087 printf("polling mobile status socket..\n");
00088 app->mobile_get_tracker_status(tx, ty, tz, rx, ry, rz, buttons);
00089
00090 temp.identity();
00091 temp.rot( ((float)rx)*rotInc, 'x' );
00092 temp.rot( ((float)ry)*rotInc, 'y' );
00093 temp.rot( ((float)rz)*rotInc, 'z' );
00094 temp.multmatrix(*orient);
00095 orient->loadmatrix(temp);
00096 pos[0] += tx * transInc;
00097 pos[1] += ty * transInc;
00098 pos[2] +=-tz * transInc;
00099 }
00100 }
00101
00102 #endif