[6524] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 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: |
---|
[6970] | 12 | main-programmer: Benjamin Grauer |
---|
[6524] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 17 | |
---|
[6970] | 18 | #include "model_entity.h" |
---|
[6524] | 19 | |
---|
[7193] | 20 | #include "util/loading/load_param.h" |
---|
| 21 | #include "util/loading/factory.h" |
---|
[6524] | 22 | |
---|
| 23 | |
---|
| 24 | |
---|
[10114] | 25 | |
---|
| 26 | ObjectListDefinition(ModelEntity); |
---|
[9869] | 27 | CREATE_FACTORY(ModelEntity); |
---|
[9406] | 28 | |
---|
[6524] | 29 | /** |
---|
| 30 | * initializes a skybox from a XmlElement |
---|
| 31 | */ |
---|
[6968] | 32 | ModelEntity::ModelEntity(const TiXmlElement* root) |
---|
[6524] | 33 | { |
---|
[9869] | 34 | this->registerObject(this, ModelEntity::_objectList); |
---|
[9235] | 35 | this->toList(OM_ENVIRON); |
---|
[6524] | 36 | |
---|
[7048] | 37 | this->speed = NULL; |
---|
| 38 | this->momentum = NULL; |
---|
| 39 | |
---|
[9656] | 40 | this->setSynchronized(true); |
---|
| 41 | |
---|
[6968] | 42 | if (root != NULL) |
---|
| 43 | this->loadParams(root); |
---|
[6524] | 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * default destructor |
---|
| 49 | */ |
---|
[6968] | 50 | ModelEntity::~ModelEntity() |
---|
[6524] | 51 | { |
---|
[7048] | 52 | if (this->speed != NULL) |
---|
| 53 | delete this->speed; |
---|
| 54 | if (this->momentum) |
---|
| 55 | delete this->momentum; |
---|
[6524] | 56 | } |
---|
| 57 | |
---|
[7048] | 58 | void ModelEntity::loadParams(const TiXmlElement* root) |
---|
| 59 | { |
---|
| 60 | WorldEntity::loadParams(root); |
---|
[6524] | 61 | |
---|
[7048] | 62 | LoadParam(root, "speed", this, ModelEntity, setSpeed); |
---|
| 63 | LoadParam(root, "momentum", this, ModelEntity, setMomentum); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | void ModelEntity::setSpeed(float x, float y, float z) |
---|
| 68 | { |
---|
| 69 | if (this->speed == NULL) |
---|
| 70 | this->speed = new Vector; |
---|
| 71 | *this->speed = Vector(x,y,z); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | void ModelEntity::setMomentum (float angle, float x, float y, float z) |
---|
| 75 | { |
---|
[9235] | 76 | Vector v(x,y,z); |
---|
| 77 | v.debug(); |
---|
| 78 | v.normalize(); |
---|
| 79 | v.debug(); |
---|
| 80 | |
---|
[7048] | 81 | if (this->momentum == NULL) |
---|
| 82 | this->momentum = new Quaternion; |
---|
[9235] | 83 | *this->momentum = Quaternion(angle, v); |
---|
| 84 | |
---|
| 85 | this->momentum->debug(); |
---|
[7048] | 86 | } |
---|
| 87 | |
---|
| 88 | void ModelEntity::tick(float dt) |
---|
| 89 | { |
---|
| 90 | if (this->speed != NULL) |
---|
| 91 | this->shiftCoor(*this->speed * dt); |
---|
| 92 | |
---|
| 93 | if (this->momentum != NULL) |
---|
[9235] | 94 | { |
---|
| 95 | this->shiftDir((*this->momentum * dt ).getNormalized()); |
---|
| 96 | //this->getAbsDir().debug(); |
---|
| 97 | } |
---|
[7048] | 98 | } |
---|