Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9933 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.6 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"
[7193]19#include "util/loading/load_param.h"
20#include "util/loading/factory.h"
[6507]21
[6488]22
[9869]23#include "class_id_DEPRECATED.h"
24ObjectListDefinitionID(MovieEntity, CL_MOVIE_ENTITY);
25CREATE_FACTORY(MovieEntity);
[9406]26
[6488]27/**
28 *  standard constructor
29 */
30MovieEntity::MovieEntity (const TiXmlElement* root)
31{
[9869]32  this->registerObject(this, MovieEntity::_objectList);
[6488]33
[6508]34  media_container = new MediaContainer();
[6507]35
[6508]36  axis = 0;
37  rotation = 0;
38  height = 20;
39  width = 20;
[6731]40  mediaLoaded = false;
[6508]41
[6507]42  this->toList(OM_COMMON);
43
[6695]44  if( root != NULL)
45    this->loadParams(root);
[6507]46
[6488]47  counter = 0;
48  timer = 0;
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);
[7115]66  LoadParam(root, "rotation", this, MovieEntity, setRotation);
[6508]67  LoadParam(root, "size", this, MovieEntity, setSize);
[7010]68  LoadParam(root, "fps", this, MovieEntity, setFPS);
[6507]69}
[6488]70
[7010]71void MovieEntity::setFPS(float fps)
72{
73  this->fps = fps;
[7049]74//PRINTF(0)("fps: %f\n", fps);
[7010]75}
76
[7221]77void MovieEntity::loadMovie(const std::string& filename)
[6507]78{
[6731]79  if(media_container->loadMedia(filename))
[7010]80  {
[6731]81    mediaLoaded = true;
[7010]82    fps = media_container->getFPS();
83  }
[6731]84  else
85    mediaLoaded = false;
[6508]86}
[6507]87
[6508]88void MovieEntity::setAxis(float axis)
89{
[7049]90//PRINTF(0)("fps: %f\n", fps);
[6508]91  this->axis = axis;
[6507]92}
93
[6508]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
[6488]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{
[6731]114  if(!mediaLoaded)
115    return;
116
[6507]117  timer += time;
[6488]118
[6507]119  if(counter != fps * timer)
120  {
[6532]121    counter = (int)(fps * timer);
[6507]122
[8310]123    if ((unsigned int)counter >= media_container->getFrameCount())
[6507]124    {
125      timer = 0;
126      counter = 0;
127    }
128  }
[6508]129
[7115]130  axis += (time * rotation/360.0);
[6488]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{
[8310]141//   if(!mediaLoaded)
142//     false;
[6488]143
[7115]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
[6507]151  glPushMatrix();
152  glTranslatef (this->getAbsCoor ().x,
153                this->getAbsCoor ().y,
154                this->getAbsCoor ().z);
[6508]155  glRotatef(axis, 0.0f, 1.0f, 0.0f);
156//PRINTF(0)("axis: %f\n", axis);
[6513]157
[6600]158  glColor3f(1.0, 1.0, 1.0);
159
[6507]160  glBegin(GL_QUADS);
[6508]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);
[6507]165  glEnd();
[6488]166
[7115]167  glPopMatrix();
[6513]168  glPopAttrib();
[6488]169}
Note: See TracBrowser for help on using the repository browser.