Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6566 was 6532, checked in by bensch, 19 years ago

orxonox/trunk: merged branches/movie_play to the trunk. no conflicts, but a minor virtual function BUG

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