Jump to content
  • Advertisement
Sign in to follow this  

Creating a GUI with sprites in a 3D World [Direct3D]

This topic is 3216 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 to draw 32x32 sprite buttons onto my 800x600 screen in my 3D world except they won't show up. I've been told that it has something to do with your camera views. Right now my view matrix is:
float x = mCameraRadius * cosf(mCameraRotationY);
	float z = mCameraRadius * sinf(mCameraRotationY);
	D3DXVECTOR3 pos(x, mCameraHeight, z);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
And my projection matrix is:
	GetClientRect(mhMainWnd, &R);
	float w = (float)R.right;
	float h = (float)R.bottom;
	D3DXMatrixPerspectiveFovLH(&mProj, D3DX_PI * 0.25f, w/h, 1.0f, 5000.0f);
	HR(gd3dDevice->SetTransform(D3DTS_PROJECTION, &mProj));
When I set up the sprites and set them to a 0,0,0 coordinate system they don't show up. Any thoughts?

Share this post

Link to post
Share on other sites
I haven't touched 3d in a while so I'm a touch rusty but I'd check to make sure that the sprites are in your field of view, as I'm not sure how far away your x, y and z values are from the origin. If that isn't the issue could you show me your sprite code so we can check that.

Share this post

Link to post
Share on other sites
Why not just draw a textured quad with a Identity matrix as your view matrix?

So setup your world and projection matricies as normal then do:

WorldViewProjMtx = WorldMtx;
WorldViewProjMtx *= IdentityMtx;
WorldViewProjMtx *= ProjMtx

This will make the textured quad appear 'flat' on the screen - and will always remain in the cameras view. Also just translate your world matrix as normal to change the position of the sprite.

Also the depth of the sprite's should always be 1.0f.

That how im doing it atleast, works for me. Then you dont have to worry about screen resoloution you can just scale it by the aspect ratio in the x-direction and sprites should remain at a relative size regardless of resolution.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!