![]() |
| | #1 |
| I am me, who else? Join Date: Oct 2002
Posts: 250
| Directx issues In any event, I started working with vertex buffers and am now having a problem. When I click and drag on the screen I am creating rectangles (this is intended) then I record the position, relative to the client window and make sure these coordinates are passed to the vertex buffers. Then I finally render the rectangle on the screen, however with the transformed verticies (passing these to a customvertex struct I picked up from someone's code)... Code: struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The transformed position for the vertex
DWORD color; // The vertex color
};
// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
Kinda looks like this at the bottom of the window. instead its here -> ---------------- | | topleft should be->x ... |_________| bottom right should be here -->x Any ideas? Lemme know if you need a better explanation, thanks. |
| dpro is offline | |
| | #2 |
| Super Moderator Join Date: Aug 2001
Posts: 7,813
| You need to adjust for GDI and the way it is representing the graphics. GDI can use many many different types of mapping modes. MM_TEXT is what I think you want.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #3 |
| I am me, who else? Join Date: Oct 2002
Posts: 250
| wow that totally did not format right at all hopefully that will help me, it was supposed to represent a square which was shifted up on the yu-axis buyt apparently I couldn't format that |
| dpro is offline | |
| | #4 | |
| I am me, who else? Join Date: Oct 2002
Posts: 250
| Quote:
Hmm I set the mapping mode to MM_TEXT, and tried a couple others, but its not working how I would have hoped. When I set out my vertexbuffers, they are given (for right now anyway) fixed coordinates. For example I create a CRect.. Code: CRect myRect(200, 100, 500, 400); Code: verticies[0].x = (float)myRect.left; verticies[0].y = (float)myRect.top; verticies[0].z = 0.0f; verticies[0].rhw = 1.0f; verticies[0].tu = 0.0f; verticies[0].tv = 0.0f; verticies[1].x = (float)myRect.right; verticies[1].y = (float)myRect.top; verticies[1].z = 0.0f; verticies[1].rhw = 1.0f; verticies[1].tu = 1.0f; verticies[1].tv = 0.0f; verticies[3].x = (float)myRect.right; verticies[3].y = (float)myRect.bottom; verticies[3].z = 0.0f; verticies[3].rhw = 1.0f; verticies[3].tu = 1.0f; verticies[3].tv = 1.0f; verticies[2].x = (float)myRect.left; verticies[2].y = (float)myRect.bottom; verticies[2].z = 0.0f; verticies[2].rhw = 1.0f; verticies[2].tu = 0.0f; verticies[2].tv = 1.0f; I draw a rectangle in the ondraw function (yes I am using MFC for this), and whats rendered by direct3d and the GDI are a bit off. Most notably in the y-axis. Usually its almost bang-on with the x-axis. Getting a book on this as well, but its always nice to have help from outside sources as well . Thanks again, and hopefully this explanation makes more sense than my previous one... | |
| dpro is offline | |
| | #5 |
| Super Moderator Join Date: Aug 2001
Posts: 7,813
| Sounds like you are still using the wrong units for mapping. Make sure it is pixels and remember that the y aspect ratio will change as the size of the window changes. There are always less pixels in Y than X. This is probably what you are seeing. The correct pixel aspect ratio for any given window barring field of view and all of that is: AspectY=HorizPixels/VertPixels; Now when you move vertically you must account for AspectY. Multiply all your y movements by AspectY and it should come out right.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #6 |
| I am me, who else? Join Date: Oct 2002
Posts: 250
| Hmmm interesting, I set it to MM_TEXT, and it reports to me that I did set MM_TEXT. I tried to use the aspecty, but either I am just totally missing your meaning, or I am doing it wrong. Basically I took the client width/height to get the aspect ratio, but its stretching the image instead of fitting it accordingly. I will attach two images which should help a lot more than words. I appreciate the help a lot ![]() The red-blue box is the GDI indicating the rectangle I am trying to draw. This is defined again as Code: CRect myRect(200, 100, 500, 400); Code: g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
D3DDISPLAYMODE d3ddm;
g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetSafeHwnd(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice );
loadTexture();
g_pd3dDevice->CreateVertexBuffer( 4*sizeof(Vertex), D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT,
&g_pVertexBuffer, NULL );
void *pVertices = NULL;
setupVerts();
g_pVertexBuffer->Lock( 0, 0, (void**)&pVertices, 0 );
memcpy( pVertices, verticies, sizeof(verticies) );
g_pVertexBuffer->Unlock();
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ),
640.0f / 480.0f, 0.1f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
|
| dpro is offline | |
| | #7 |
| Super Moderator Join Date: Aug 2001
Posts: 7,813
| Then maybe the division I posted is backwards. Try PixelY*(height/width).
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #8 |
| I am me, who else? Join Date: Oct 2002
Posts: 250
| Tried that actually, it shrunk instead I am not sure if I am just totally off, or if anyone has had this before at all... I'm using vertex buffers, but transformed coords, so it should not be a problem I wouldn't think... |
| dpro is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ DirectX 9 3D z-buffer issues? | jrbarr | Game Programming | 3 | 02-14-2008 01:23 AM |
| Isometric Tile Engine using DirectX | Wraithan | Game Programming | 3 | 07-17-2006 12:16 PM |
| DirectX version issues | Bubba | Game Programming | 1 | 06-26-2006 06:52 PM |
| DirectSound header issues | dxfoo | C++ Programming | 0 | 03-19-2006 07:16 PM |
| DirectX - Starting Guide? | Zeusbwr | Game Programming | 13 | 11-25-2004 12:49 AM |