I'm using View3D PointLineSeries3D and I'd like to get the x,y, z values under the mouse, not the screen coordinates.
I saw the example for ViewXY, but that doesn't seem work for the View3D.
Any help would be appreciated. Thanks!
Convert Screen Coordinates to Axis Values: View3D
Moderator: Queue Moderators
- blakeadkins
- Posts: 44
- Joined: Tue Feb 25, 2014 7:49 pm
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Convert Screen Coordinates to Axis Values: View3D
Hi,
under the mouse, there's infinite count of positions (a vector from mouse towards the screen), and therefore 2D coordinate can't be directly converted into 3D coordinate. Are you looking for a method that solves the nearest point in PointLineSeries3D?
under the mouse, there's infinite count of positions (a vector from mouse towards the screen), and therefore 2D coordinate can't be directly converted into 3D coordinate. Are you looking for a method that solves the nearest point in PointLineSeries3D?
LightningChart Support Team, PT
- blakeadkins
- Posts: 44
- Joined: Tue Feb 25, 2014 7:49 pm
Re: Convert Screen Coordinates to Axis Values: View3D
Yeah, that might work.
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Convert Screen Coordinates to Axis Values: View3D
In MouseMove or MouseClick event handler, seek it like this. Indicate the nearest point with another PLS3D with only one point as a marker.
Here, the nearest point is indicated with the lime box.
Code: Select all
private void chart_MouseMove(object sender, MouseEventArgs e)
{
Point mouseScreen = e.GetPosition(m_chart);
//Seek from data series
int iNearestIndex = GetNearestIndexToMouse(m_chart.View3D.PointLineSeries3D[0], mouseScreen.X, mouseScreen.Y);
if (iNearestIndex >= 0)
{
PointDouble3D nearestPoint = m_chart.View3D.PointLineSeries3D[0].Points[iNearestIndex];
m_chart.BeginUpdate();
//Create another PointLineSeries to show the nearest point with a box.
if(m_chart.View3D.PointLineSeries3D.Count < 2)
{
PointLineSeries3D marker = new PointLineSeries3D(m_chart.View3D, Axis3DBinding.Primary, Axis3DBinding.Primary, Axis3DBinding.Primary);
marker.PointStyle.Shape = PointShape3D.Box;
marker.PointStyle.Size.SetValues(4, 4, 4);
marker.Material.DiffuseColor = Color.Lime;
marker.MouseInteraction = false;
m_chart.View3D.PointLineSeries3D.Add(marker);
}
m_chart.View3D.PointLineSeries3D[1].Points = new PointDouble3D[] { nearestPoint };
m_chart.EndUpdate();
}
}
int GetNearestIndexToMouse(PointLineSeries3D pls, double mouseX, double mouseY)
{
PointDouble3D[] points = pls.Points;
int iPointCount = pls.PointCount;
PointInt p;
double dMinDistSq = double.MaxValue;
int iNearestIndex = -1;
double dDistSq;
double x, y;
//Seek nearest point, by using squared method. It's faster than calling Sqrt every time.
for(int i=0;i<iPointCount;i++)
{
p = m_chart.View3D.ConvertSeriesValueToScreenCoord(pls, points[i].X, points[i].Y, points[i].Z);
x = (double) p.X;
y = (double) p.Y;
dDistSq = (y - mouseY) * (y - mouseY) + (x - mouseX) * (x - mouseX);
if (dDistSq < dMinDistSq)
{
dMinDistSq = dDistSq;
iNearestIndex = i;
}
}
return iNearestIndex;
}
LightningChart Support Team, PT
- blakeadkins
- Posts: 44
- Joined: Tue Feb 25, 2014 7:49 pm
Re: Convert Screen Coordinates to Axis Values: View3D
Is there a way to always grab the closest point to the viewer?
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Convert Screen Coordinates to Axis Values: View3D
Kind of. But the mouse must be right over a point.
PointLineSeries3D_0: a polyline, going through all the N points. LineVisible = true, PointsVisible = false, MouseInteraction = false.
PointLineSeries3D_1 ... PointLineSeries3D_N : A series for each point separately. LineVisible = false, PointsVisible = true, Title.ShowInLegendBox = false. Set MouseOverOn/MouseClick event handler for every series. The event handler will launch only for the series that is nearest to camera.
PointLineSeries3D_0: a polyline, going through all the N points. LineVisible = true, PointsVisible = false, MouseInteraction = false.
PointLineSeries3D_1 ... PointLineSeries3D_N : A series for each point separately. LineVisible = false, PointsVisible = true, Title.ShowInLegendBox = false. Set MouseOverOn/MouseClick event handler for every series. The event handler will launch only for the series that is nearest to camera.
LightningChart Support Team, PT
- blakeadkins
- Posts: 44
- Joined: Tue Feb 25, 2014 7:49 pm
Re: Convert Screen Coordinates to Axis Values: View3D
Thanks! Does what I needed.