View Full Version : Drawing a "2d" object in a 3d scene
07-14-2005, 08:32 AM
My problem this time is that I want to draw a sprite in a 3d scene. My first solution was to use billboards and that worked fine until I moved the avatar ( camera: 3rd person view ) right next to a wall and rotated around the sprite... Depending on the angle you look at the sprite ( facing to wall is most obvious ) the sprite is rotated and intersects the wall at the top ( of the sprite ). So I had to scrap my old idea of using billboard.
Today and friend of mine came up with the idea that I could use a sprite drawn in 2d with a specific depth value so that every triangle drawn would either be behind or in front of the sprite. This would still create artefacts but it should work far better than my rotated billboard.
So now I've spent almost my entire day to figure out how to do that - and to be honest I don't think I've got anywhere.
I figured that if I could aquire the z-value of the pixel in the center of the screen in some way, and then draw the sprite in a glOrtho perspective this whole thing could look quite nice, but I've not been able to figure out how to get the z-value, nor how to draw the sprite with that value as it's z value. Any help in any way is appreciated.
07-14-2005, 08:41 AM
I admit I don't fully understand what your problem is by your post (a screen shot might belp).
either way - it seems you're having problems regarding rotations and sprites that should always remain screen aligned (?).
you could look into point sprites, they may help you. although there are some issues with point sprites - the biggest one to me is that if the center of the sprite is clipped the entire sprite is clipped.
or you could take some care not to apply rotations to your sprites (is this how you implemented your billboards?).
when I'm sure of what problem it is you're having perhaps i can try and be of more help.
07-14-2005, 09:24 AM
Well to show you the effect i have this screenshot:
In ragnarok online they look like this:
( yes I'm working on a homebrewed clone of ragnarok ;-) )
07-14-2005, 10:11 AM
I assume you're referring to the banner.
The banner you see in Ragnarock there doesn't intersect the ground.
That "triangle" you're seeing there is the intersection of your magenta banner with the brick wall. If you disable depth testing and draw the banner last, you'll see that the banner will be "superimposed" over the bricks.
You don't really want that though. And I don't think you want billboards for a banner either.
You want to be able to move around the wall and have the banner move around as well.
In Ragnarock, the banner is high above the ground. From the camera's point of view (since it's a 3/4 looking from up in the air) the banner is nearer to the eye and doesn't get obscured by the ground farther below.
I suggest you use a simple quad (you can add wind with better tesselated geometry later if you wish)
to render your banner and make sure you render it farther away from the wall.
Your problem is simply one of positioning.
07-14-2005, 10:26 AM
Well I was not refering to the banner ( flag ), I was refering to the sprite of the character, that sprite intersects the base of the stone foundation for the banner depending on what angle you have the camera at.
Here is two more screens - the only thing I've done here is to rotate the camera and if the charater sprite would have been drawn in an ordinary 3d way - the character should not intersect the wall the way it does in "3.png", Nove this error is what I WANT to have.
In ragnarok tey are probably drawing the sprites in a similar way to what I described above.
07-16-2005, 02:12 AM
If I got you right, you don't want a completely screen aligned quad for your sprite. Only aligned around the vertical axis of the scene.
That way, the billboard will be parallel to the vertical.
The quad will always have about the same width on screen, but if the view is straight form above it will be only one line high.
Does this helps ?
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.