Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/osX/src/story_entities/movie_loader.cc @ 6996

Last change on this file since 6996 was 6731, checked in by bensch, 19 years ago

merged avi_play back to the trunk. command https://svn.orxonox.net/orxonox/branches/avi_play . -r6602:HEAD

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