Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6789 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
RevLine 
[6488]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:
[6507]12   main-programmer: David Hasenfratz, Stefan Lienhard
[6488]13   co-programmer:
14*/
15
16#include "movie_entity.h"
17
[6507]18#include "media_container.h"
19#include "load_param.h"
20#include "factory.h"
21
[6488]22using namespace std;
23
[6507]24CREATE_FACTORY(MovieEntity, CL_MOVIE_ENTITY);
[6488]25
26/**
27 *  standard constructor
28 */
29MovieEntity::MovieEntity (const TiXmlElement* root)
30{
31  this->setClassID(CL_MOVIE_ENTITY, "MovieEntity");
32
[6508]33  media_container = new MediaContainer();
[6507]34
[6508]35  axis = 0;
36  rotation = 0;
37  height = 20;
38  width = 20;
[6731]39  mediaLoaded = false;
[6508]40
[6507]41  this->toList(OM_COMMON);
42
[6695]43  if( root != NULL)
44    this->loadParams(root);
[6507]45
[6488]46  counter = 0;
47  timer = 0;
[6507]48  fps = media_container->getFPS();
[6488]49}
50
51/**
52 *  standard destructor
53 */
54MovieEntity::~MovieEntity ()
55{
[6695]56  if( this->media_container)
57    delete this->media_container;
[6488]58}
59
[6507]60void MovieEntity::loadParams(const TiXmlElement* root)
61{
[6532]62  WorldEntity::loadParams(root);
[6508]63
64  LoadParam(root, "name", this, MovieEntity, loadMovie);
65  LoadParam(root, "axis", this, MovieEntity, setAxis);
[6731]66  //LoadParam(root, "rotation", this, MovieEntity, setRotation);
[6508]67  LoadParam(root, "size", this, MovieEntity, setSize);
[6507]68}
[6488]69
[6507]70void MovieEntity::loadMovie(const char* filename)
71{
[6731]72  if(media_container->loadMedia(filename))
73    mediaLoaded = true;
74  else
75    mediaLoaded = false;
[6508]76}
[6507]77
[6508]78void MovieEntity::setAxis(float axis)
79{
80  this->axis = axis;
[6507]81}
82
[6508]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
[6488]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{
[6731]103  if(!mediaLoaded)
104    return;
105
[6507]106  timer += time;
[6488]107
[6507]108  if(counter != fps * timer)
109  {
[6532]110    counter = (int)(fps * timer);
[6507]111
112    if (counter >= media_container->getFrameCount())
113    {
114      timer = 0;
115      counter = 0;
116    }
117  }
[6508]118
119  if(rotation != 0)
120    axis = (int)(axis + (time * 360/rotation))%360;
[6488]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{
[6731]131  if(!mediaLoaded)
132    false;
[6488]133
[6507]134  glPushMatrix();
135  glTranslatef (this->getAbsCoor ().x,
136                this->getAbsCoor ().y,
137                this->getAbsCoor ().z);
[6508]138  glRotatef(axis, 0.0f, 1.0f, 0.0f);
139//PRINTF(0)("axis: %f\n", axis);
[6513]140
141  glPushAttrib(GL_ENABLE_BIT);
142  glDisable(GL_LIGHTING);
143
[6600]144  glEnable(GL_TEXTURE_2D);
[6507]145  glBindTexture(GL_TEXTURE_2D, media_container->getFrameTexture(counter));
[6488]146
[6600]147  glColor3f(1.0, 1.0, 1.0);
148
[6507]149  glBegin(GL_QUADS);
[6508]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);
[6507]154  glEnd();
[6488]155
[6513]156  glPopAttrib();
157
[6507]158  glPopMatrix();
[6488]159
160}
Note: See TracBrowser for help on using the repository browser.