Jump to content
  • Advertisement
Sign in to follow this  
MrDoomMaster

Sprites in 3D Space

This topic is 4827 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 using ID3DXSprite to display and manage my sprites. How can I setup ID3DXSprite to work with 2D sprites in 3D space exactly as if they were 3D objects? Each sprite should basically act as a 3D Plane. Think of how Doom's sprites worked. Doom used 2D bitmaps in 3D space with billboarding. I am not as concerned with billboarding though. Thanks for any help. Code examples would be most helpful!

Share this post


Link to post
Share on other sites
Advertisement
Hi,

You can use ID3DXSprite::SetTransform to set a transform matrix to a sprite.

Syntax:
HRESULT SetTransform(CONST D3DXMATRIX *pTransform);

If you want some code, ask
ProgrammingNerd

Share this post


Link to post
Share on other sites
If you want to use billboarding, which is kind important, you just have to do two things:

(1) Call Begin() with D3DXSPRITE_BILLBOARD
(2) Set your view and world matrix in SetWorldView*()

Share this post


Link to post
Share on other sites
What good does adding a transform matrix to a sprite do? I'm not really translating or rotating the sprite yet, I'm just trying to get it to display as a plane in 3D space.

Also, I may have the definition of Billboarding confused. Isn't billboarding where the bitmap always faces the user, no matter where the camera is rotated? Yet, if given depth, the bitmap will always appear to scale smaller or larger, depending on the distance of the camera? Much like Doom's sprites... They always faced the screen.

Is this correct?

I also have no idea how I would set up any of these matrices for my sprites. I don't know the requirements of the matrices nor what they are responsible for.

Thanks for your help everyone.

Share this post


Link to post
Share on other sites
Hi,

If you translate the sprite to some place in 3d space, you should get a plane at that spot in space with your texture on it.

You can use D3DXMatrixTranslation to compute a translation matrix for your sprites:

D3DXMATRIX *WINAPI D3DXMatrixTranslation(D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z);

ProgrammingNerd

Share this post


Link to post
Share on other sites
To rotate a sprite for only a 2D game (ZBUFFER disabled), how would you do this? I want to use a matrix for the rotation/scaling/translation of a 2D sprite in 2D space, but I don't know how you would do this. Which axis would you rotate around? Would you rotate at the Z axis, even when the depth buffer is disabled?

Share this post


Link to post
Share on other sites
I figured out my last question by myself. You do rotate the Z axis.

Now I'm facing a new problem. I've enabled D3DXSPRITE_BILLBOARD, and I made a call to SetWorldViewRH as follows:

SetWorldViewRH(NULL, NULL);


The DirectX Docs specifically state that if either parameter is NULL, then the identity matrix is used. The thing is, I don't have any idea what the world or view transform matrices should look like, nor what they do.

My sprite is not displayed at all so far.

Any help is greatly appreciated! Thank you!

Share this post


Link to post
Share on other sites
Hi,

First, I'm assuming that you are using right-handed coordinants. The default is left-handed.

Second, the world transformation matrix holds the rotations, translations, and scalings an object can have.

First, create the world transform matrix:
D3DXMATRIX* pWorldMatrix;

You can use this for setting up your rotations:
D3DXMATRIX *WINAPI D3DXMatrixRotationYawPitchRoll(
D3DXMATRIX *pOut,
FLOAT Yaw,
FLOAT Pitch,
FLOAT Roll
);

Use this to translate your object:
D3DXMATRIX *WINAPI D3DXMatrixTranslation(
D3DXMATRIX *pOut,
FLOAT x,
FLOAT y,
FLOAT z
);

And use this to scale your object:
D3DXMATRIX *WINAPI D3DXMatrixScaling(
D3DXMATRIX *pOut,
FLOAT sx,
FLOAT sy,
FLOAT sz
);

Third, the view matrix holds the up vector, the look vector, and the eye vector of an object. Set this to set where the object should face at.

D3DXMATRIX *WINAPI D3DXMatrixLookAtLH(
D3DXMATRIX *pOut,
CONST D3DXVECTOR3 *pEye,
CONST D3DXVECTOR3 *pAt,
CONST D3DXVECTOR3 *pUp
);

Or for right handed matrices:
D3DXMATRIX *WINAPI D3DXMatrixLookAtRH(
D3DXMATRIX *pOut,
CONST D3DXVECTOR3 *pEye,
CONST D3DXVECTOR3 *pAt,
CONST D3DXVECTOR3 *pUp
)

This should explain some thing, hope this helps you,
ProgrammingNerd

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!