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

Author Topic: How to calculate a field of view?  (Read 2944 times)

0 Members and 1 Guest are viewing this topic.

jdm1891

  • Newbie
  • *
  • Posts: 17
    • View Profile
How to calculate a field of view?
« on: December 12, 2016, 09:40:19 pm »
This isn't really an SFML question, more of an algorithm/physics one. I'm wondering how I would be able to make a 'field of view' for a top down player. More specifically, This is how I think I would do it:


  • Draw aseries of lines between two angles on each side of the player until it hits a solid object
  • Change the colour of/brighten everything between these lines(like a flashlight)

The problem with the above is:
I don't know how I would get all the pixels between the lines, and I'm not sure how I would draw a lines that are stopped when it hits a pixel which is 'solid'(Or how I would add this property to all the pixels).

A baldy drawn example of the effect I'm trying to achive here:  http://imgur.com/a/9NDBq

Any help
« Last Edit: December 12, 2016, 09:48:51 pm by jdm1891 »

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile

jdm1891

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: How to calculate a field of view?
« Reply #2 on: December 12, 2016, 09:49:49 pm »
This is exactly what I wanted, thanks!

jdm1891

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: How to calculate a field of view?
« Reply #3 on: December 12, 2016, 10:00:17 pm »
After I read it, I still have a question: How would I detect the corners of objects?

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: How to calculate a field of view?
« Reply #4 on: December 13, 2016, 02:53:05 pm »
The corners of the objects are essentially the vertices of the polygon representing the object.
For instance, if you use sf::ConvexShape, vertices are the respective points you set with the setPoint() method.

 

anything