AramaiTii
04-29-2005, 12:01 AM
Hello,
I've been tearing my hair out for the past few days trying to do this.
I am trying to draw a rectangle enclosing a rotating 3D object. The rectangle position is fixed no matter where the camera is or how it rotates. The rectangle acts like a control panel to the 3D scene.
I am using D3DXMatrixOrthoLH to position the rectangle. But I am not sure what should I put in the w and h. Should I put the display resolution values such as 800, 600? Or the size of the display surface in pixels?
Is it true that if I use D3DXMatrixOrthoLH, its origin starts at the center, not the top left corner? How can I translate my line coordinates into the display surface? I can't seem to get the rectangle displayed no matter what coordinates I use.
Here's my code
Dim mode As D3DDISPLAYMODE
Dim matOrtho As D3DMATRIX
Dim matIdentity As D3DMATRIX
Dim oSurface As Direct3DSurface8
Dim SurfDesc As D3DSURFACE_DESC
Set oSurface = g_D3DDevice.GetRenderTarget
oSurface.GetDesc SurfDesc
' Get The current Display Mode format
g_d3d.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
D3DXMatrixOrthoLH matOrtho, SurfDesc.width, SurfDesc.height, 0#, 1#
' D3DXMatrixOrthoLH matOrtho, mode.width, mode.height, 0#, 1#
D3DXMatrixIdentity matIdentity
g_D3DDevice.SetTransform D3DTS_PROJECTION, matOrtho
g_D3DDevice.SetTransform D3DTS_WORLD, matIdentity
g_D3DDevice.SetTransform D3DTS_VIEW, matIdentity
'Make sure that the z-buffer and lighting are disabled
g_D3DDevice.SetRenderState D3DRS_ZENABLE, D3DZB_FALSE
g_D3DDevice.SetRenderState D3DRS_LIGHTING, False
LineStripBox(0) = CreateTLVertex(2, 2, 1, 1, RGB(0, 255, 0), 0, 0, 0)
LineStripBox(1) = CreateTLVertex(390, 2,1, 1, RGB(0, 0, 0), 0, 0, 0)
LineStripBox(2) = CreateTLVertex(390, 400, 1, 1, RGB(0, 0, 0), 0, 0, 0)
LineStripBox(3) = CreateTLVertex(2, 400, 1, 1, RGB(0, 0, 255), 0, 0, 0)
LineStripBox(4) = CreateTLVertex(2, 2, 1, 1, RGB(0, 0, 0), 0, 0, 0)
g_D3DDevice.SetVertexShader FVF
g_D3DDevice.DrawPrimitiveUP D3DPT_LINESTRIP, 4, LineStripBox(0), Len(LineStripBox(0))
I've been tearing my hair out for the past few days trying to do this.
I am trying to draw a rectangle enclosing a rotating 3D object. The rectangle position is fixed no matter where the camera is or how it rotates. The rectangle acts like a control panel to the 3D scene.
I am using D3DXMatrixOrthoLH to position the rectangle. But I am not sure what should I put in the w and h. Should I put the display resolution values such as 800, 600? Or the size of the display surface in pixels?
Is it true that if I use D3DXMatrixOrthoLH, its origin starts at the center, not the top left corner? How can I translate my line coordinates into the display surface? I can't seem to get the rectangle displayed no matter what coordinates I use.
Here's my code
Dim mode As D3DDISPLAYMODE
Dim matOrtho As D3DMATRIX
Dim matIdentity As D3DMATRIX
Dim oSurface As Direct3DSurface8
Dim SurfDesc As D3DSURFACE_DESC
Set oSurface = g_D3DDevice.GetRenderTarget
oSurface.GetDesc SurfDesc
' Get The current Display Mode format
g_d3d.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
D3DXMatrixOrthoLH matOrtho, SurfDesc.width, SurfDesc.height, 0#, 1#
' D3DXMatrixOrthoLH matOrtho, mode.width, mode.height, 0#, 1#
D3DXMatrixIdentity matIdentity
g_D3DDevice.SetTransform D3DTS_PROJECTION, matOrtho
g_D3DDevice.SetTransform D3DTS_WORLD, matIdentity
g_D3DDevice.SetTransform D3DTS_VIEW, matIdentity
'Make sure that the z-buffer and lighting are disabled
g_D3DDevice.SetRenderState D3DRS_ZENABLE, D3DZB_FALSE
g_D3DDevice.SetRenderState D3DRS_LIGHTING, False
LineStripBox(0) = CreateTLVertex(2, 2, 1, 1, RGB(0, 255, 0), 0, 0, 0)
LineStripBox(1) = CreateTLVertex(390, 2,1, 1, RGB(0, 0, 0), 0, 0, 0)
LineStripBox(2) = CreateTLVertex(390, 400, 1, 1, RGB(0, 0, 0), 0, 0, 0)
LineStripBox(3) = CreateTLVertex(2, 400, 1, 1, RGB(0, 0, 255), 0, 0, 0)
LineStripBox(4) = CreateTLVertex(2, 2, 1, 1, RGB(0, 0, 0), 0, 0, 0)
g_D3DDevice.SetVertexShader FVF
g_D3DDevice.DrawPrimitiveUP D3DPT_LINESTRIP, 4, LineStripBox(0), Len(LineStripBox(0))