[3750] | 1 | |
---|
| 2 | |
---|
[4597] | 3 | /* |
---|
[3750] | 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[4597] | 15 | co-programmer: |
---|
[3750] | 16 | */ |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | #include "satellite.h" |
---|
| 20 | |
---|
| 21 | #include "objModel.h" |
---|
| 22 | #include "list.h" |
---|
| 23 | #include "vector.h" |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | using namespace std; |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | \brief standard constructor |
---|
| 30 | */ |
---|
| 31 | Satellite::Satellite (Vector axis, float speed) |
---|
| 32 | { |
---|
[4320] | 33 | this->setClassID(CL_SATELLITE, "Satellite"); |
---|
[4597] | 34 | |
---|
[3750] | 35 | this->model = (Model*) ResourceManager::getInstance()->load("cube", RP_LEVEL); |
---|
| 36 | this->speed = speed; |
---|
| 37 | this->axis = new Vector(); |
---|
| 38 | *this->axis = axis; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | \brief standard destructor |
---|
| 43 | */ |
---|
| 44 | Satellite::~Satellite () |
---|
| 45 | { |
---|
| 46 | // if( collisioncluster != NULL) delete collisioncluster; |
---|
| 47 | if (this->model) |
---|
| 48 | ResourceManager::getInstance()->unload(this->model); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | \brief this method is called every frame |
---|
| 54 | \param time: the time in seconds that has passed since the last tick |
---|
[4597] | 55 | |
---|
[3750] | 56 | Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
| 57 | */ |
---|
[4597] | 58 | void Satellite::tick(float time) |
---|
[3750] | 59 | { |
---|
| 60 | float w = this->speed * M_PI; |
---|
| 61 | |
---|
[4597] | 62 | Quaternion rotation(w * time, *this->axis); |
---|
[3750] | 63 | Quaternion v = this->getRelDir(); |
---|
[4597] | 64 | |
---|
[3750] | 65 | this->setRelDir(v * rotation); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | \brief the entity is drawn onto the screen with this function |
---|
[4597] | 71 | |
---|
[3750] | 72 | 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. |
---|
| 73 | */ |
---|
[4597] | 74 | void Satellite::draw() |
---|
[3750] | 75 | { |
---|
| 76 | glMatrixMode(GL_MODELVIEW); |
---|
| 77 | glPushMatrix(); |
---|
| 78 | float matrix[4][4]; |
---|
[4597] | 79 | |
---|
[3750] | 80 | /* translate */ |
---|
[4597] | 81 | glTranslatef (this->getAbsCoor ().x, |
---|
| 82 | this->getAbsCoor ().y, |
---|
| 83 | this->getAbsCoor ().z); |
---|
[3750] | 84 | /* rotate */ |
---|
| 85 | this->getAbsDir ().matrix (matrix); |
---|
| 86 | glMultMatrixf((float*)matrix); |
---|
[4597] | 87 | |
---|
[3750] | 88 | this->model->draw(); |
---|
| 89 | glPopMatrix(); |
---|
| 90 | |
---|
| 91 | } |
---|
| 92 | |
---|