Results 1 to 6 of 6

Thread: Drawing a "2d" object in a 3d scene

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    26

    Drawing a "2d" object in a 3d scene

    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.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    569

    Re: Drawing a "2d" object in a 3d scene

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    26

    Re: Drawing a "2d" object in a 3d scene

    Well to show you the effect i have this screenshot:
    http://ariel.rsn.bth.se/files/2.png

    In ragnarok online they look like this:
    http://ariel.rsn.bth.se/files/1.png

    ( yes I'm working on a homebrewed clone of ragnarok )

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    569

    Re: Drawing a "2d" object in a 3d scene

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    26

    Re: Drawing a "2d" object in a 3d scene

    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.

    http://ariel.rsn.bth.se/files/3.png
    http://ariel.rsn.bth.se/files/4.png

    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.

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Drawing a "2d" object in a 3d scene

    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.
    http://nehe.gamedev.net/data/article...p?article=19#5

    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 ?

Similar Threads

  1. Drawing 2D interface before the scene
    By silikone in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-15-2017, 03:17 PM
  2. Drawing on top of the scene
    By Inoss in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 04-15-2011, 06:07 PM
  3. Scene drawing problems
    By z_z_z_z in forum OpenGL ES
    Replies: 0
    Last Post: 10-27-2010, 06:38 AM
  4. drawing text in 2d in a 3d scene
    By BennUK in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-01-2004, 06:49 AM
  5. I want to know when the scene drawing is completed.
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-01-2000, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean