Sign in to follow this  

Intergrating Sprites with Voxels

Recommended Posts

zorba990    122
I have my own custom voxel engine for my embedded platform. I am having some trouble with the math to correctly place a sprite on the terrain generated by the voxels. I need to use basic sprites due to lack of any real 3D support and speed issues. For static sprites like trees, I have, for the moment, just been marking their position as I generate the landscape and then going back in later and drawing them. So without the sprites the landscape just has these 2x2 poles sticking up. Its very fast but has the disadvantage of being dependent upon altering the color map which is no good for moving sprites. Also, there is no way to tell if I am just looking at the top of a sprite obscured by a mountain or a short sprite. (This is ok for cone shaped trees as the result is fine but, again, is no good for sprites like running people) For a while I experimented with detecting if the sprite was within the POV, and drawing it's size based on its distance from me. The big problems I had with this were getting the sprite situated properly down on the terrain, and clipping it correctly if it was partially obscured by terrain (my past experience with this used an engine where the floor was always level so it made placement easier) An suggestions for resources/tutorials/code samples would be most appreciated.

Share this post

Link to post
Share on other sites
Iftah    413
uhm, for clipping when partly obscured i guess you have a choice

1) to draw the sprites while you are drawing the terrain: as you draw the voxels from back to front check if there is a sprite there and draw it. this way when a closer voxel will obscure it it will look proper.

2) to keep a z-buffer. 3d hardware can handle it but i guess for your program you have to manualy (very slow) draw to a z-buffer and test it. this is very simple if you keep all the voxels and sprites facing the viewer (i.e. can look left/right but not up/down). Note this technique is slow but its been used by software rendering that ran on a pentium 100Mhz (and even slower), so its doable.

as for the height, place the sprite at the coordinate (x,y,heightmap[x,y]-sprite_height) and do a perspective transform.
(in words, use the heightmap, and draw image-heght above the floor so the image will be just touching the floor).


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this