Skip to main content
GameDev.net gamedev.net
🔒 Locked

Perspective matrix problem. *Solved*

Started by Calin Sep 27, 2005 at 3:39 AM 3 replies 600+ views
Original Post
Calin
Calin
Hi everyone! I have a 3D cursor that gets distorted by the Perspective matrix when it is on the edges of the screen. Does anyone now how do I "erase" the perspective matrix effect when I draw the cursor and then restore it when I want to draw everything else? Thanks for any input. [Edited by - Calin on September 27, 2005 6:10:47 AM]
My project`s facebook page is “DreamLand Page”
centipede
centipede
Try using ortho matrix when rendering mouse cursor and other GUI elements. After you have rendered them, switch back to perspective matrix.
Calin
Calin
Thanks!
If I am not asking to much can you also tell how do you set the ortho matrix ?
I searched on MSDN for "ortho matrix" but nothing came out, I need the exact name of the function.

Edit: I found the function: D3DXMatrixOrthoLH. Problem solved.

[Edited by - Calin on September 27, 2005 4:48:41 AM]
My project`s facebook page is “DreamLand Page”
centipede
centipede
There's several ortho matrix functions in D3DX. I suggest you to use D3DXMatrixOrthoOffCenterLH() to create your matrix:

D3DXMatrixOrthoOffCenterLH(&orthoMatrix, 0.0f, 800.0f, 0.0f, 600.0f, -1.0f, 1.0f);


Then you just assign this matrix to D3DTS_PROJECTION.

Now you can use coordinates where upper left corner of the screen is (0, 0) and lower right (800, 600). Notice that this is independent of actual screen resolution.

After you have rendered all GUI elements, switch back to perspective matrix.
Calin
Calin
For some reason my cursor does not get redered.
Here is the code:
D3DXMATRIX matProjection, matOrtho; // global variablesHRESULT GameInit(){D3DXMatrixPerspectiveFovLH(&matProjection, D3DX_PI/4, g_D3DSettings.m_fScreenAspect, 0.5f, 500.0f);	rslt=g_pDevice->SetTransform(D3DTS_PROJECTION, &matProjection); // Set mat Projection as the default projection matrix.	if(FAILED(rslt)) { return D3DError(rslt, __LINE__, __FILE__, "Failed to set Projection Transform."); }	D3DXMatrixOrthoOffCenterLH(&matOrtho, 0.0f,800, 0.0f, 600, -1.0f, 1.0f);}HRESULT Render(){   rslt=g_pDevice->SetTransform(D3DTS_PROJECTION, &matOrtho);   if(FAILED(rslt)) { return D3DError(rslt, __LINE__, __FILE__, "Set matOrtho failed."); }	Cursor.DrawCursor(g_pDevice,		              g_pDIMouse->GetAbsoluteX(),			      g_pDIMouse->GetAbsoluteY() );		g_pDevice->SetTransform(D3DTS_PROJECTION, &matProjection); // some code here}HRESULT CursorMold::DrawCursor(LPDIRECT3DDEVICE9 mDevice, float PosX, float PosY){	D3DXMatrixIdentity(&IdMt); //  Make IdMt Identity Matrix	D3DXMatrixRotationY(&RotCursYAxis, angle); // Make a rotation  matrix for Y axis using angle 	D3DXMatrixRotationX(&Italic0, angle2);	D3DXMatrixRotationZ(&Italic, angle2);	D3DXMatrixMultiply(&ItalicSum,&Italic,&Italic0);		 	D3DXMatrixTranslation(&Mt3,PosX ,PosY,0.0);			mDevice->SetTransform(D3DTS_WORLD, &IdMt);	D3DXMatrixMultiply(&SumMoveItalic,&ItalicSum,&Mt3);	D3DXMatrixMultiply(&AllTransf,&RotCursYAxis,&SumMoveItalic);	mDevice->SetTransform(D3DTS_WORLD, &AllTransf);		mDevice->SetFVF(FVF_SIMPLEVERTEX);	mDevice->SetStreamSource(0, CursorVB, 0, sizeof(SIMPLEVERTEX));	//make shure that the object will have no texture on it.	mDevice->SetTexture(0,0);		mDevice->DrawPrimitive(D3DPT_TRIANGLEFAN , 0, 4); 	mDevice->DrawPrimitive(D3DPT_TRIANGLEFAN , 6, 4);		return S_OK;}


Edit: I still don`t now what was the probem but I found another way to do what I wanted.

[Edited by - Calin on September 27, 2005 6:13:55 AM]
My project`s facebook page is “DreamLand Page”

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.