getPixelPosition method

List<double> getPixelPosition(
  1. Vector3 coords
)

Converts the manim coordinates (Vector3 coords) to the pixel coordinates The z component of coords is ignored. It returns a list of 2 double containing the x and y pixel coordinates

Implementation

List<double> getPixelPosition(Vector3 coords) {
  coords -= camera.frameCenter;

  // map pixelX which can be between 0 and pixelWidth
  // to between -frameWidth / 2 and frameWidth / 2
  // then the x coordinate of the frame center is added
  var px = mapValue(coords.x, -camera.frameWidth / 2, camera.frameWidth / 2,
      0, camera.pixelWidth);
  // same as the x coordinate except that the screen coordinates
  // and the manim coordinates have an inverted y axis
  var py = mapValue(coords.y, -camera.frameHeight / 2, camera.frameHeight / 2,
      camera.pixelHeight, 0);

  return [px, py];
}