Jump to content
  • Advertisement
Sign in to follow this  
Ilici

Billboards in 3D Isometric

This topic is 5456 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 working on an isometric engine and i'm going to implement a billboard rendering function. I've done this before by getting the OpenGL modelview matrix and transforming the center of the billboard by it then rendering a quad at that point with an identity modelview matrix. This has the drawback of the quad not being scaled according to the current scale and also that i have to do a matrix multiplication with a vector (slow for lots of sprites). Is there a better way to do it? Also, how would i sort these sprites based on depth? They only have a x and z component as i'm using a tilebased 2d map.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Ilici
I'm working on an isometric engine and i'm going to implement a billboard rendering function. I've done this before by getting the OpenGL modelview matrix and transforming the center of the billboard by it then rendering a quad at that point with an identity modelview matrix. This has the drawback of the quad not being scaled according to the current scale and also that i have to do a matrix multiplication with a vector (slow for lots of sprites).


I'm going to assume here that you are using billboarding to draw sprites in a 2d engine using 2d tiles for the map.

You don't really need a general billboarding solution for this. The approach you described is needed for a 3d engine because the billboards could be placed in any arbitrary location in the scene, with an arbitrary camera. However in this case we can take advantage of the fact that the camera angle is known and the sprites will be drawn directly over the background tiles.

What you really want to do is draw your sprites as quads flat on the screen. Make sure the modelview matrix is set to identity, and then translate the quads in the x,y directions to the correct place on the screen.

You can either do the translation with a glTranslate2() call for each sprite, or if you want to batch your quads you could modify the corners of each sprite by adding the x,y offsets to each vertex. You don't need a matrix multiply for this, just a few additions. Presumably in that case you would store the quads in a vertex array or vbo. This is a bit more complex so I would recomend using glTranslate unless you are running into speed issues.

If you want to scale your scene just start with a glScale on the modelview matrix instead of identity. Due to the matrix multiplication order in ogl this will get your scale applied after the translate. This would also work for the batched approach as long as you want the same scale applied to all sprites.

Quote:

Also, how would i sort these sprites based on depth? They only have a x and z component as i'm using a tilebased 2d map.


This is probably the hardest part of 2d isometrics, and there are a few different approaches. The simple approach is to draw the objects based on their tile, top to bottom, left to right. But this does have some issues with large sprites. One solution to that problem is something called LORM (do a search on this forum).

The general solution is to consider that each object is actually taking up a rectangular volume in 3d world space. It's position along the ground plane, and it's height above the ground plane are known (you are tracking this object in world space based on the tile it is over, and you know the height of the tile, or if you allow flying objects, the height of the object over the tile.)

Remember that world space is different than screen space since the world is rotated and the camera is at an angle. Based on object size and position you can find its bounding box in 3d world space and sort it against the bounding boxes of the other objects.

For example you could find the center of each bounding box and
transform that point into screen space and then compare it's depth against other object centers. This only works if the bounding volumes are convex and do not interpenetrate, but that's a reasonable limitation. Of course this gets you back to a matrix multiply per object, but you can exploit temporal coherence to avoid doing this every frame, and you only need to resort moving objects. If this is still too slow you could look into more complex methods of space partitioning.

Share this post


Link to post
Share on other sites
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!