Added Root & new Thing ref. constructor

This commit is contained in:
Pascal Serrarens 2025-05-17 18:09:38 +02:00
parent 17de9db0be
commit 3f8eadf8cc
2 changed files with 36 additions and 16 deletions

View File

@ -20,11 +20,27 @@ namespace RoboidControl {
#pragma region Init
// Thing::Thing(unsigned char thingType)
// : Thing(IsolatedParticipant::Isolated(), thingType) {}
Thing Root = Thing(Thing::Type::Undetermined, Root);
Thing::Thing(Participant* owner,
unsigned char thingType) {
Thing::Thing(unsigned char thingType, Thing& parent) {
this->type = thingType;
this->position = Spherical::zero;
this->positionUpdated = true;
this->orientation = SwingTwist::identity;
this->orientationUpdated = true;
this->hierarchyChanged = true;
this->linearVelocity = Spherical::zero;
this->angularVelocity = Spherical::zero;
// std::cout << "add thing [" << (int)this->id << "] to owner "
// << this->owner->ipAddress << ":" << this->owner->port <<
// std::endl;
this->owner->Add(this, true);
}
Thing::Thing(Participant* owner, unsigned char thingType) {
// unsigned char thingId) {
if (owner == nullptr)
owner = IsolatedParticipant::Isolated();

24
Thing.h
View File

@ -41,10 +41,9 @@ class Thing {
};
#pragma region Init
static Thing Root; // = Thing(Type::Undetermined, Root);
/// @brief Create a new thing without communication abilities
/// @param thingType The type of thing (can use Thing::Type)
//Thing(unsigned char thingType = Type::Undetermined);
Thing(unsigned char thingType = Type::Undetermined, Thing& parent = Root);
/// @brief Create a new thing for a participant
/// @param owner The owning participant
@ -53,7 +52,7 @@ class Thing {
/// an ID
Thing(Participant* owner = nullptr,
unsigned char thingType = Type::Undetermined);
//unsigned char thingId = 0);
// unsigned char thingId = 0);
/// @brief Create a new child thing
/// @param parent The parent thing
@ -61,11 +60,14 @@ class Thing {
/// @param thingId The ID of the thing, leave out or set to zero to generate
/// an ID
/// @note The owner will be the same as the owner of the parent thing
Thing(Thing* parent, unsigned char thingType = 0); //, unsigned char thingId = 0);
Thing(Thing* parent,
unsigned char thingType = 0); //, unsigned char thingId = 0);
static Thing Reconstruct(Participant* owner, unsigned char thingType, unsigned char thingId);
static Thing Reconstruct(Participant* owner,
unsigned char thingType,
unsigned char thingId);
#pragma endregion Init
#pragma endregion Init
public:
/// @brief Terminated things are no longer updated
@ -201,9 +203,11 @@ class Thing {
/// parent's orientation
SwingTwist orientation;
/// @brief The linear velocity of the thing in local space, in meters per second
/// @brief The linear velocity of the thing in local space, in meters per
/// second
Spherical linearVelocity;
/// @brief The angular velocity of the thing in local space, in degrees per second
/// @brief The angular velocity of the thing in local space, in degrees per
/// second
Spherical angularVelocity;
#pragma endregion Pose
@ -216,7 +220,7 @@ class Thing {
static unsigned long GetTimeMs();
/// @brief Updates the state of the thing
//void Update(bool recursive = false);
// void Update(bool recursive = false);
/// @brief Updates the state of the thing
/// @param currentTimeMs The current clock time in milliseconds; if this is