Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/avi_play/src/lib/graphics/importer/movie_player.cc @ 6325

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

branches\avi_play: the frames are created faster with glTexSubImage2D, implemented custom speed setting

File size: 3.0 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
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 */
34MoviePlayer::MoviePlayer(const char* filename)
35{
36  media_container = new MediaContainer(filename);
37
38  this->init();
39}
40
41MoviePlayer::MoviePlayer()
42{
43  media_container = new MediaContainer();
44
45  this->init();
46}
47
48/**
49 * Default destructor
50 */
51MoviePlayer::~MoviePlayer()
52{
53  delete media_container;
54}
55
56void MoviePlayer::init()
57{
58  status = STOP;
59  timer = 0;
60  speed = 1;
61
62  material = new Material;
63
64  material->setDiffuseMap("maps/radialTransparency.png");
65
66  model = new PrimitiveModel(PRIM_PLANE, 10.0);
67
68  LightManager* lightMan = LightManager::getInstance();
69  lightMan->setAmbientColor(.1,.1,.1);
70  (new Light())->setAbsCoor(5.0, 10.0, 40.0);
71  (new Light())->setAbsCoor(-10, -20, -100);
72}
73
74void MoviePlayer::loadMovie(const char* filename)
75{
76  media_container->loadMedia(filename);
77}
78
79void MoviePlayer::printInformation()
80{
81  media_container->printMediaInformation();
82}
83
84void MoviePlayer::start(unsigned int start_frame)
85{
86  status = PLAY;
87  timer = 0;
88  fps = media_container->getFPS();
89
90  media_container->gotoFrame(start_frame);
91
92   PRINTF(0)("start\n");
93}
94
95void MoviePlayer::resume()
96{
97  if(status == STOP)
98    this->start(0);
99  else
100    status = PLAY;
101
102   PRINTF(0)("resume\n");
103}
104
105void MoviePlayer::pause()
106{
107  if(status != STOP)
108    status = PAUSE;
109
110  PRINTF(0)("pause\n");
111}
112
113void MoviePlayer::stop()
114{
115  status = STOP;
116  texture = NULL;
117
118  PRINTF(0)("stop\n");
119}
120
121void MoviePlayer::tick(float dt)
122{
123  if(status == PLAY)
124  {
125    current_frame = media_container->getFrameNumber();
126    timer += dt;
127    actuel_frame = timer * fps * speed;
128
129    if(actuel_frame != current_frame)
130    {
131      if(actuel_frame - current_frame == 1)
132        texture = media_container->getNextFrame();
133      else
134        texture = media_container->skipFrame(actuel_frame - current_frame - 1);
135    }   
136    //PRINTF(0)("frame_number: %i\n", media_container->getFrameNumber());
137
138    if(texture == NULL && current_frame != 0)
139      this->stop();
140  }
141}
142
143const void MoviePlayer::draw()
144{
145  material->select();
146  glBindTexture(GL_TEXTURE_2D, texture);
147  model->draw();
148
149  LightManager::getInstance()->draw();
150}
151
152void MoviePlayer::setSpeed(float speed)
153{
154  if(speed > 0)
155    this->speed = speed;
156}
157
158float MoviePlayer::getSpeed()
159{
160  return this->speed;
161}
162
163const MP_STATUS MoviePlayer::getStatus()
164{
165  return this->status;
166}
Note: See TracBrowser for help on using the repository browser.