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