Public Group

# 2D Sprites in 3D Space

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

## Recommended Posts

Could someone provide an example of how to make a 2D sprite appear in 3D space (Object Space)? I prefer to use ID3DXSprite if possible. I'm trying to display a 2D tree in a 3D world, yet this tree should not always be facing the camera. If you walk around it in circles, you will be able to see the back of it, the front, depending on which side of the sprite you're located at. I can't seem to figure out how to do this with ID3DXSprite. Thank you!

##### Share on other sites
Don't tell me that out of 50 views no one can help me. Can anyone even help just a little bit? This is driving me nuts :(

Any help is greatly appreciated!

##### Share on other sites
What you actually should be looking into is a technique called "Billboarding".

I'm from the OpenGL fraction, so I can't give you DirectX code details, but you should find a lot of information on the web because this is a well known and often used technique.

I can say that in OpenGL you have to do the mathmatical calculations on your own and there are many different ways to do it, some simpler, some more advanced, some that are faster but may look incorrect under certain camera angles and some that look correct at any time but may be more expensive to calculate...

##### Share on other sites
Quote:
 Original post by ZMasterWhat you actually should be looking into is a technique called "Billboarding".

Actually, what MrDoomMaster described is not billboarding. With billboarding, the object always faces the camera. The OP doesn't want that.

The simple answer is to not use the ID3DXSprite interface. You just need to texcture a quad and place it like any other geometry. Then you will be able to walk around it. If you want different images on the front and back of the "sprite", then simply draw two quads, one facing one direction, and the other facing the opposite direction.

##### Share on other sites
Well I know that billboarding causes the sprite to always face the camera, which isn't what I want.

Many games use 2D sprites in 3D space that do not face the camera all of the time. Take spider webs for example. Spider webs are sprites that are displayed in 3D space with a position and an absolute direction and size. They do not face the camera. In fact, if you look along the "side" of the sprite, it might actually look as if it is not there, since sprites have no actual width.

I have a hunch that the flag D3DXSPRITE_OBJECTSPACE might enable me to do what I need to do. The thing is, I don't know more than that. I don't know how to display the sprite in object space.

If someone could provide a code example or something, it would be very helpful. Thank you very much ZMaster for your kind reply. I wish I wasn't so clueless all of the time :)

##### Share on other sites
Quote:
 Original post by MrDoomMasterI'm trying to display a 2D tree in a 3D world, yet this tree should not always be facing the camera.

You're right, sorry I overread the NOT :-)
Anyway, the textured quad should do the job, you're right again...

Cheers

##### Share on other sites
Alright so what good does the D3DXSPRITE_OBJECTSPACE flag do? I tried using it, but if I do then my sprite doesn't appear on the screen anywhere.

##### Share on other sites
Quote:
 Original post by Dave HuntThe simple answer is to not use the ID3DXSprite interface. You just need to texcture a quad and place it like any other geometry. Then you will be able to walk around it. If you want different images on the front and back of the "sprite", then simply draw two quads, one facing one direction, and the other facing the opposite direction.

Dave has actually given you a great answer. Not only will this work, but it will also mean that you can handle your 2D objects as you would the rest of your 3D geometry. This would be much more simple then developing a special case rendering sequence for 2D objects using ID3DXSprite.

##### Share on other sites
Thanks, I plan to use textured quads. I was just curious as to how the D3DXSPRITE_OBJECTSPACE flag affects sprites. I don't see how it is useful. Come to think of it, billboarding is also pointless. The sprites are drawn in screen coordinates, so either way the sprite is always facing the camera.

##### Share on other sites
I'm not sure about that flag but the easiest way I've done 2D in 3D before is just to have a fixed camera looking down the -Z axis, translated back a few units. Then you quads can all live in the XY plane and you can treat all collisions etc. as 2D problems.

Then I used the world translation to put them into the right place along with the camera's view transform (using the utility LookAtLH, since it never changes this is easy) and an orthographic perspective transform.

1. 1
2. 2
khawk
19
3. 3
Rutin
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013761
×