1 /**************************************************************************** 2 * VCGLib o o * 3 * Visual and Computer Graphics Library o o * 4 * _ O _ * 5 * Copyright(C) 2004-2016 \/)\/ * 6 * Visual Computing Lab /\/| * 7 * ISTI - Italian National Research Council | * 8 * \ * 9 * All rights reserved. * 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 * This program is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 20 * for more details. * 21 * * 22 ****************************************************************************/ 23 /**************************************************************************** 24 History 25 26 $Log: not supported by cvs2svn $ 27 Revision 1.1 2005/04/14 21:23:39 ganovelli 28 *** empty log message *** 29 30 31 32 ****************************************************************************/ 33 #ifndef VCGLIB_TRACKRECORDER 34 #define VCGLIB_TRACKRECORDER 35 36 37 #include <wrap/gui/trackball.h> 38 #include <stdio.h> 39 #include <time.h> 40 41 namespace vcg{ 42 struct TrackRecorder{ 43 TrackRecorderTrackRecorder44 TrackRecorder(){Stop();} 45 46 FILE * trackfile; 47 48 enum { PLAY,REC,OFF } mode; 49 int nextTime, 50 startTime; 51 StartPlayingTrackRecorder52 void StartPlaying(char * namefile){ 53 if(trackfile != NULL) return; 54 55 trackfile = fopen(namefile,"rb"); 56 startTime = clock(); 57 mode = PLAY; 58 fread(&nextTime,4,1,trackfile); 59 } 60 UpdateTrackballTrackRecorder61 void UpdateTrackball(Trackball & t){ 62 63 while( ( clock()-startTime > nextTime)&& !feof(trackfile)){ 64 fread(&t.track,sizeof(float)*4 + sizeof(float)*5,1,trackfile); 65 fread(&nextTime,4,1,trackfile); 66 } 67 if(feof(trackfile)) 68 Stop(); 69 } 70 StartRecordingTrackRecorder71 void StartRecording(char * namefile){ 72 if(trackfile != NULL) return; 73 trackfile = fopen(namefile,"wb"); 74 startTime = clock(); 75 mode = REC; 76 } 77 RecordTrackballTrackRecorder78 void RecordTrackball(Trackball & t){ 79 nextTime = clock()-startTime; 80 fwrite(&nextTime,4,1,trackfile); 81 fwrite(&t.track,sizeof(float)*4 + sizeof(float)*5,1,trackfile); 82 } 83 StopTrackRecorder84 void Stop(){mode = OFF; trackfile = NULL;}; 85 86 }; 87 } 88 #endif