1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: David Hasenfratz |
---|
13 | co-programmer: |
---|
14 | */ |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_MEDIA module |
---|
19 | For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput |
---|
20 | */ |
---|
21 | #define DEBUG_MODULE_MEDIA |
---|
22 | |
---|
23 | |
---|
24 | /* include your own header */ |
---|
25 | #include "movie_player.h" |
---|
26 | |
---|
27 | /* header for debug output */ |
---|
28 | #include "debug.h" |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * Default constructor |
---|
33 | */ |
---|
34 | MoviePlayer::MoviePlayer(const char* filename) |
---|
35 | { |
---|
36 | media_container = new MediaContainer(filename); |
---|
37 | |
---|
38 | this->init(); |
---|
39 | } |
---|
40 | |
---|
41 | MoviePlayer::MoviePlayer() |
---|
42 | { |
---|
43 | media_container = new MediaContainer(); |
---|
44 | |
---|
45 | this->init(); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * Default destructor |
---|
50 | */ |
---|
51 | MoviePlayer::~MoviePlayer() |
---|
52 | { |
---|
53 | delete media_container; |
---|
54 | } |
---|
55 | |
---|
56 | void MoviePlayer::init() |
---|
57 | { |
---|
58 | status = STOP; |
---|
59 | timer = 0; |
---|
60 | |
---|
61 | material = new Material; |
---|
62 | |
---|
63 | material->setDiffuseMap("maps/radialTransparency.png"); |
---|
64 | |
---|
65 | model = new PrimitiveModel(PRIM_PLANE, 10.0); |
---|
66 | |
---|
67 | LightManager* lightMan = LightManager::getInstance(); |
---|
68 | lightMan->setAmbientColor(.1,.1,.1); |
---|
69 | (new Light())->setAbsCoor(5.0, 10.0, 40.0); |
---|
70 | (new Light())->setAbsCoor(-10, -20, -100); |
---|
71 | } |
---|
72 | |
---|
73 | void MoviePlayer::loadMovie(const char* filename) |
---|
74 | { |
---|
75 | media_container->loadMedia(filename); |
---|
76 | } |
---|
77 | |
---|
78 | void MoviePlayer::printInformation() |
---|
79 | { |
---|
80 | media_container->printMediaInformation(); |
---|
81 | } |
---|
82 | |
---|
83 | void MoviePlayer::start(unsigned int start_frame) |
---|
84 | { |
---|
85 | status = PLAY; |
---|
86 | timer = 0; |
---|
87 | fps = media_container->getFPS(); |
---|
88 | |
---|
89 | media_container->gotoFrame(start_frame); |
---|
90 | |
---|
91 | PRINTF(0)("start\n"); |
---|
92 | } |
---|
93 | |
---|
94 | void MoviePlayer::resume() |
---|
95 | { |
---|
96 | if(status == STOP) |
---|
97 | this->start(0); |
---|
98 | else |
---|
99 | status = PLAY; |
---|
100 | |
---|
101 | PRINTF(0)("resume\n"); |
---|
102 | } |
---|
103 | |
---|
104 | void MoviePlayer::pause() |
---|
105 | { |
---|
106 | if(status != STOP) |
---|
107 | status = PAUSE; |
---|
108 | |
---|
109 | PRINTF(0)("pause\n"); |
---|
110 | } |
---|
111 | |
---|
112 | void MoviePlayer::stop() |
---|
113 | { |
---|
114 | status = STOP; |
---|
115 | texture = NULL; |
---|
116 | |
---|
117 | PRINTF(0)("stop\n"); |
---|
118 | } |
---|
119 | |
---|
120 | void MoviePlayer::tick(float dt) |
---|
121 | { |
---|
122 | if(status == PLAY) |
---|
123 | { |
---|
124 | current_frame = media_container->getFrameNumber(); |
---|
125 | timer += dt; |
---|
126 | actuel_frame = timer * fps; |
---|
127 | |
---|
128 | if(actuel_frame != current_frame) |
---|
129 | { |
---|
130 | if(actuel_frame - current_frame == 1) |
---|
131 | texture = media_container->getNextFrame(); |
---|
132 | else |
---|
133 | texture = media_container->skipFrame(actuel_frame - current_frame - 1); |
---|
134 | } |
---|
135 | //PRINTF(0)("frame_number: %i\n", media_container->getFrameNumber()); |
---|
136 | |
---|
137 | if(texture == NULL && current_frame != 0) |
---|
138 | this->stop(); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | const void MoviePlayer::draw() |
---|
143 | { |
---|
144 | material->select(); |
---|
145 | glBindTexture(GL_TEXTURE_2D, texture); |
---|
146 | model->draw(); |
---|
147 | |
---|
148 | LightManager::getInstance()->draw(); |
---|
149 | } |
---|
150 | |
---|
151 | void MoviePlayer::setSpeed(float speed) |
---|
152 | { |
---|
153 | this->speed = speed; |
---|
154 | } |
---|
155 | |
---|
156 | float MoviePlayer::getSpeed() |
---|
157 | { |
---|
158 | return this->speed; |
---|
159 | } |
---|
160 | |
---|
161 | const MP_STATUS MoviePlayer::getStatus() |
---|
162 | { |
---|
163 | return this->status; |
---|
164 | } |
---|