Talk:Field of Vision

From RogueBasin
Revision as of 06:37, 12 June 2008 by Gbox (Talk | contribs)

Jump to: navigation, search

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)

Simple and accurate LOS function

'// 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
Personal tools