Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/movie_entity.cc @ 6870

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