【发布时间】:2011-04-06 12:05:36
【问题描述】:
我有几个关于使用 C++ 在 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
-
纹理通常是正方形...
标签: c++ directx mouse collision-detection textures