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\$
  • \$\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 '14 at 20:37
  • \$\begingroup\$ Sweet, especially as we're using JS/ Canvas here. Thanks!! \$\endgroup\$ – Philipp Lenssen Feb 7 '14 at 20:48
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\$
  • \$\begingroup\$ I'm not sure i understand, how do you determine the locations of the scaled blocks? \$\endgroup\$ – ThatOneGuy Feb 8 '14 at 14:17
  • \$\begingroup\$ I just scaled with the eye position as the origin. \$\endgroup\$ – Arne Feb 9 '14 at 13:30
  • \$\begingroup\$ Ah ofcourse, that makes sense. \$\endgroup\$ – ThatOneGuy Feb 9 '14 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\$
  • \$\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 '14 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 '14 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.