Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6584 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
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#include "material.h"
22
23#include "network_game_manager.h"
24#include "converter.h"
25
[6488]26using namespace std;
27
[6507]28CREATE_FACTORY(MovieEntity, CL_MOVIE_ENTITY);
[6488]29
30/**
31 *  standard constructor
32 */
33MovieEntity::MovieEntity (const TiXmlElement* root)
34{
35  this->setClassID(CL_MOVIE_ENTITY, "MovieEntity");
36
[6508]37  media_container = new MediaContainer();
[6507]38
39  this->material = new Material;
40  this->material->setDiffuseMap("maps/radialTransparency.png");
41
[6508]42  axis = 0;
43  rotation = 0;
44  height = 20;
45  width = 20;
46
[6507]47  this->toList(OM_COMMON);
48
49  this->loadParams(root);
50
[6488]51  counter = 0;
52  timer = 0;
[6507]53  fps = media_container->getFPS();
[6488]54}
55
56/**
57 *  standard destructor
58 */
59MovieEntity::~MovieEntity ()
60{
[6507]61  delete this->material;
62  delete this->media_container;
[6488]63}
64
[6507]65void MovieEntity::loadParams(const TiXmlElement* root)
66{
[6532]67  WorldEntity::loadParams(root);
[6508]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);
[6507]73}
[6488]74
[6507]75void MovieEntity::loadMovie(const char* filename)
76{
[6508]77  media_container->loadMedia(filename);
78}
[6507]79
[6508]80void MovieEntity::setAxis(float axis)
81{
82  this->axis = axis;
[6507]83}
84
[6508]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
[6488]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{
[6507]105  timer += time;
[6488]106
[6507]107  if(counter != fps * timer)
108  {
[6532]109    counter = (int)(fps * timer);
[6507]110
111    if (counter >= media_container->getFrameCount())
112    {
113      timer = 0;
114      counter = 0;
115    }
116  }
[6508]117
118  if(rotation != 0)
119    axis = (int)(axis + (time * 360/rotation))%360;
[6488]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
[6507]131  glPushMatrix();
132  glTranslatef (this->getAbsCoor ().x,
133                this->getAbsCoor ().y,
134                this->getAbsCoor ().z);
[6508]135  glRotatef(axis, 0.0f, 1.0f, 0.0f);
136//PRINTF(0)("axis: %f\n", axis);
[6513]137
138  glPushAttrib(GL_ENABLE_BIT);
139  glDisable(GL_LIGHTING);
140
[6507]141  this->material->select();
142  glBindTexture(GL_TEXTURE_2D, media_container->getFrameTexture(counter));
[6488]143
[6507]144  glBegin(GL_QUADS);
[6508]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);
[6507]149  glEnd();
[6488]150
[6513]151  glPopAttrib();
152
[6507]153  glPopMatrix();
[6488]154
155}
Note: See TracBrowser for help on using the repository browser.