Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: weaponManager works 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
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
40  this->toList(OM_COMMON);
41
42  this->loadParams(root);
43
44  counter = 0;
45  timer = 0;
46  fps = media_container->getFPS();
47}
48
49/**
50 *  standard destructor
51 */
52MovieEntity::~MovieEntity ()
53{
54  delete this->media_container;
55}
56
57void MovieEntity::loadParams(const TiXmlElement* root)
58{
59  WorldEntity::loadParams(root);
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);
65}
66
67void MovieEntity::loadMovie(const char* filename)
68{
69  media_container->loadMedia(filename);
70}
71
72void MovieEntity::setAxis(float axis)
73{
74  this->axis = axis;
75}
76
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
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{
97  timer += time;
98
99  if(counter != fps * timer)
100  {
101    counter = (int)(fps * timer);
102
103    if (counter >= media_container->getFrameCount())
104    {
105      timer = 0;
106      counter = 0;
107    }
108  }
109
110  if(rotation != 0)
111    axis = (int)(axis + (time * 360/rotation))%360;
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
123  glPushMatrix();
124  glTranslatef (this->getAbsCoor ().x,
125                this->getAbsCoor ().y,
126                this->getAbsCoor ().z);
127  glRotatef(axis, 0.0f, 1.0f, 0.0f);
128//PRINTF(0)("axis: %f\n", axis);
129
130  glPushAttrib(GL_ENABLE_BIT);
131  glDisable(GL_LIGHTING);
132
133  glEnable(GL_TEXTURE_2D);
134  glBindTexture(GL_TEXTURE_2D, media_container->getFrameTexture(counter));
135
136  glColor3f(1.0, 1.0, 1.0);
137
138  glBegin(GL_QUADS);
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);
143  glEnd();
144
145  glPopAttrib();
146
147  glPopMatrix();
148
149}
Note: See TracBrowser for help on using the repository browser.