Skip to content

Commit

Permalink
4 -> 5
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <louise@openrobotics.org>
  • Loading branch information
chapulina committed Oct 13, 2021
2 parents 6f3105b + 5e183b5 commit 1d0d22a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
7 changes: 4 additions & 3 deletions ogre2/src/Ogre2RayQuery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ RayQueryResult Ogre2RayQuery::ClosestPointBySelectionBuffer()
typeid(unsigned int))
{
auto userAny = ogreItem->getUserObjectBindings().getUserAny();
double pointLength = point.Length();
if (!std::isinf(pointLength))
double distance = this->dataPtr->camera->WorldPosition().Distance(point)
- this->dataPtr->camera->NearClipPlane();
if (!std::isinf(distance))
{
result.distance = pointLength;
result.distance = distance;
result.point = point;
result.objectId = Ogre::any_cast<unsigned int>(userAny);
}
Expand Down
14 changes: 11 additions & 3 deletions ogre2/src/media/materials/scripts/selection_buffer.material
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
*
*/

vertex_program selection_buffer_vs glsl
{
// reuse depth camera vertex shader
source depth_camera_vs.glsl
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
}
}

fragment_program selection_buffer_fs glsl
{
source selection_buffer_fs.glsl
Expand All @@ -34,9 +44,7 @@ material SelectionBuffer
pass
{
// Make this pass use the vertex shader defined above
vertex_program_ref DepthCameraVS
{
}
vertex_program_ref selection_buffer_vs { }

// Make this pass use the pixel shader defined above
fragment_program_ref selection_buffer_fs { }
Expand Down
37 changes: 30 additions & 7 deletions src/Utils_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void UtilTest::ClickToScene(const std::string &_renderEngine)

const int halfWidth = static_cast<int>(width / 2);
const int halfHeight = static_cast<int>(height / 2);
const ignition::math::Vector2i centerClick(halfWidth, halfHeight);
ignition::math::Vector2i centerClick(halfWidth, halfHeight);

RayQueryPtr rayQuery = scene->CreateRayQuery();
EXPECT_TRUE(rayQuery != nullptr);
Expand Down Expand Up @@ -117,23 +117,46 @@ void UtilTest::ClickToScene(const std::string &_renderEngine)
box->SetLocalScale(1.0, 1.0, 1.0);
root->AddChild(box);

root->AddChild(camera);
camera->Update();

// \todo(anyone)
// the centerClick var above is set to a screen pos of (width/2, height/2).
// This is off-by-1. The actual center pos should be at
// (width/2 - 1, height/2 - 1) so the result.X() and result.Y() is a bit off
// from the expected position. However, fixing the centerClick above caused
// the screenToPlane tests to fail so only modifying the pos here, and the
// cause of test failure need to be investigated.
centerClick = ignition::math::Vector2i(halfWidth-1, halfHeight-1);

// API without RayQueryResult and default max distance
result = screenToScene(centerClick, camera, rayQuery, rayResult);

EXPECT_NEAR(0.5, result.Z(), 1e-10);
if (_renderEngine == "ogre2")
{
// tests using selection buffer fail on CI, see issue #170
// https://github.com/ignitionrobotics/ign-rendering/issues/170
igndbg << "Selection buffer based screenToScene test is disabled in "
<< _renderEngine << "." << std::endl;
return;
}

// high tol is used for z due to depth buffer precision.
// Do not merge the tol changes forward to ign-rendering6.
EXPECT_NEAR(0.5, result.Z(), 1e-3);
EXPECT_NEAR(0.0, result.X(), 2e-6);
EXPECT_NEAR(0.0, result.Y(), 2e-6);
EXPECT_TRUE(rayResult);
EXPECT_NEAR(14.5 - camera->NearClipPlane(), rayResult.distance, 4e-6);
EXPECT_NEAR(14.5 - camera->NearClipPlane(), rayResult.distance, 1e-3);
EXPECT_EQ(box->Id(), rayResult.objectId);

result = screenToScene(centerClick, camera, rayQuery, rayResult, 20.0);

EXPECT_NEAR(0.5, result.Z(), 1e-10);
EXPECT_NEAR(0.5, result.Z(), 1e-3);
EXPECT_NEAR(0.0, result.X(), 2e-6);
EXPECT_NEAR(0.0, result.Y(), 2e-6);
EXPECT_TRUE(rayResult);
EXPECT_NEAR(14.5 - camera->NearClipPlane(), rayResult.distance, 4e-6);
EXPECT_NEAR(14.5 - camera->NearClipPlane(), rayResult.distance, 1e-3);
EXPECT_EQ(box->Id(), rayResult.objectId);

// Move camera closer to box
Expand All @@ -142,11 +165,11 @@ void UtilTest::ClickToScene(const std::string &_renderEngine)

result = screenToScene(centerClick, camera, rayQuery, rayResult);

EXPECT_NEAR(0.5, result.Z(), 1e-10);
EXPECT_NEAR(0.5, result.Z(), 1e-3);
EXPECT_NEAR(0.0, result.X(), 2e-6);
EXPECT_NEAR(0.0, result.Y(), 2e-6);
EXPECT_TRUE(rayResult);
EXPECT_NEAR(6.5 - camera->NearClipPlane(), rayResult.distance, 4e-6);
EXPECT_NEAR(6.5 - camera->NearClipPlane(), rayResult.distance, 1e-4);
EXPECT_EQ(box->Id(), rayResult.objectId);
}

Expand Down

0 comments on commit 1d0d22a

Please sign in to comment.