Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/movie_entity.cc @ 6678

Last change on this file since 6678 was 6678, checked in by patrick, 18 years ago

network: sys better now, got less errors and removed the pnode link sync alg, replacing

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