Pre loader

3D Selection modifier to select point nearest to mouse pointer

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

Hello SciChart team,

I wanted to implement 3DSelectionModifier that should select a point closest to the mouse pointer per mouse click.

To do this, I create a rectangle with a clicked point in the center with a mouse click and use the PickScene method of the ViewPort3D object.

List<EntityVertexId>? entityVertexIds = Viewport3D.PickScene(mousePoint.ToRectCenter(30));

Depending on the camera angle It can of course happen that several points appear in the scene. In this case I wanted to do the following:

for each determined point in 3D space, determine its 2D screen coordinates

HitTestInfo3D hitTestInfo = new HitTestInfo3D() { IsHit = true, EntityId = entityVertexId.EntityId, VertexId = entityVertexId.VertexId };
SeriesInfo3D? seriesInfo = pointsEntity.ToSeriesInfo(hitTestInfo);
//Vector3D hitVertex = seriesInfo.HitVertex; 
Vector3 vertex = seriesInfo.HitVertexCoords; 
Point point1 = ParentSurface.Camera.WorldToScreenSpace(vertex); 

Determine the distance between the point of the mouse and the 2D coordinates of the point from the scene

double newDistance = PointUtil.Distance(mousePoint, point1);

Select the point with the shortest distance.

if (distance.IsNaN() || newDistance < distance) 
{   
  distance = newDistance;   
  nearestSeriesInfo3D = seriesInfo; 
}

During the implementation I encountered the following problem:
I used following camera object method first

Point p = ParentSurface.Camera.WorldToScreenSpace(vertex);

but this gave me no plausible point.
The other method

Point p = ParentSurface.Camera.LocalCoordinateToScreenSpace(vertex);

also seemed to return a point that returned the wrong value when calculating the distance, so the wrong point was selected.

If I try to click the data point directly, I expect at least one of the methods to return a point very very close to the mouse pointer. However, both methods gave me a point on the screen (see screenshot) that did not match the mouse point.

Maybe I’m missing a step or transformation. Could you explain me what I’m doing wrong?

Example project is attached

Version
6.6.0.26505
Images
  • You must to post comments
0
0

Hello Silvester,

Thanks for your inquiry. We are sorry for the late reply.
Please take a look at the implementation shown in our “3DScatterChart_DragPointModifier” sandbox example. Here is a link:
https://github.com/ABTSoftware/SciChart.Wpf.Examples/tree/master/Sandbox/CustomerExamples/3DScatterChart_DragPointModifier

Is this what you are looking for?

With best regards,
Lex
SciChart Technical Support Engineer

  • You must to post comments
0
0

Hey Lex,

Could you help me out with something? I’m not looking to move the point markers, but rather to select a point with a simple click of the mouse. Our markers need to be small, so we need to implement a selection modifier that will choose the closest marker to the mouse click.

I’ve attached an example project to demonstrate my issue and have also explained the key points in this thread. The problem I’m facing is with converting a 3D point to 2D. I’ve already gone through all the sample projects and forum posts related to this topic, but still haven’t been able to find a solution.
Any help you can provide would be greatly appreciated!

Best regards
Silvester

  • You must to post comments
0
0

Additional Information:
Our data point markers need to be small because our 3D windows can also be tiny.
So, sometimes it’s really tricky for customers to click on the data points accurately.

I had this idea of implementing a DataPointSelectionModifier that would select the closest data point to the mouse pointer when clicked.
I defined a small selection rectangle around the mouse point and used Viewport3D.PickScene to find the data point markers within that rectangle. However, when converting world coordinates to screen coordinates using ParentSurface.Camera.WorldToScreenSpace(vertex), the Y value I get is measured from the bottom edge of the control. On the other hand, the Y value of the Mouse Point is determined from the top edge of the control. So, the distance to the points is calculated incorrectly, resulting in the wrong point being selected.

I’m not sure if I’m missing a transformation somewhere or if it’s a bug in the convert method. I even tried calculating the y-value of the point with given y-value from bottom and height of the RootGrid, but it didn’t give me accurate results, and the next point often wasn’t selected correctly.

Do you think it’s possible to determine the 2D point such precisely?

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies