Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: the net code works again

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