我有幾個關於使用C++編程DirectX的疑問。DirectX問題
我遇到的第一個問題是我的紋理不能正確顯示在屏幕上。創建窗口時,窗口設置爲800x600,紋理也爲800x600,但程序加載時只顯示部分紋理。代碼如下所示,用於紋理加載和繪製。
//This sets the image
helpFileTexture = new Texture(d3dDevice, L"../Resources/Help Guide.png");
//This is the draw function
helpFileTexture->Draw(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//Which calls this
void Texture::Draw(long xPos, long yPos, long width, long height)
{
sprite->Begin(NULL);
RECT imageRectangle;
imageRectangle.left = xPos;
imageRectangle.top = yPos;
imageRectangle.right = imageRectangle.left + width;
imageRectangle.bottom = imageRectangle.top + height;
sprite->Draw(texture, &imageRectangle, &D3DXVECTOR3(1.0f, 1.0f, 0.0f), &D3DXVECTOR3((float)xPos, (float)yPos, 0.0f), D3DCOLOR_XRGB(255, 255, 255));
sprite->End();
}
正如我所說的SCREEN_WIDTH
被設置爲800和SCREEN_HEIGHT
被設置爲600(其也是相同的尺寸圖像)。它從左上角開始繪製,但只顯示圖像的一部分。當可以看到整個圖像時,窗口大小設置爲大約1100x1100。我在編碼中做了什麼錯誤來設置圖像大小。
接下來就是我隱藏光標的問題。當我點擊鼠標左鍵時,我想隱藏光標,然後在我放開時重新出現。但光標不會消失。爲此編碼如下。
if(input->mouseButtons.rgbButtons[0])
{
d3dDevice->ShowCursor(FALSE);
GetCursorPos(&input->mousePosition);
SetCursorPos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
input->mousePosition.x -= SCREEN_WIDTH/2;
mainCamera->UpdateYaw(input->mousePosition.x * rotationSpeed);
indexYaw += mainCamera->GetYaw();
D3DXMatrixRotationY(&viewMatrix, indexYaw);
d3dDevice->SetTransform(D3DTS_VIEW, &viewMatrix);
}
else
{
d3dDevice->ShowCursor(TRUE);
}
正如您所看到的,當鼠標左鍵單擊攝像機控制但它仍然顯示時,光標會消失。
最後幾件事是什麼是在對象和地形跟隨之間實現碰撞檢測的最佳方式,或者可以將我連接到找到這些地方的好地方。
我知道這是一個很多我也問過,但任何幫助將是巨大
解決了紋理問題,一個下來:D – trevski87 2011-04-06 14:33:00
紋理通常是正方形... – 2011-04-07 09:07:47