RoboidControl-cpp/Sensor.cpp
2024-11-29 15:06:08 +01:00

41 lines
1015 B
C++

#include "Sensor.h"
#include "Roboid.h"
Sensor::Sensor() : Thing(0) { // for now, id should be set properly later
this->type = Thing::SensorType;
}
void Sensor::SetParent(Thing *parent) {
this->parent = parent;
if (this->parent->IsRoboid()) {
Roboid *roboidParent = (Roboid *)this->parent;
roboidParent->perception->AddSensor(this);
}
}
void Sensor::ConnectTo(Thing *oldThing) {
this->name = oldThing->name;
this->id = oldThing->id;
Thing *oldParent = oldThing->GetParent();
oldParent->RemoveChild(oldThing);
oldParent->AddChild(this);
for (int childIx = 0; childIx < oldThing->childCount; childIx++) {
Thing *child = oldThing->GetChild(childIx);
this->AddChild(child);
}
this->position = oldThing->position;
this->orientation = oldThing->orientation;
// delete (thing); // can we do this?
}
void Sensor::ConnectTo(Thing *rootThing, const char *thingName) {
Thing *thing = rootThing->FindChild(thingName);
if (thing != nullptr)
this->ConnectTo(thing);
}