1 | #ifndef _WALKTHROUGHRECORDER_H__
|
---|
2 | #define _WALKTHROUGHRECORDER_H__
|
---|
3 |
|
---|
4 | #include "common.h"
|
---|
5 | #include <fstream>
|
---|
6 | #include "Vector3.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace CHCDemoEngine
|
---|
10 | {
|
---|
11 |
|
---|
12 | class Camera;
|
---|
13 |
|
---|
14 | struct FrameInfo
|
---|
15 | {
|
---|
16 | FrameInfo(const Vector3 &pos, const Vector3 &dir):
|
---|
17 | mPosition(pos), mDirection(dir)
|
---|
18 | {}
|
---|
19 |
|
---|
20 | FrameInfo() {}
|
---|
21 |
|
---|
22 |
|
---|
23 | /////////////
|
---|
24 |
|
---|
25 | Vector3 mPosition;
|
---|
26 | Vector3 mDirection;
|
---|
27 |
|
---|
28 | friend std::ostream& operator<< (std::ostream &s, const FrameInfo &A);
|
---|
29 | friend std::istream& operator>> (std::istream &s, FrameInfo &A);
|
---|
30 | };
|
---|
31 |
|
---|
32 |
|
---|
33 | /// Overload << operator for C++-style output
|
---|
34 | inline std::ostream& operator<< (std::ostream &s, const FrameInfo &A)
|
---|
35 | {
|
---|
36 | return s << A.mPosition << " " << A.mDirection;
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | /// Overload >> operator for C++-style input
|
---|
41 | inline std::istream& operator>> (std::istream &s, FrameInfo &A)
|
---|
42 | {
|
---|
43 | return s >> A.mPosition >> A.mDirection;
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | /** Records given walkthrough
|
---|
48 | */
|
---|
49 | class WalkThroughRecorder
|
---|
50 | {
|
---|
51 | public:
|
---|
52 | /** Writes walkthrough frames to file.
|
---|
53 | */
|
---|
54 | WalkThroughRecorder(const std::string &filename);
|
---|
55 |
|
---|
56 | ~WalkThroughRecorder();
|
---|
57 |
|
---|
58 | /** Writes current camera data.
|
---|
59 | */
|
---|
60 | void WriteFrame(Camera *cam);
|
---|
61 |
|
---|
62 |
|
---|
63 | protected:
|
---|
64 |
|
---|
65 | std::ofstream mFile;
|
---|
66 | };
|
---|
67 |
|
---|
68 |
|
---|
69 | /** Replays a given walkthrough
|
---|
70 | */
|
---|
71 | class WalkThroughPlayer
|
---|
72 | {
|
---|
73 | public:
|
---|
74 | /** Writes walkthrough frames to file.
|
---|
75 | */
|
---|
76 | WalkThroughPlayer(const std::string &filename);
|
---|
77 | /** Reads next frame. returns false if end of recorded frames is reached.
|
---|
78 | */
|
---|
79 | bool ReadNextFrame(Camera *cam);
|
---|
80 |
|
---|
81 |
|
---|
82 | protected:
|
---|
83 |
|
---|
84 | std::vector<FrameInfo> mFrameInfos;
|
---|
85 |
|
---|
86 | int mFrame;
|
---|
87 | };
|
---|
88 |
|
---|
89 |
|
---|
90 | }
|
---|
91 |
|
---|
92 | #endif
|
---|