- Timestamp:
- Dec 4, 2017, 4:17:59 PM (7 years ago)
- Location:
- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc
r11606 r11638 64 64 } 65 65 66 void ScriptableController::registerMobileEntity(std::string id, MobileEntity *entity) 67 { 68 this->mobileEntities_[id] = entity; 69 } 70 66 71 void ScriptableController::registerPawn(std::string id, Pawn *pawn) 67 72 { … … 124 129 } 125 130 131 MobileEntity *ScriptableController::getMobileEntityByID(std::string id) const 132 { 133 if(id == "player" || id == "Player" || id == "PLAYER") 134 return this->player_->getControllableEntity(); 135 136 auto entity = this->mobileEntities_.find(id); 137 return entity != this->mobileEntities_.end() ? entity->second : nullptr; 138 139 } 140 126 141 Pawn *ScriptableController::getPawnByID(std::string id) const 127 142 { -
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.h
r11606 r11638 59 59 60 60 /** 61 * @brief Register a MobileEntity to the ScriptableController 62 * @param id The ID of the MobileEntity 63 * @param entity The MobileEntity 64 * 65 * The ScriptableController needs a list of all MobileEntity's so it can 66 * convert an ID to a MobileEntity. 67 */ 68 void registerMobileEntity(std::string id, MobileEntity *entity); 69 70 /** 61 71 * @brief Register a Pawn to the ScriptableController 62 72 * @param id The ID of the Pawn … … 101 111 102 112 /** 113 * @brief Convert an ID to a MobileEntity pointer 114 * @param id The ID of the MobileEntity 115 * @return A pointer to the MobileEntity, nullptr if it's not found 116 */ 117 MobileEntity *getMobileEntityByID(std::string id) const; 118 119 /** 103 120 * @brief Convert an ID to a Pawt pointer 104 121 * @param id The ID of the Pawn … … 111 128 PlayerInfo *player_; 112 129 std::map<std::string, WorldEntity*> worldEntities_; 130 std::map<std::string, MobileEntity*> mobileEntities_; 113 131 std::map<std::string, Pawn*> pawns_; 114 132 std::map<Pawn*, std::string> pawnsReverse_; -
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 { -
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h
r11606 r11638 39 39 ~ScriptableControllerAPI(); 40 40 41 // --- API ---------------------------------- 41 // ### API #################################################################### 42 42 43 43 /** … … 139 139 void killPawn(std::string id); 140 140 141 // ------------------------------------------ 141 /** 142 * @brief Set the position of an object 143 * @param id The ID of the object 144 * @param x The position on the x-axis 145 * @param y The position on the y-axis 146 * @param z The position on the z-axis 147 */ 148 void setPosition(std::string id, double x, double y, double z); 149 150 /** 151 * @brief Set the orientation of an object 152 * @param id The ID of the object 153 * @param x The x component of the axis vector 154 * @param y The y component of the axis vector 155 * @param z The z component of the axis vector 156 * @param angle The angle around the axis 157 * 158 * To set the orientation, you have to specify the direction that the 159 * object should be facing with the vector (x, y, z) and the rotation 160 * of the object around this axis with 'angle', which has to be given 161 * in degrees, NOT radian. The vector does not have to be normalized. 162 */ 163 void setOrientation(std::string id, double x, double y, double z, double angle); 164 165 /** 166 * @brief Set the velocity of an object 167 * @param id The ID of the object 168 * @param x The velocity in x-direction 169 * @param y The velocity in y-direction 170 * @param z The velocity in z-direction 171 * 172 * The velocity is in units per second. 173 */ 174 void setVelocity(std::string id, double x, double y, double z); 175 176 /** 177 * @brief Set the angular velocity of an object 178 * @param id The ID of the object 179 * @param x The rotation velocity around the x-axis 180 * @param y The rotation velocity around the y-axis 181 * @param z The rotation velocity around the z-axis 182 */ 183 void setAngularVelocity(std::string id, double x, double y, double z); 184 185 // ### API END ################################################################ 142 186 143 187 /**
Note: See TracChangeset
for help on using the changeset viewer.