Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Position of drawn pixels  (Read 1694 times)

0 Members and 1 Guest are viewing this topic.

Dajcok

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Position of drawn pixels
« on: May 29, 2020, 03:25:44 pm »
Hello,
I'm trying to create function which will check mousePosition in order to check if it collides with visible area of my object and if yes it will delete the object from an array. For example: If I go with cursor over some circle's outline(when I draw circle only outlines are enabled to be visible in my window) and then I click on the outline the circle will be deleted from my circle vector. It can be done trough sin and cos but it would be very uneficient since it would have to store position from every pixel in the perimeter of that circle for every circle I draw so I was wondering if there's is some kind of OpenGL or SFML function which can tell position of the pixels in circles outline so i can write som code like:

for(int i = 0; i < object.countOfDrawnPixels() /*<-- function that I am seeking for */; i++)
{
 if(object.getCoordinatesOfPixel.at(i) /*<-- also function that I am seeking for*/ == sf::Mouse::getPosition())
 {
   pixelTriggered = true;
 }
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Position of drawn pixels
« Reply #1 on: May 29, 2020, 04:39:00 pm »
Forget pixel tests for such simple geometrical primitives. Compute the distance between the mouse cursor and the circle center, and if it's close enough to the radius, then it's on.
Laurent Gomila - SFML developer

Dajcok

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: Position of drawn pixels
« Reply #2 on: May 30, 2020, 10:43:58 am »
Thanks very much, I didn't think about this possibility at all.  ;D