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
- Silvester Schneidt asked 1 year ago
- last edited 1 year ago
-
Is there any suggestion?
- You must login to post comments
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
- Lex answered 1 year ago
- You must login to post comments
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
- Silvester Schneidt answered 1 year ago
- You must login to post comments
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?
- Silvester Schneidt answered 9 months ago
- last edited 9 months ago
- You must login to post comments
Please login first to submit.