| 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: | 
|---|
| 12 |    main-programmer: Benjamin Grauer | 
|---|
| 13 |    co-programmer: ... | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY | 
|---|
| 17 |  | 
|---|
| 18 | #include "model_entity.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "util/loading/load_param.h" | 
|---|
| 21 | #include "util/loading/factory.h" | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | #include "class_id_DEPRECATED.h" | 
|---|
| 26 | ObjectListDefinitionID(ModelEntity, CL_MODEL_ENTITY); | 
|---|
| 27 | CREATE_FACTORY(ModelEntity); | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 |  *  initializes a skybox from a XmlElement | 
|---|
| 31 | */ | 
|---|
| 32 | ModelEntity::ModelEntity(const TiXmlElement* root) | 
|---|
| 33 | { | 
|---|
| 34 |   this->registerObject(this, ModelEntity::_objectList); | 
|---|
| 35 |   this->toList(OM_ENVIRON); | 
|---|
| 36 |  | 
|---|
| 37 |   this->speed = NULL; | 
|---|
| 38 |   this->momentum = NULL; | 
|---|
| 39 |  | 
|---|
| 40 |   this->setSynchronized(true); | 
|---|
| 41 |  | 
|---|
| 42 |   if (root != NULL) | 
|---|
| 43 |     this->loadParams(root); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 |  | 
|---|
| 47 | /** | 
|---|
| 48 |  *  default destructor | 
|---|
| 49 | */ | 
|---|
| 50 | ModelEntity::~ModelEntity() | 
|---|
| 51 | { | 
|---|
| 52 |   if (this->speed != NULL) | 
|---|
| 53 |     delete this->speed; | 
|---|
| 54 |   if (this->momentum) | 
|---|
| 55 |     delete this->momentum; | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | void ModelEntity::loadParams(const TiXmlElement* root) | 
|---|
| 59 | { | 
|---|
| 60 |   WorldEntity::loadParams(root); | 
|---|
| 61 |  | 
|---|
| 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 | { | 
|---|
| 76 |   Vector v(x,y,z); | 
|---|
| 77 |   v.debug(); | 
|---|
| 78 |   v.normalize(); | 
|---|
| 79 |   v.debug(); | 
|---|
| 80 |  | 
|---|
| 81 |   if (this->momentum == NULL) | 
|---|
| 82 |     this->momentum = new Quaternion; | 
|---|
| 83 |   *this->momentum = Quaternion(angle, v); | 
|---|
| 84 |  | 
|---|
| 85 |   this->momentum->debug(); | 
|---|
| 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) | 
|---|
| 94 |   { | 
|---|
| 95 |     this->shiftDir((*this->momentum * dt ).getNormalized()); | 
|---|
| 96 |     //this->getAbsDir().debug(); | 
|---|
| 97 |   } | 
|---|
| 98 | } | 
|---|