Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6691 was 6676, checked in by bensch, 19 years ago

trunk: weaponManager works again

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