Jump to content
  • Advertisement
Sign in to follow this  
MrDoomMaster

2D Sprites in 3D Space

This topic is 4799 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

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 this post


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


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by ZMaster
What 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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by MrDoomMaster
I'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 this post


Link to post
Share on other sites
Quote:
Original post by Dave Hunt
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.


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 this post


Link to post
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 this post


Link to post
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!