Field of Vision formulas

Progress reports and musings from the developers on the current gaming tools.

Moderators: dorpond, trevor, Azhrei

Post Reply
webdev
Kobold
Posts: 2
Joined: Fri Feb 18, 2011 8:50 am

Field of Vision formulas

Post by webdev »

Hi,

i'm an italian web developer, and i'm trying to create a 2d grid map with field of vision in Javascript using HTML5 "canvas" element.
I know, Javascript is not the best performing language for this scope, but it's the only one i know (other than PHP).
MapTool is a fantastic application and inspired me, so i thought "MapTool is an opensource project, maybe i can ask for some little help in its forum!"
In fact, using MapTool this example works: http://homepage.mac.com/guyf/DDM/LOSNot ... orner.html

The only difference with MapTool that i want introduce is: when a cell is partially visible, i want show all the cell's area, not only the visibile portion.

Is raycasting the best solution? Does MapTool use raycasting? Or some other algorithm? I found this, do you think is it useful?
http://roguebasin.roguelikedevelopment. ... ligloscode

THANKS!!!

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Field of Vision formulas

Post by Azhrei »

(Moved to the developer forum since this isn't an Idea for New Applications that the RPTools team might develop.)

I can't answer the question about "how does MapTool do vision" as I've never looked at that section of code. However, I believe it does use raycasting with some optimizations. For example, the VBL drawn in MapTool is a vector-based system and the raycasting determines that there is VBL between point A and point B, so anything beyond that is not visible, hence the raycasting algorithm doesn't need to check beyond that area. That significantly speeds things up since MT can create a Java "Area" object and constrain it (i.e. clip it) based on the VBL.

I believe that Java actually passes that information to the next layer down in the graphics hierarchy and with the correct drivers, it may be the hardware that does the actual work. For example, OpenGL or DirectX may be doing the actual work.

In any case, you're right about MT being open source. If you choose to look at the source code, you can start with Zone.renderZone(). That's the top-level routine that renders a map. Somewhere in that function is a call to renderTokens() (or something similar) which draws the token and it's vision area. That should give you a starting point for where to look -- I don't recall that class name(s) off-hand because I just don't deal with that part of the code.

webdev
Kobold
Posts: 2
Joined: Fri Feb 18, 2011 8:50 am

Re: Field of Vision formulas

Post by webdev »

Thank you for reply, it's a good starting point for me :)
But I don't know Java and i might have trouble looking through the code.
Someone can post here some conceptual formulas, or java function, or material that might help?
Thanks!

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Field of Vision formulas

Post by Azhrei »

Try taking a look here: http://www.java-gaming.org/index.php?topic=21301.0;wap2

There are links to other resources regarding line of sight-type algorithms. If nothing else, that discussion (and the related ones) will give you keywords you can type into Google. ;)

Post Reply

Return to “Developer Notes”