-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New StaticObject
API
#107
New StaticObject
API
#107
Conversation
In few comments, `ros` was written instead of `rows`.
- Make `StaticObject` concrete (no pure virtuals). Allow subclasses to still change internal mechanics by keeping seters and getters virtual. - Make `StaticGate` nothing but a shorthand to spawn the "rpg_gate" asset. This also solves a shadowning issue. - Change `getPos` into `getPosition` (so that it matches formatting of `setPosition`). - Return `id_` and `prefab_id_` by const reference. - Updated `unity_bridge.cpp` to use the new API. - Updated `racing.cpp` (from the `flightros` pkg) to show and use the new API.
Make sure that sub-classes of `StaticObject` can change the pose and size of the object (by making the corresponding variables protected).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. A minor comment.
Thanks @yun-long for having reviewed the PR. Latest changes:
Also, sorry for all the formatting-related commits, I keep forgetting to run clang before committing... 😓 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Hello!
I want to propose this PR, which slightly changes how
StaticObject
s work.Motivation and main proposal
The motivation is the following: if I want to insert a new static object, I have to inherit from
StaticObject
and add fields to set/get its pose. This is exactly whatStaticGate
was doing. However, this would likely mean that to create a new static object I should "copy-paste"static_gate.hpp/cpp
and update it accordingly, e.g., by simply changing the class name. However, I think this should be discouraged since it is not very DRY.My proposal is thus the following: let's make all static objects behave like the static gate. This means that a
StaticObject
now features, in addition to theid_
andprefab_id_
fields, protected variables representing the pose of the object (as well as the size). This means that now to spawn different objects one simply needs to change theprefab_id
value passed to the constructor. Finally, theStaticGate
class now becomes a simple shorthand for callingStaticGate
's constructor with"rpg_gate"
asprefab_id
.Detailed description of the changes
StaticObject
The class
StaticObject
is now non-abstract and can be used directly to spawn any object that does not require simulation of its dynamics. It is, more or less, a copy of whatStaticGate
was before this PR. The main changes are the following:position_
,quat_
andscale_
. To access and modify them, the corresponding getters and setters were moved fromStaticGate
toStaticObject
. These methods are kept virtual, meaning that one can change how they behave if needed.getPosition
is now used instead ofgetPos
.getRotation
andsetRotation
have been changed intosetQuaternion
andgetQuaternion
to make code clearer.getID
andgetPrefabID
now returnconst std::string&
, i.e., by reference.StaticGate
Since its internal mechanics is now included into
StaticObject
, the class is now almost a "one-liner convenience class" that allows to shorten the creation of a gate as aStaticObject
:Given how simple its definition has become, I have removed
static_gate.cpp
and kept the full class definition insidestatic_gate.hpp
. Let me know if you prefer to separate declaration and implementation!Note that by making this class so minimal, a (potential) sub-issue has been also fixed: the private fields
id_
andprefab_id_
were both appearing inStaticObject
andStaticGate
. While this is not illegal, it was most likely unintended?UnityBridge
I simply updated its
.cpp
file so that it uses the new API. This simply means callinggetPosition()
instead ofgetPos()
andgetQuaternion()
instead ofgetQuat()
.race
executableIn
race.cpp
(from the packageflightros
) I have updated the instructions that spawn the gates to show that the same gate can be inserted using eitherStaticObject
orStaticGate
. I also added few lines to demonstrate that (and how) the position of aStaticObject
can be updated if needed.types.hpp
I just saw that "rows" was misspelled in three doc-comments. I simply corrected the word where needed: no code-change was performed!
Conclusion
I hope this PR helps improving Flightmare 😄 I am of course open to discussion after your reviews 👍