This topic is 3080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm rendering an isometric world in two dimensions. Each object has an x coordinate a y coordinate and a z coordinate, though. The objects actual position on the screen is represented (x, y + z*ZHEIGHT) where ZHEIGHT is a constant multiple.

So, to calculate the shadow from a light to a tile, I need to know the angle between the corner of the tile and the light. The tile is a surface that is 64*32 pixels. So, the left corner is at (0, 16). The top corner is at (31, 0). The right corner is at (63, 16). And the bottom corner is at (31, 31).

// the angle between the left corner and the light is:a0 = arctan2( (tile.y + tile.z*ZHEIGHT + 16) - (light.y + light.z*ZHEIGHT), tile.x - light.x);// The "+ 16" is for the y offset of the left corner.

To get the length of the vector, I use similar right triangles to get that the magnitude of the vector should be:

shadowLength = tile.z*ZHEIGHT*distance(tile, light)/((light.z - tile.z)*ZHEIGHT);// Where distance is a function returning the distance between the tile and the light.

Anyway, after getting the correct coordinates for the outline of the shadow, I can render something like this:

http://img266.imageshack.us/i/lightexample.png/

That works great when everything is level, but I need to have the tiles render the shadow on themselves rather than have the tile render it's shadow.

I'm wondering how I should do this. I can put the vertex for the shadow in the tile on which it should be rendered. However, I'm wondering how I would move that vertex to the correct position. I know that the angle of the vector wouldn't change, but the magnitude would. So, I need to recalculate shadowLength to take into account the height of the tile on which the shadow is being drawn.

So, I think this should work:

// assuming that tile is now the tile on which the shadow is being drawn// and that sTile is the tile which the shadow is being cast fromshadowLength = (sTile.z - tile.z)*ZHEIGHT*distance(tile, light)/((light.z - tile.z)*ZHEIGHT);

However, once the vertex is moved, the primitive is no longer proportionate. I need to add another vertex on the edge of the tiles, I think. But I'm not sure exactly.

I can't figure out what I need to do to get the correct shape of the shadow. Can anyone help?

Thank you,

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×