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