[D3D9] 'Drawing' into window

Started by
14 comments, last by exextatic 12 years, 1 month ago
Advertisement
I don't have time to look in-depth just now, but I'd suggest printing out the various coordinates fed in and out of your picking code to see why the position is flickering between two locations like that. If you can get it so that it's in one position, that'll make it easier to narrow down. Then, if it's still wrong by a fixed offset, check that the top left coordinate of the viewport is correct, that your input mouse coordinates are relative to the viewport and not in screen space, and so on.

I don't have time to look in-depth just now, but I'd suggest printing out the various coordinates fed in and out of your picking code to see why the position is flickering between two locations like that. If you can get it so that it's in one position, that'll make it easier to narrow down. Then, if it's still wrong by a fixed offset, check that the top left coordinate of the viewport is correct, that your input mouse coordinates are relative to the viewport and not in screen space, and so on.

Thats made me think, is there a viewport per-swapchain? Im just using GetViewport() to get a viewport, and using that in the D3DXVec3Unproject()
Also, I think I've fixed it from flickering between places (restores the world matrix from when the app started instead of using the current world matrix).
Its still off from the mouse position though.
Ok, gonna post some more code and upload the latest version for you guys..
Heres the picking code at the moment:</p>
void Editor::addPlane(D3DXVECTOR3 oldMPos, D3DXVECTOR3 oldMDir, string texName, float* texScale, int whichForm)
{
D3DXMATRIX matView, matWorld;
d3ddev->SetTransform(D3DTS_WORLD, &matStart);
matWorld = matStart;

if(whichForm == 0)
{
fpsCamera->calculateViewMatrix(&matView);
cameraPos[whichForm] = fpsCamera->getPosition();
cameraEyePos[whichForm] = fpsCamera->getEyePos();
}
else
{</div>
D3DXMatrixLookAtLH(&amp;matView,
&cameraPos[whichForm],
&cameraEyePos[whichForm],
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));
}
d3ddev->SetTransform(D3DTS_VIEW, &matView);

D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&amp;matProjection,
D3DXToRadian(45),
(FLOAT)screenSize[whichForm].x / (FLOAT)screenSize[whichForm].y,
1.0f,
100.0f);
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);

POINT mousePos;
GetCursorPos(&mousePos);

D3DXVECTOR3 mouseOut, mouseOut2;
D3DVIEWPORT9 viewPort;

d3ddev->GetViewport(&viewPort);

ScreenToClient(hWnd[whichForm], &mousePos);

D3DXVec3Unproject(&mouseOut, &D3DXVECTOR3(mousePos.x, mousePos.y, viewPort.MinZ), &viewPort, &matProjection, &matView, &matWorld);
D3DXVec3Unproject(&mouseOut2, &D3DXVECTOR3(mousePos.x, mousePos.y, viewPort.MaxZ), &viewPort, &matProjection, &matView, &matWorld);

float wz = 3.0f;
float wx = ((wz - mouseOut.z) * (mouseOut2.x - mouseOut.x)) / (mouseOut2.z - mouseOut.z) + mouseOut.x;
float wy = ((wz - mouseOut.z) * (mouseOut2.y - mouseOut.y)) / (mouseOut2.z - mouseOut.z) + mouseOut.y;
D3DXVECTOR3 mouseFinal = D3DXVECTOR3(wx, wy, wz);

addPlane(D3DXVECTOR2(mouseFinal.x, mouseFinal.y), D3DXVECTOR2(1.0f, 1.0f), 0.0f, PhysDefinition(NoPhysics, 0.0f, 0.0f, 0.0f), ForeGroundPlane, TextureDefinition(texName, D3DXVECTOR2(texScale[0], texScale[1]), 0.0f));
}

Heres the latest build:
http://jameswarner.co.cc/Files/Other/Editor.rar
And heres whats happening currently:
33mmjwo.png

Any ideas?
Bump
Bump
Bump again :/
Bump again :/
Bump, and who went through all my bumps downvoting them? lol

This topic is closed to new replies.

Advertisement