Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/avi_play/src/world_entities/movie_entity.cc @ 6721

Last change on this file since 6721 was 6704, checked in by hdavid, 19 years ago

branches/avi_play: MediaContainer is dummy-safe

File size: 3.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2005 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_entity.h"
17
18#include "media_container.h"
19#include "load_param.h"
20#include "factory.h"
21
22#include "network_game_manager.h"
23#include "converter.h"
24
25using namespace std;
26
27CREATE_FACTORY(MovieEntity, CL_MOVIE_ENTITY);
28
29/**
30 *  standard constructor
31 */
32MovieEntity::MovieEntity (const TiXmlElement* root)
33{
34  this->setClassID(CL_MOVIE_ENTITY, "MovieEntity");
35
36  media_container = new MediaContainer();
37
38  axis = 0;
39  rotation = 0;
40  height = 20;
41  width = 20;
42  mediaLoaded = false;
43
44  this->toList(OM_COMMON);
45
46  this->loadParams(root);
47
48  counter = 0;
49  timer = 0;
50  fps = media_container->getFPS();
51}
52
53/**
54 *  standard destructor
55 */
56MovieEntity::~MovieEntity ()
57{
58  delete this->media_container;
59}
60
61void MovieEntity::loadParams(const TiXmlElement* root)
62{
63  WorldEntity::loadParams(root);
64
65  LoadParam(root, "name", this, MovieEntity, loadMovie);
66  LoadParam(root, "axis", this, MovieEntity, setAxis);
67  //LoadParam(root, "rotation", this, MovieEntity, setRotation);
68  LoadParam(root, "size", this, MovieEntity, setSize);
69}
70
71void MovieEntity::loadMovie(const char* filename)
72{
73  if(media_container->loadMedia(filename))
74    mediaLoaded = true;
75  else
76    mediaLoaded = false;
77}
78
79void MovieEntity::setAxis(float axis)
80{
81  this->axis = axis;
82}
83
84// Seconds for one loop
85void MovieEntity::setRotation(float rotation)
86{
87  this->rotation = rotation;
88}
89
90void MovieEntity::setSize(float width, float height)
91{
92  this->width = width;
93  this->height = height;
94}
95
96/**
97 *  this method is called every frame
98 * @param time: the time in seconds that has passed since the last tick
99
100   Handle all stuff that should update with time inside this method (movement, animation, etc.)
101 */
102void MovieEntity::tick(float time)
103{
104  if(!mediaLoaded)
105    return;
106
107  timer += time;
108
109  if(counter != fps * timer)
110  {
111    counter = (int)(fps * timer);
112
113    if (counter >= media_container->getFrameCount())
114    {
115      timer = 0;
116      counter = 0;
117    }
118  }
119
120  if(rotation != 0)
121    axis = (int)(axis + (time * 360/rotation))%360;
122}
123
124
125/**
126 *  the entity is drawn onto the screen with this function
127
128   This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn.
129 */
130void MovieEntity::draw() const
131{
132  if(!mediaLoaded)
133    false;
134
135  glPushMatrix();
136  glTranslatef (this->getAbsCoor ().x,
137                this->getAbsCoor ().y,
138                this->getAbsCoor ().z);
139  glRotatef(axis, 0.0f, 1.0f, 0.0f);
140//PRINTF(0)("axis: %f\n", axis);
141
142  glPushAttrib(GL_ENABLE_BIT);
143  glDisable(GL_LIGHTING);
144
145  glEnable(GL_TEXTURE_2D);
146  glBindTexture(GL_TEXTURE_2D, media_container->getFrameTexture(counter));
147
148  glColor3f(1.0, 1.0, 1.0);
149
150  glBegin(GL_QUADS);
151    glTexCoord2f(1.0f, 1.0f); glVertex3f(-width/2, -height/2,  0.0f);
152    glTexCoord2f(0.0f, 1.0f); glVertex3f( width/2, -height/2,  0.0f);
153    glTexCoord2f(0.0f, 0.0f); glVertex3f( width/2,  height/2,  0.0f);
154    glTexCoord2f(1.0f, 0.0f); glVertex3f(-width/2,  height/2,  0.0f);
155  glEnd();
156
157  glPopAttrib();
158
159  glPopMatrix();
160
161}
Note: See TracBrowser for help on using the repository browser.