2 replies to this topic

### #1seiko

New Member

• Members
• 16 posts

Posted 25 November 2005 - 02:22 PM

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

### #2Reedbeta

DevMaster Staff

• 5308 posts
• LocationSanta Clara, CA

Posted 26 November 2005 - 09:45 AM

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 |
\--------\|


As you see, you don't even need any trig, just a bit of algebra.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #3Mattias Gustavsson

Senior Member

• Members
• 413 posts

Posted 26 November 2005 - 10:15 AM

One simple way of doing it is to define a cube (or several cubes?) for each building, and then call the D3DXMatrixShadow function, which calculates a matrix that projects geometry onto a plane, and then just render the cube with that matrix. As long as the shadow receiver is flat, this can produce very realistic shadows.

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users