Conversion matrix returns incorrect values

Hey all,

I need some help on an issue I am facing. I am trying to have a temporary circle follow my mouse, but I am finding after some point there is a distance between the circle and my mouse. After all my investigation, all I can find is that the converted point seems to be wrong.

Here’s what my code looks like.

void OnMouseMove( UINT nFlags, CPoint point )
{
   SetTempPinPos( point );
}

void SetTempPinPos( CPoint const& tempPinPos )
{
  PixelToWorld( tempPinPos, tempPinPosInWorld );
  DrawPin( tempPinPosInWorld ); //Draws a circle with the center being at that point, not adding that in
}

bool PixelToWorld( CPoint const& point, PointDataType<double> & convertedPoint ) const
{
  HPS::Point pointInPixel( point.x, point.y, 0 );
  auto res { Convert( HPS::Coordinate::Space::Pixel, HPS::Coordinate::Space::World, pointInPixel, convertedPoint ) };
  if( res )
  {
    convertedPoint = RestorePoint( PointDataType<double>( convertedPoint.x, convertedPoint.y, convertedPoint.z ) );
  }
  return res;
}

bool Convert( HPS::Coordinate::Space spaceIn,
              HPS::Coordinate::Space spaceOut,
              HPS::Point      const& point,
              PointDataType<double>& convertedPoint ) const
{
  HPS::Point transformedPoint {};
  auto sprkPath { HPS::SprocketPath( m_canvas,
                                     m_canvas.GetAttachedLayout(),                                  
m_canvas.GetAttachedLayout().GetAttachedView(),
                                     m_model ) };
  auto res { sprkPath.GetKeyPath().ConvertCoordinate( spaceIn, point, spaceOut, transformedPoint ) };

  convertedPoint.x = transformedPoint.x;
  convertedPoint.y = transformedPoint.y;
  convertedPoint.z = transformedPoint.z;

  return res;
}

PointDataType<double> RestorePoint( PointDataType<double> const& point ) const
{
  return PointDataType<double>( point.x + m_origin.x,
                                point.y + m_origin.y,
                                point.z + m_origin.z );
// We use a origin to reduce the value of these points, we use geomatic coordinates so they can get quite big
}

Any help is greatly appreciated on why the circle we draw seems to be offset from the mouse.

Hello @amaan.makhani,

Nothing particular jumps out as being the cause of the mismatched position of the circle and mouse pointer. That said, the code for DrawPin() and the value for m_origin is not provided.

At what point does the distance become noticeable? Is the circle and mouse aligned at the center of the screen if the mouse pointer is at the center of the screen? If not, I think that could be starting point on where to debug as (pixel height / 2, pixel width / 2) should be the origin (0, 0, 0) in world space.

Thanks,
Tino