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