0
101 Nov 25, 2005 at 14:22

I’m creating an over head 2d scroller and use quads to represent buildings. I want to now simulate a buildings shadow cast by using anothr quad. This quad will simply be alpha blended to the scene. Question is how can I calculate the shadow quad so it is rotated and sized correctly dependant on the lights position, quads position and height. Obviously the 2d quad doesn’t have a height but I can add the variable from else where as this will be determined by artistic flare ;)

As it’s 2d albeit using a 3d engine I’m hoping that I can call upon some basic trig and just to be clear I’m not after a super precise shadow with soft edges etc. I just want the shadow to flare out from the buildings base at the correct angles so it won’t be enough just to rotate the original quad.

Many thanks

#### 2 Replies

0
165 Nov 26, 2005 at 09:45

I think you will not be able to draw a single shadow quad, but rather a quad for each edge (wall) of the building. If your buildings are represented by rectangles, and let’s say the light is coming from the top left, then you need to draw a shadow quad each for the right and bottom edges (i.e. the ones facing away from the light). You simply take each edge, translate it away from the light by an amount proportional to the height, connect the vertices of the original edge to the vertices of the translated one, and you’re done.

An attempt at ASCII-art to show what I mean:

\ light direction
\

|--------|\
|        |s\
|building|h \
|        |a |
|--------|d |
\        \2 |