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 active 9 months ago