Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6669 was 6600, checked in by bensch, 19 years ago

TRUNK: merged the avi_play branche again

File size: 3.2 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
43  this->toList(OM_COMMON);
44
45  this->loadParams(root);
46
47  counter = 0;
48  timer = 0;
49  fps = media_container->getFPS();
50}
51
52/**
53 *  standard destructor
54 */
55MovieEntity::~MovieEntity ()
56{
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  media_container->loadMedia(filename);
73}
74
75void MovieEntity::setAxis(float axis)
76{
77  this->axis = axis;
78}
79
80// Seconds for one loop
81void MovieEntity::setRotation(float rotation)
82{
83  this->rotation = rotation;
84}
85
86void MovieEntity::setSize(float width, float height)
87{
88  this->width = width;
89  this->height = height;
90}
91
92/**
93 *  this method is called every frame
94 * @param time: the time in seconds that has passed since the last tick
95
96   Handle all stuff that should update with time inside this method (movement, animation, etc.)
97 */
98void MovieEntity::tick(float time)
99{
100  timer += time;
101
102  if(counter != fps * timer)
103  {
104    counter = (int)(fps * timer);
105
106    if (counter >= media_container->getFrameCount())
107    {
108      timer = 0;
109      counter = 0;
110    }
111  }
112
113  if(rotation != 0)
114    axis = (int)(axis + (time * 360/rotation))%360;
115}
116
117
118/**
119 *  the entity is drawn onto the screen with this function
120
121   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.
122 */
123void MovieEntity::draw() const
124{
125
126  glPushMatrix();
127  glTranslatef (this->getAbsCoor ().x,
128                this->getAbsCoor ().y,
129                this->getAbsCoor ().z);
130  glRotatef(axis, 0.0f, 1.0f, 0.0f);
131//PRINTF(0)("axis: %f\n", axis);
132
133  glPushAttrib(GL_ENABLE_BIT);
134  glDisable(GL_LIGHTING);
135
136  glEnable(GL_TEXTURE_2D);
137  glBindTexture(GL_TEXTURE_2D, media_container->getFrameTexture(counter));
138
139  glColor3f(1.0, 1.0, 1.0);
140
141  glBegin(GL_QUADS);
142    glTexCoord2f(1.0f, 1.0f); glVertex3f(-width/2, -height/2,  0.0f);
143    glTexCoord2f(0.0f, 1.0f); glVertex3f( width/2, -height/2,  0.0f);
144    glTexCoord2f(0.0f, 0.0f); glVertex3f( width/2,  height/2,  0.0f);
145    glTexCoord2f(1.0f, 0.0f); glVertex3f(-width/2,  height/2,  0.0f);
146  glEnd();
147
148  glPopAttrib();
149
150  glPopMatrix();
151
152}
Note: See TracBrowser for help on using the repository browser.