From 3f8eadf8ccaf39fbdeaca51b60a0320e2feec434 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 17 May 2025 18:09:38 +0200 Subject: [PATCH] Added Root & new Thing ref. constructor --- Thing.cpp | 26 +++++++++++++++++++++----- Thing.h | 26 +++++++++++++++----------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Thing.cpp b/Thing.cpp index bbf82e3..67a704e 100644 --- a/Thing.cpp +++ b/Thing.cpp @@ -20,12 +20,28 @@ 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) { - // unsigned char thingId) { +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(); this->owner = owner; diff --git a/Thing.h b/Thing.h index 9045430..8247bc5 100644 --- a/Thing.h +++ b/Thing.h @@ -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 @@ -52,8 +51,8 @@ class Thing { /// @param thingId The ID of the thing, leave out or set to zero to generate /// an ID Thing(Participant* owner = nullptr, - unsigned char thingType = Type::Undetermined); - //unsigned char thingId = 0); + unsigned char thingType = Type::Undetermined); + // 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