[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 | |
---|
[9406] | 25 | |
---|
[6968] | 26 | CREATE_FACTORY(ModelEntity, CL_MODEL_ENTITY); |
---|
[6524] | 27 | |
---|
| 28 | /** |
---|
| 29 | * initializes a skybox from a XmlElement |
---|
| 30 | */ |
---|
[6968] | 31 | ModelEntity::ModelEntity(const TiXmlElement* root) |
---|
[6524] | 32 | { |
---|
[6968] | 33 | this->setClassID(CL_MODEL_ENTITY, "ModelEntity"); |
---|
[9235] | 34 | this->toList(OM_ENVIRON); |
---|
[6524] | 35 | |
---|
[7048] | 36 | this->speed = NULL; |
---|
| 37 | this->momentum = NULL; |
---|
| 38 | |
---|
[9656] | 39 | this->setSynchronized(true); |
---|
| 40 | |
---|
[6968] | 41 | if (root != NULL) |
---|
| 42 | this->loadParams(root); |
---|
[6524] | 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * default destructor |
---|
| 48 | */ |
---|
[6968] | 49 | ModelEntity::~ModelEntity() |
---|
[6524] | 50 | { |
---|
[7048] | 51 | if (this->speed != NULL) |
---|
| 52 | delete this->speed; |
---|
| 53 | if (this->momentum) |
---|
| 54 | delete this->momentum; |
---|
[6524] | 55 | } |
---|
| 56 | |
---|
[7048] | 57 | void ModelEntity::loadParams(const TiXmlElement* root) |
---|
| 58 | { |
---|
| 59 | WorldEntity::loadParams(root); |
---|
[6524] | 60 | |
---|
[7048] | 61 | LoadParam(root, "speed", this, ModelEntity, setSpeed); |
---|
| 62 | LoadParam(root, "momentum", this, ModelEntity, setMomentum); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | void ModelEntity::setSpeed(float x, float y, float z) |
---|
| 67 | { |
---|
| 68 | if (this->speed == NULL) |
---|
| 69 | this->speed = new Vector; |
---|
| 70 | *this->speed = Vector(x,y,z); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void ModelEntity::setMomentum (float angle, float x, float y, float z) |
---|
| 74 | { |
---|
[9235] | 75 | Vector v(x,y,z); |
---|
| 76 | v.debug(); |
---|
| 77 | v.normalize(); |
---|
| 78 | v.debug(); |
---|
| 79 | |
---|
[7048] | 80 | if (this->momentum == NULL) |
---|
| 81 | this->momentum = new Quaternion; |
---|
[9235] | 82 | *this->momentum = Quaternion(angle, v); |
---|
| 83 | |
---|
| 84 | this->momentum->debug(); |
---|
[7048] | 85 | } |
---|
| 86 | |
---|
| 87 | void ModelEntity::tick(float dt) |
---|
| 88 | { |
---|
| 89 | if (this->speed != NULL) |
---|
| 90 | this->shiftCoor(*this->speed * dt); |
---|
| 91 | |
---|
| 92 | if (this->momentum != NULL) |
---|
[9235] | 93 | { |
---|
| 94 | this->shiftDir((*this->momentum * dt ).getNormalized()); |
---|
| 95 | //this->getAbsDir().debug(); |
---|
| 96 | } |
---|
[7048] | 97 | } |
---|