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