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

Started by
2 comments, last by Maddius 14 years, 1 month ago
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:
RECT R;
	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?
Advertisement
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.
Post your code for drawing the sprites. They shouldn't be affected by the camera.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.

This topic is closed to new replies.

Advertisement