Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/world_entities/movie_entity.cc @ 10293

Last change on this file since 10293 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

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