Changeset 11638 for code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
- Timestamp:
- Dec 4, 2017, 4:17:59 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
r11606 r11638 26 26 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPawnHit)>::registerFunction<&ScriptableControllerAPI::registerAtPawnHit>(this, lua, "registerAtPawnHit"); 27 27 28 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setPosition)>::registerFunction<&ScriptableControllerAPI::setPosition>(this, lua, "setPosition"); 29 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setOrientation)>::registerFunction<&ScriptableControllerAPI::setOrientation>(this, lua, "setOrientation"); 30 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setVelocity)>::registerFunction<&ScriptableControllerAPI::setVelocity>(this, lua, "setVelocity"); 31 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setAngularVelocity)>::registerFunction<&ScriptableControllerAPI::setAngularVelocity>(this, lua, "setAngularVelocity"); 32 28 33 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::killPawn)>::registerFunction<&ScriptableControllerAPI::killPawn>(this, lua, "killPawn"); 29 34 … … 98 103 } 99 104 105 void ScriptableControllerAPI::setPosition(std::string id, double x, double y, double z) 106 { 107 WorldEntity *entity = this->controller_->getWorldEntityByID(id); 108 if(entity == nullptr) 109 { 110 orxout(user_warning) << "Trying to set position of an unknown object" << std::endl; 111 return; 112 } 113 114 const Vector3 &old = entity->getPosition(); 115 116 x = std::isnan(x) ? old.x : x; 117 y = std::isnan(y) ? old.y : y; 118 z = std::isnan(z) ? old.z : z; 119 120 entity->setPosition(x, y, z); 121 } 122 123 void ScriptableControllerAPI::setOrientation(std::string id, double x, double y, double z, double angle) 124 { 125 WorldEntity *entity = this->controller_->getWorldEntityByID(id); 126 if(entity == nullptr) 127 { 128 orxout(user_warning) << "Trying to set orientation of an unknown object" << std::endl; 129 return; 130 } 131 132 Vector3 old_axis; 133 Degree old_angle; 134 135 entity->getOrientation().ToAngleAxis(old_angle, old_axis); 136 137 x = std::isnan(x) ? old_axis.x : x; 138 y = std::isnan(y) ? old_axis.y : y; 139 z = std::isnan(z) ? old_axis.z : z; 140 angle = std::isnan(x) ? old_angle.valueDegrees() : angle; 141 142 entity->setOrientation(Vector3(x, y, z), Degree(angle)); 143 } 144 145 void ScriptableControllerAPI::setVelocity(std::string id, double x, double y, double z) 146 { 147 MobileEntity *entity = this->controller_->getMobileEntityByID(id); 148 if(entity == nullptr) 149 { 150 orxout(user_warning) << "Trying to set velocity of an unknown object" << std::endl; 151 return; 152 } 153 154 const Vector3 &old = entity->getVelocity(); 155 156 x = std::isnan(x) ? old.x : x; 157 y = std::isnan(y) ? old.y : y; 158 z = std::isnan(z) ? old.z : z; 159 160 entity->setVelocity(x, y, z); 161 } 162 163 void ScriptableControllerAPI::setAngularVelocity(std::string id, double x, double y, double z) 164 { 165 MobileEntity *entity = this->controller_->getMobileEntityByID(id); 166 if(entity == nullptr) 167 { 168 orxout(user_warning) << "Trying to set angular velocity of an unknown object" << std::endl; 169 return; 170 } 171 172 const Vector3 &old = entity->getAngularVelocity(); 173 174 x = std::isnan(x) ? old.x : x; 175 y = std::isnan(y) ? old.y : y; 176 z = std::isnan(z) ? old.z : z; 177 178 entity->setAngularVelocity(x, y, z); 179 } 180 100 181 void ScriptableControllerAPI::pawnKilled(std::string id) 101 182 {
Note: See TracChangeset
for help on using the changeset viewer.