Debian Codegraph @

vcg/wrap/gui/trackrecorder.h

raw symbols SCIP
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004 \/)\/ *
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: trackrecorder.h,v $
27 Revision 1.2 2005/04/14 21:29:03 ganovelli
28 "void" added
29
30 Revision 1.1 2005/04/14 21:23:39 ganovelli
31 *** empty log message ***
32
33
34
35 ****************************************************************************/
36 #ifndef VCGLIB_TRACKRECORDER
37 #define VCGLIB_TRACKRECORDER
38
39
40 #include <wrap/gui/trackball.h>
41 #include <stdio.h>
42 #include <time.h>
43
44 namespace vcg{
45 struct TrackRecorder{
46
47 TrackRecorder(){Stop();}
48
49 FILE * trackfile;
50
51 enum { PLAY,REC,OFF } mode;
52 int nextTime,
53 startTime;
54
55 void StartPlaying(char * namefile){
56 if(trackfile != NULL) return;
57
58 trackfile = fopen(namefile,"rb");
59 startTime = clock();
60 mode = PLAY;
61 fread(&nextTime,4,1,trackfile);
62 }
63
64 void UpdateTrackball(Trackball & t){
65
66 while( ( clock()-startTime > nextTime)&& !feof(trackfile)){
67 fread(&t.track,sizeof(float)*4 + sizeof(float)*5,1,trackfile);
68 fread(&nextTime,4,1,trackfile);
69 }
70 if(feof(trackfile))
71 Stop();
72 }
73
74 void StartRecording(char * namefile){
75 if(trackfile != NULL) return;
76 trackfile = fopen(namefile,"wb");
77 startTime = clock();
78 mode = REC;
79 }
80
81 void RecordTrackball(Trackball & t){
82 nextTime = clock()-startTime;
83 fwrite(&nextTime,4,1,trackfile);
84 fwrite(&t.track,sizeof(float)*4 + sizeof(float)*5,1,trackfile);
85 }
86
87 void Stop(){mode = OFF; trackfile = NULL;};
88
89 };
90 }
91 #endif