-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create arrow class and move it to selected lane
- Loading branch information
Showing
7 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2018 Toyota Research Institute | ||
|
||
#include "arrow_mesh.hh" | ||
#include <ignition/common/MeshManager.hh> | ||
#include <ignition/math/Helpers.hh> | ||
#include <ignition/rendering/Material.hh> | ||
#include <ignition/rendering/Mesh.hh> | ||
#include <ignition/rendering/Scene.hh> | ||
|
||
namespace delphyne { | ||
namespace gui { | ||
|
||
ArrowMesh::ArrowMesh(ignition::rendering::ScenePtr& _scene, double _zOffset, double _scaleFactor) | ||
: zOffset(_zOffset), | ||
scaleFactor(_scaleFactor), | ||
distanceToMove(zOffset / 4.0), | ||
step(0.005), | ||
totalTicks(distanceToMove / step), | ||
currentTick(0), | ||
currentDirection(-1) { | ||
ignition::rendering::MaterialPtr material = _scene->CreateMaterial(); | ||
material->SetDiffuse(255.0, 0.0, 0.0, 1.0); | ||
material->SetAmbient(255.0, 0.0, 0.0, 1.0); | ||
this->arrow = _scene->CreateVisual(); | ||
this->arrow->AddGeometry(_scene->CreateCone()); | ||
this->arrow->SetMaterial(material); | ||
this->arrow->SetVisible(false); | ||
this->arrow->SetWorldPosition(0., 0., 0.); | ||
this->arrow->SetWorldRotation(0, IGN_PI, 0.); | ||
_scene->RootVisual()->AddChild(this->arrow); | ||
ignition::common::MeshManager* meshManager = ignition::common::MeshManager::Instance(); | ||
const ignition::common::Mesh* unitConeMesh = meshManager->MeshByName("unit_cone"); | ||
minArrowBoundingBox = unitConeMesh->Min(); | ||
} | ||
|
||
void ArrowMesh::SelectAt(double _distanceFromCamera, const ignition::math::Vector3d& _worldPosition) { | ||
const double scaleIncrement = 1.0 + scaleFactor * _distanceFromCamera; | ||
const double newMinArrowBBZAxis = scaleIncrement * minArrowBoundingBox.Z(); | ||
this->arrow->SetWorldScale(scaleIncrement, scaleIncrement, scaleIncrement); | ||
this->arrow->SetWorldPosition(_worldPosition.X(), _worldPosition.Y(), | ||
_worldPosition.Z() + std::abs(newMinArrowBBZAxis) + zOffset); | ||
currentDirection = -1; | ||
currentTick = 0; | ||
} | ||
|
||
void ArrowMesh::SetVisibility(bool _visible) { this->arrow->SetVisible(_visible); } | ||
|
||
void ArrowMesh::Update() { | ||
ignition::math::Vector3d worldPosition = this->arrow->WorldPosition(); | ||
this->arrow->SetWorldPosition(worldPosition.X(), worldPosition.Y(), worldPosition.Z() + currentDirection * step); | ||
if (currentTick++ == totalTicks) { | ||
currentDirection = currentDirection * -1; | ||
currentTick = 0; | ||
} | ||
} | ||
|
||
} // namespace gui | ||
} // namespace delphyne |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2018 Toyota Research Institute | ||
|
||
#ifndef DELPHYNE_GUI_ARROW_MESH_HH | ||
#define DELPHYNE_GUI_ARROW_MESH_HH | ||
|
||
#include <ignition/math/Vector3.hh> | ||
#include <ignition/rendering/Scene.hh> | ||
|
||
namespace delphyne { | ||
namespace gui { | ||
|
||
/// \brief Renders a cone which will act as a pointing arrow when the user clicks over a lane | ||
class ArrowMesh { | ||
public: | ||
/// \brief Creates a cone and adds it as a child to the RootVisual of the scene, which will move | ||
/// upwards and downwards for a fixed amount of ticks. | ||
/// \param[in] _scene Scene pointer to create the cone. | ||
/// \param[in] _zOffset Units above the pointed object that the cone tip should be. | ||
/// \param[in] _scaleFactor Factor to increase/decrease the scale of the arrow based on the distance from the camera | ||
/// to the clicked position. | ||
ArrowMesh(ignition::rendering::ScenePtr& _scene, double _zOffset = 2.0, double _scaleFactor = 0.025); | ||
/// \brief Destructor. | ||
~ArrowMesh() = default; | ||
|
||
/// \brief Moves the arrow to a given world position and resets the downwards movement. | ||
/// \param[in] _distanceFromCamera How far the camera is from the clicked point. | ||
/// \param[in] _worldPosition World position of the cursor ray cast click. | ||
void SelectAt(double _distanceFromCamera, const ignition::math::Vector3d& _worldPosition); | ||
|
||
/// \brief Toggles the visibility of the arrow. | ||
/// \param[in] _visible Boolean that determines if the arrow should be visible or not. | ||
void SetVisibility(bool _visible); | ||
|
||
/// \brief Updates the position of the arrow moving slightly the z axis. | ||
void Update(); | ||
|
||
private: | ||
/// \brief Bounding box of the cone in construction time. | ||
ignition::math::Vector3d minArrowBoundingBox; | ||
|
||
/// \brief Visual pointer of the created cone. | ||
ignition::rendering::VisualPtr arrow; | ||
|
||
/// \brief Units that the tip of the cone should be from the clicked position. | ||
const double zOffset; | ||
/// \brief Factor to increase/decrease the size of the cone. | ||
const double scaleFactor; | ||
/// \brief Distance to move downwards/upwards. | ||
const double distanceToMove; | ||
/// \brief How much units should the arrow move downwards/upwards per tick. | ||
const double step; | ||
/// \brief How much ticks required to move the arrow from down to up or up to down. | ||
const int totalTicks; | ||
/// \brief How many ticks passed since it started moving. | ||
int currentTick; | ||
/// \brief Tells the arrow if it should move upwards (1) or downwards (-1). | ||
int currentDirection; | ||
}; | ||
} // namespace gui | ||
} // namespace delphyne | ||
|
||
#endif // DELPHYNE_GUI_ARROW_MESH_HH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters