Jump to content
  • Advertisement
Sign in to follow this  
yahn

Isometric Shadows

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

If you intended to correct an error in the post then please contact us.

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 from
shadowLength = (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,

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!