Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/avi_play/src/story_entities/movie_loader.cc @ 6604

Last change on this file since 6604 was 6604, checked in by hdavid, 18 years ago

scaled, so it is not a mirror of its own

File size: 2.8 KB
Line 
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, Stefan Lienhard
13   co-programmer:
14*/
15
16#include "movie_loader.h"
17
18#include "movie_player.h"
19#include "factory.h"
20#include "graphics_engine.h"
21#include "load_param.h"
22#include "resource_manager.h"
23#include "state.h"
24
25
26using namespace std;
27
28CREATE_FACTORY(MovieLoader, CL_MOVIE_LOADER);
29
30MovieLoader::MovieLoader(const TiXmlElement* root)
31{
32  this->setClassID(CL_MOVIE_LOADER, "MovieLoader");
33
34  movie_player = new MoviePlayer();
35  this->loadParams(root);
36}
37
38MovieLoader::~MovieLoader()
39{
40  PRINTF(4)("Deleted MoviePlayer\n");
41}
42
43
44
45void MovieLoader::loadParams(const TiXmlElement* root)
46{
47  StoryEntity::loadParams(root);
48
49  LoadParam(root, "name", this, MovieLoader, loadMovie);
50}
51
52void MovieLoader::loadMovie(const char* filename)
53{
54  movie_player->loadMovie(filename);
55
56  PRINTF(0)("\nloaded Movie %s\n\n", filename);
57}
58
59
60ErrorMessage MovieLoader::init()
61{
62
63}
64
65
66ErrorMessage MovieLoader::loadData()
67{
68
69}
70
71
72ErrorMessage MovieLoader::unloadData()
73{
74
75}
76
77bool MovieLoader::start()
78{
79  PRINTF(0)("\nMovieLoader INFO:\n");
80  movie_player->printInformation();
81  PRINTF(0)("\n");
82
83  this->isRunning = true;
84
85  this->run();
86}
87
88bool MovieLoader::stop()
89{
90  this->isRunning = false;
91}
92
93bool MovieLoader::pause() { }
94bool MovieLoader::resume() { }
95
96void MovieLoader::run()
97{
98  // first timestamp for t = 0
99  this->lastFrame = SDL_GetTicks ();
100  this->movie_player->start(0);
101
102  while( this->isRunning)
103  {
104
105    this->tick();
106    this->draw();
107
108  }
109}
110
111void MovieLoader::draw() const
112{
113  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
114
115
116  GraphicsEngine::enter2DMode();
117
118  glEnable(GL_TEXTURE_2D);
119  glBindTexture(GL_TEXTURE_2D, movie_player->getTexture());
120
121  glColor3f(1.0, 1.0, 1.0);
122
123  glBegin(GL_QUADS);
124    glTexCoord2f(0.0f, 0.0f); glVertex2f( 0, 0);
125    glTexCoord2f(0.0f, 1.0f); glVertex2f( 0, State::getResY());
126    glTexCoord2f(1.0f, 1.0f); glVertex2f( State::getResX(), State::getResY());
127    glTexCoord2f(1.0f, 0.0f); glVertex2f( State::getResX(), 0);
128  glEnd();
129
130  GraphicsEngine::leave2DMode();
131
132  SDL_GL_SwapBuffers();
133}
134
135
136void MovieLoader::tick()
137{
138  // get timestamp
139  currentFrame = SDL_GetTicks();
140
141  // calculate time difference in milliseconds (Uint32)
142  this->dt = currentFrame - this->lastFrame; 
143  // calculate time difference in seconds (float)
144  this->dts = (float)this->dt / 1000.0f;
145
146  movie_player->tick(dts);
147
148  if (movie_player->getStatus() == STOP)
149    this->isRunning = false;
150
151  this->lastFrame = currentFrame;
152}
Note: See TracBrowser for help on using the repository browser.