1
\$\begingroup\$

Given a 2D sideview with even-sized grid squares and our hero in a known center-ish position like this

enter image description here

... and imagining this hero's line of sight like this...

enter image description here

how could one get the point values needed for the black overlay polygons as shown here? Thanks!

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Though it doesn't directly answer the question, and the page describes 2D lighting, I think the following page me be of help (particularly the bottom part): greweb.me/2012/05/… \$\endgroup\$
    – Lysol
    Feb 7, 2014 at 20:37
  • \$\begingroup\$ Sweet, especially as we're using JS/ Canvas here. Thanks!! \$\endgroup\$ Feb 7, 2014 at 20:48

2 Answers 2

3
\$\begingroup\$

you can do the simple scaling trick.

yea too lazy to explain, just look at the image and ask if you don't understand

In this example I just scaled by a factor of 2. Higher values give longer shadows.

alt text

\$\endgroup\$
3
  • \$\begingroup\$ I'm not sure i understand, how do you determine the locations of the scaled blocks? \$\endgroup\$
    – ThatOneGuy
    Feb 8, 2014 at 14:17
  • \$\begingroup\$ I just scaled with the eye position as the origin. \$\endgroup\$
    – Arne
    Feb 9, 2014 at 13:30
  • \$\begingroup\$ Ah ofcourse, that makes sense. \$\endgroup\$
    – ThatOneGuy
    Feb 9, 2014 at 19:00
1
\$\begingroup\$

I think you will need raycasting or walltracking to solve this.

This link might help you out. It shows the basic idea behind raycasting and walltracking with some interactive examples.

edit 1: changed raytracing to raycasting on first line, comment pointed out my brainfart

edit 2: Only use raycasting on the corners of your square, the rest can be interpolated. No need to cast endless amount of rays.

\$\endgroup\$
2
  • \$\begingroup\$ I think you mean raycasting. Raytracing is used for computer graphics to create ultra realistic images, although it can take a very long time. I get what you mean though :) \$\endgroup\$
    – Lysol
    Feb 7, 2014 at 22:25
  • \$\begingroup\$ no you don't need raycasting. And I wouldn't recommend raycasting since a lot of rays would be required. \$\endgroup\$
    – Arne
    Feb 8, 2014 at 2:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .