Talk:Field of Vision

From RogueBasin
(Difference between revisions)
Jump to: navigation, search
(Simple and accurate LOS function)
(Added a couple of notes for Gbox, and pointed at the new article.)
 
(One intermediate revision by one user not shown)
Line 3: Line 3:
 
:As I understand it, field of vision is an algorithm for determining everything is visible. Line of sight is about determining whether a particular square is visible. The former can be created with the latter, but it may be inefficient to do it that way. [[User:Duerig|Duerig]] 20:44, 23 Apr 2007 (CEST)
 
:As I understand it, field of vision is an algorithm for determining everything is visible. Line of sight is about determining whether a particular square is visible. The former can be created with the latter, but it may be inefficient to do it that way. [[User:Duerig|Duerig]] 20:44, 23 Apr 2007 (CEST)
  
== Simple and accurate LOS function ==
+
Gbox, I have moved your code. It needs its own article rather than being hidden in a talk page somewhere. It is now its own article ([[Simple and accurate LOS function for BlitzMax]]), linked through the [[Ray casting]] page because it belongs to that general class of algorithms. You might want to expand your article a bit to provide an explanation of your design decisions and its performance and such rather than just have the code. You could also note that the number of rays is a parameter allowing accuracy to be traded off against speed. I like the fact that you use raw angles to determine the rays rather than iterating through the points on the edge of the field of view or something similar. That reduces the number of artifacts, especially near the cardinal directions. [[User:Duerig|Duerig]] 07:36, 12 June 2008 (CEST)
 
+
<pre><nowiki>
+
'// Code is [http://www.Blitzbasic.com BlitzMax]
+
 
+
Function UpdateLOS(m:tMonster, UpdateMap:Int = True)
+
If m = Null Then RuntimeError("Null in LOScheck!")
+
Local XX:Int, YY:Int '// Clear LOS flag from previous //
+
For xx = 0 To MAPWIDTH - 1
+
For yy = 0 To MAPHEIGHT - 1
+
If Map[xx, yy].InLOS = True Then
+
Map[xx, yy].HasSeen = True '// HasSeen cells are marked dark
+
Map[xx, yy].InLOS = False
+
EndIf
+
Next
+
Next
+
 
+
For Local angle:Float = 1 To 360 Step 0.18 '// fractional amount gives better resolution [0.1 causes sight though doors, > 0.2 creates gaps. 0.18 seems the sweet spot
+
Local dist:Int = 0
+
Local x:Float = Float(m.X) + 0.5 '//M.x and M.y are player/monster current map location
+
Local y:Float = Float(m.y) + 0.5
+
Local xmove:Float = Cos(angle)
+
Local ymove:Float = Sin(angle)
+
+
Repeat
+
x = x + xmove
+
y = y + ymove
+
dist = dist + 1
+
If dist >= m.Vision Then Exit  '// M.vision is the range of sight
+
If X >= MAPWIDTH Then Exit
+
If y >= MAPHEIGHT Then Exit
+
If x < 0 Then Exit
+
If y < 0 Then Exit
+
Map[x, y].InLOS = True
+
If Map[x, y].BlockVision Then Exit '// Map[,].Blockvision is for walls/closed doors ect
+
Forever
+
Next
+
 
+
End Function
+
</nowiki></pre>
+

Latest revision as of 07:51, 12 June 2008

Anyone cares to clarify what is the difference between Field of Vision and Line of Sight??? --Slash 18:08, 8 Apr 2006 (CEST)

As I understand it, field of vision is an algorithm for determining everything is visible. Line of sight is about determining whether a particular square is visible. The former can be created with the latter, but it may be inefficient to do it that way. Duerig 20:44, 23 Apr 2007 (CEST)

Gbox, I have moved your code. It needs its own article rather than being hidden in a talk page somewhere. It is now its own article (Simple and accurate LOS function for BlitzMax), linked through the Ray casting page because it belongs to that general class of algorithms. You might want to expand your article a bit to provide an explanation of your design decisions and its performance and such rather than just have the code. You could also note that the number of rays is a parameter allowing accuracy to be traded off against speed. I like the fact that you use raw angles to determine the rays rather than iterating through the points on the edge of the field of view or something similar. That reduces the number of artifacts, especially near the cardinal directions. Duerig 07:36, 12 June 2008 (CEST)

Personal tools