Sprites in 3D Space
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!
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
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
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*()
(1) Call Begin() with D3DXSPRITE_BILLBOARD
(2) Set your view and world matrix in SetWorldView*()
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.
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.
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
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
Could I just give the sprite the identity matrix so that it is just placed at the origin with no changes?
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?
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:
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!
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!
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement