source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/WalkThroughRecorder.cpp @ 3220

Revision 3220, 1.2 KB checked in by mattausch, 16 years ago (diff)

worked on video replay function

Line 
1#include "WalkThroughRecorder.h"
2#include "Camera.h"
3#include "Vector3.h"
4#include <sstream>
5
6using namespace std;
7
8
9namespace CHCDemoEngine
10{
11
12
13WalkThroughRecorder::WalkThroughRecorder(const std::string &filename):
14mFile(filename.c_str())
15{
16}
17
18
19WalkThroughRecorder::~WalkThroughRecorder()
20{
21        mFile.close();
22}
23
24
25void WalkThroughRecorder::WriteFrame(Camera *cam)
26{
27        FrameInfo info(cam->GetPosition(), cam->GetDirection());
28        mFile << info << endl;
29}
30
31
32WalkThroughPlayer::WalkThroughPlayer(const std::string &filename):
33mFrame(0)
34{
35        ifstream file(filename.c_str());
36
37        if (file.is_open())
38        {
39                FrameInfo info;
40                int i=0;
41
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
53        {
54                cerr << "problem: cannot open file " << filename << endl;
55        }
56
57        file.close();
58}
59
60
61bool WalkThroughPlayer::ReadNextFrame(Camera *cam)
62{
63        if (mFrameInfos.empty())
64                return false;
65
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;
72}
73
74
75}
Note: See TracBrowser for help on using the repository browser.