-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrameSequence.cpp
64 lines (53 loc) · 1.3 KB
/
FrameSequence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "FrameSequence.h"
#ifdef WIN32
#include <windows.h>
#endif
#ifdef __mac
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#ifdef __debug
#include <assert.h>
#endif
#include <math.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
using namespace std; // Wince
#include "Frame.h"
FrameSequence::FrameSequence(const char *filename) : currentFrame_(0) {
ifstream fp(filename);
if (!fp.is_open()) {
cerr << "File " << filename << " could not be opened." << endl;
exit(-1);
}
const int kNumCharsToIgnoreOnComment = 65536;
while(!fp.eof()) {
if (fp.peek() == SEQUENCE_FILE_COMMENT_CHARACTER)
fp.ignore(kNumCharsToIgnoreOnComment, '\n');
frames_.push_back(new Frame(&fp));
}
fp.close();
}
FrameSequence::~FrameSequence() {
}
void FrameSequence::nextFrame() {
currentFrame_ = (currentFrame_ + 1) % frames_.size();
}
const Frame& FrameSequence::getCurrentFrame() const {
return *(frames_[currentFrame_]);
}
void FrameSequence::fastForwardTo(unsigned long t) {
unsigned int index;
for (index = 0; index < frames_.size(); index++) {
if (frames_[index]->getTimeInMS() > t)
break;
}
currentFrame_ = index % frames_.size();
}
unsigned int FrameSequence::getNumFrames() const {
return frames_.size();
}