source:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/WalkThroughRecorder.cpp
@
3220
Revision 3220, 1.2 KB checked in by mattausch, 16 years ago (diff) |
---|
Rev | Line | |
---|---|---|
[3173] | 1 | #include "WalkThroughRecorder.h" |
[3210] | 2 | #include "Camera.h" |
[3219] | 3 | #include "Vector3.h" |
4 | #include <sstream> | |
[3173] | 5 | |
[3210] | 6 | using namespace std; |
7 | ||
8 | ||
[3173] | 9 | namespace CHCDemoEngine |
10 | { | |
11 | ||
12 | ||
[3219] | 13 | WalkThroughRecorder::WalkThroughRecorder(const std::string &filename): |
14 | mFile(filename.c_str()) | |
15 | { | |
16 | } | |
[3173] | 17 | |
[3219] | 18 | |
[3220] | 19 | WalkThroughRecorder::~WalkThroughRecorder() |
20 | { | |
21 | mFile.close(); | |
22 | } | |
23 | ||
24 | ||
[3210] | 25 | void WalkThroughRecorder::WriteFrame(Camera *cam) |
26 | { | |
[3219] | 27 | FrameInfo info(cam->GetPosition(), cam->GetDirection()); |
28 | mFile << info << endl; | |
[3210] | 29 | } |
30 | ||
31 | ||
[3219] | 32 | WalkThroughPlayer::WalkThroughPlayer(const std::string &filename): |
33 | mFrame(0) | |
34 | { | |
35 | ifstream file(filename.c_str()); | |
[3210] | 36 | |
[3220] | 37 | if (file.is_open()) |
38 | { | |
39 | FrameInfo info; | |
40 | int i=0; | |
[3210] | 41 | |
[3220] | 42 | std::string token; |
43 | ||
44 | while(std::getline(file, token)) | |
45 | { | |
46 | std::stringstream line(token); | |
47 | ||
48 | line >> info; | |
49 | mFrameInfos.push_back(info); | |
50 | } | |
51 | } | |
52 | else | |
[3219] | 53 | { |
[3220] | 54 | cerr << "problem: cannot open file " << filename << endl; |
55 | } | |
[3219] | 56 | |
[3220] | 57 | file.close(); |
[3219] | 58 | } |
59 | ||
60 | ||
61 | bool WalkThroughPlayer::ReadNextFrame(Camera *cam) | |
[3210] | 62 | { |
[3220] | 63 | if (mFrameInfos.empty()) |
64 | return false; | |
65 | ||
[3219] | 66 | cam->SetDirection(mFrameInfos[mFrame].mDirection); |
67 | cam->SetPosition(mFrameInfos[mFrame].mPosition); | |
68 | ||
69 | mFrame = (mFrame + 1) % (int)mFrameInfos.size(); | |
70 | ||
71 | return mFrame != 0; | |
[3210] | 72 | } |
73 | ||
74 | ||
[3173] | 75 | } |
Note: See TracBrowser
for help on using the repository browser.