Skip to content
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

Scale BaseAxis properly #88

Merged
merged 12 commits into from
May 29, 2020
45 changes: 42 additions & 3 deletions include/ignition/rendering/base/BaseAxisVisual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ namespace ignition
public: virtual ~BaseAxisVisual();

public: virtual void Init();

public: virtual void SetLocalScale(double _x, double _y, double _z) override;

public: virtual void SetLocalScale(double _scale) override;

public: virtual void SetLocalScale(const math::Vector3d &_scale) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to just override this version with math::Vector3d arg. The other two just calls this function so can be removed.


private: ArrowVisualPtr xArrow;

private: ArrowVisualPtr yArrow;

private: ArrowVisualPtr zArrow;
};

//////////////////////////////////////////////////
Expand All @@ -51,25 +63,52 @@ namespace ignition
{
}

//////////////////////////////////////////////////
template <class T>
void BaseAxisVisual<T>::SetLocalScale(double _x, double _y, double _z)
{
xArrow->SetLocalScale(_x, _y, _z);
yArrow->SetLocalScale(_x, _y, _z);
zArrow->SetLocalScale(_x, _y, _z);
}

//////////////////////////////////////////////////
template <class T>
void BaseAxisVisual<T>::SetLocalScale(double _scale)
{
xArrow->SetLocalScale(_scale, _scale, _scale);
yArrow->SetLocalScale(_scale, _scale, _scale);
zArrow->SetLocalScale(_scale, _scale, _scale);
}

//////////////////////////////////////////////////
template <class T>
void BaseAxisVisual<T>::SetLocalScale(const math::Vector3d &_scale)
{
xArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:

      for (unsigned int i = 0; i < this->ChildCount(); ++i)
        this->ChildByIndex(i)->SetLocalScale(_scale);

this way we don't need to declare the private xArrow, yArrow, zArrow variables

yArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z());
zArrow->SetLocalScale(_scale.X(), _scale.Y(), _scale.Z());
}

//////////////////////////////////////////////////
template <class T>
void BaseAxisVisual<T>::Init()
{
T::Init();

ArrowVisualPtr xArrow = this->Scene()->CreateArrowVisual();
xArrow = this->Scene()->CreateArrowVisual();
xArrow->SetLocalPosition(0, 0, 0);
xArrow->SetLocalRotation(0, IGN_PI / 2, 0);
xArrow->SetMaterial("Default/TransRed");
this->AddChild(xArrow);

ArrowVisualPtr yArrow = this->Scene()->CreateArrowVisual();
yArrow = this->Scene()->CreateArrowVisual();
yArrow->SetLocalPosition(0, 0, 0);
yArrow->SetLocalRotation(-IGN_PI / 2, 0, 0);
yArrow->SetMaterial("Default/TransGreen");
this->AddChild(yArrow);

ArrowVisualPtr zArrow = this->Scene()->CreateArrowVisual();
zArrow = this->Scene()->CreateArrowVisual();
zArrow->SetLocalPosition(0, 0, 0);
zArrow->SetLocalRotation(0, 0, 0);
zArrow->SetMaterial("Default/TransBlue");
Expand Down