FindChild by name

This commit is contained in:
Pascal Serrarens 2024-11-15 17:06:13 +01:00
parent f1a6ea29c4
commit 4ebe38eb39
2 changed files with 18 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#include "Thing.h"
#include <string.h>
using namespace Passer::RoboidControl;
Thing::Thing(unsigned char id) : id(id) {
@ -93,6 +95,21 @@ Thing *Passer::RoboidControl::Thing::RemoveChild(Thing *child) {
return child;
}
Thing *Thing::FindChild(const char *name) {
for (unsigned char childIx = 0; childIx < this->childCount; childIx++) {
Thing *child = this->children[childIx];
if (child == nullptr)
continue;
if (strcmp(child->name, name) == 0)
return child;
Thing *foundChild = child->FindChild(name);
if (foundChild != nullptr)
return foundChild;
}
return nullptr;
}
Spherical16 Thing::GetLinearVelocity() { return this->linearVelocity; }
Spherical16 Thing::GetAngularVelocity() { return this->angularVelocity; }

View File

@ -85,6 +85,7 @@ public:
/// or the child could not be found
Thing *GetChild(unsigned char childIx);
Thing *RemoveChild(Thing *child);
Thing *FindChild(const char *name);
/// @brief Sets the location from where the 3D model of this Thing can be
/// loaded from