Sign in to follow this  

trying to make a GUI through texture quads, can't get them to 'stick' to the screen

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

My problem is kind of annoying. basically i have set up some quads to which I load a texture and render it right in front of the camera, through this code (if you're interested);
D3DXMATRIX* Camera::getViewMatrix()
{
	D3DXMATRIX* V = new D3DXMATRIX;

	// Keep camera's axes orthogonal to eachother
	D3DXVec3Normalize(&_look, &_look);

	D3DXVec3Cross(&_up, &_look, &_right);
	D3DXVec3Normalize(&_up, &_up);

	D3DXVec3Cross(&_right, &_up, &_look);
	D3DXVec3Normalize(&_right, &_right);

	// Build the view matrix:
	float x = -D3DXVec3Dot(&_right, &_pos);
	float y = -D3DXVec3Dot(&_up, &_pos);
	float z = -D3DXVec3Dot(&_look, &_pos);

	(*V)(0,0) = _right.x; (*V)(0, 1) = _up.x; (*V)(0, 2) = _look.x; (*V)(0, 3) = 0.0f;
	(*V)(1,0) = _right.y; (*V)(1, 1) = _up.y; (*V)(1, 2) = _look.y; (*V)(1, 3) = 0.0f;
	(*V)(2,0) = _right.z; (*V)(2, 1) = _up.z; (*V)(2, 2) = _look.z; (*V)(2, 3) = 0.0f;
	(*V)(3,0) = x;        (*V)(3, 1) = y;     (*V)(3, 2) = z;       (*V)(3, 3) = 1.0f;

	return V;
}
basically I've set the quad data to be just in front of the screen. Anyways, my problem is that when the screen moves fast (and even slow actually) the quad starts lagging behind the camera and it creates this totally cool yet unwanted effect where the quad is playing catch up with the screen. How can I make the quad stick to the screen a little better?

Share this post


Link to post
Share on other sites
I think you need to update your camera position before you place your quads on screen. It sounds like your doing it after so the quads are taking their position relative to the cameras old position (1 frame ago).
hope this helps

Share this post


Link to post
Share on other sites
If you're using the fixed-function pipeline for your sprites, you use the D3DFVF_XYZRHW FVF code. This specifies that the vertex is already transformed, so you can set the vertex position to wherever you want in screen coordinates. If you're using vertex declarations, use D3DDECLUSAGE_POSITIONT.

Share this post


Link to post
Share on other sites
Or if your using vertex buffers you can just set to identity matrices like TheAdmiral said. If your not sure what that means:

D3DXMATRIX identityMatrix;

D3DXMatrixIdentity(&identityMatrix);
device->SetTransfrom(D3DTS_VIEW, &identityMatrix);
device->SetTransfrom(D3DTS_PROJECTION, &identityMatrix);

/* now draw your GUI bits. X and Y in the range -1 to 1 and z in the range 0 to 1. I think you will want to turn off z testing too. device->SetRenderState(D3DRS_ZENABLE, false);

*/

Share this post


Link to post
Share on other sites
Quote:
Original post by jrmcv
Or if your using vertex buffers you can just set to identity matrices like TheAdmiral said. If your not sure what that means:

D3DXMATRIX identityMatrix;

D3DXMatrixIdentity(&identityMatrix);
device->SetTransfrom(D3DTS_VIEW, &identityMatrix);
device->SetTransfrom(D3DTS_PROJECTION, &identityMatrix);

/* now draw your GUI bits. X and Y in the range -1 to 1 and z in the range 0 to 1. I think you will want to turn off z testing too. device->SetRenderState(D3DRS_ZENABLE, false);

*/



I'm not sure if I follow, how exactly can I set the x and y values? Do I just use device->SetTransform(D3DTS_WORLD, &Matrix)?

I've tried that but nothing actually got printed on screen.

Share this post


Link to post
Share on other sites
Don't do it the wrong way just because you don't know how to do it the right way.

Google one of the constants MJP mentioned (depending on which you're using of FVFs and vertex-declarations). There is plenty of information out there about pre-transformed geometry.

Share this post


Link to post
Share on other sites

This topic is 3663 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this