平铺纹理未正确平铺. [英] Tiled Texture is not tiling correctly.
本文介绍了平铺纹理未正确平铺.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在地板上添加平铺的纹理.纹理不会显示,而是所有顶点都显示,并且球现在在其弹跳之后具有一个底面.任何帮助将不胜感激.
I am trying to add a tiled texture to the floor. The texture does not show up, instead all the vertices are showing, and the ball now has a floor that follows it''s bounce. Any help would be appreciated.
//within winmain
pGrid->CreateDirectXMesh(pd3dDevice);
D3DXCreateSphere(pd3dDevice, 2, 20, 20, &pBallMesh, NULL);
// Main message loop:
// Enter the message loop
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
// check for messages
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
// this is called when no messages are pending
else
{
createCamera(0.1f, 1000.0f); // near clip plane, far clip plane
moveCamera(camPos);
pointCamera(camLook);
float speed, maxSpeed = 0.5;
long volume;
// update the ball velocity and position
// fake some gravity here by increasing the ball''s negative y velocity
BallVel.y -= .01f;
// limit the ball''s speed to some maxSpeed value
if (Abs(D3DXVec3Length(&BallVel)) > maxSpeed) {
D3DXVec3Normalize(&BallVel, &BallVel);
D3DXVec3Scale(&BallVel, &BallVel, maxSpeed);
}
// update the ball''s position
BallPos = BallPos + BallVel;
// rebound if ball hits the grid
pGrid->GetGridPoint(&gridPt, BallPos.x, BallPos.z);
if (BallPos.y < gridPt.y) {
// adjust the volume based on the speed of the collision
speed = D3DXVec3Length(&BallVel);
volume = long(0.25 * DSBVOLUME_MIN * (1 - (speed/maxSpeed)));
// if speed is really slow set volume to min value
if (speed < maxSpeed * 0.1f) {
volume = DSBVOLUME_MIN;
}
hr = DSBuffer->SetVolume(volume);
if( FAILED( hr ) )
DXTRACE_ERR( TEXT("Volume error "), hr );
// play this sound
playSound(DSBuffer);
// reflect the ball''s velocity in the y direction
// make the rebound have some loss of energy
BallVel.y *= -.8f;
// adjust ball slightly above the grid
BallPos.y = gridPt.y + .01f;
}
D3DXMatrixTranslation(&translate, BallPos.x, BallPos.y, BallPos.z);
D3DXMatrixIdentity(&id);
// Clear the backbuffer to a black color
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(5, 5, 5), 1.0, 0 );
// Clear the z buffer to a black color
pd3dDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(5, 5, 5), 1.0, 0 );
// Call D3DXCreateTextureFromFile
hr = D3DXCreateTextureFromFile( pd3dDevice, "patchy.jpg", &g_pTexture);
// Check return code to make sure you have a valid texture
if FAILED(hr)
return false;
pd3dDevice->BeginScene();
pd3dDevice->SetTransform(D3DTS_WORLD, &id);
pGrid->DrawDirectXMesh(pd3dDevice);
pd3dDevice->SetTransform(D3DTS_WORLD, &translate);
pBallMesh->DrawSubset(0);
pd3dDevice->SetTexture(0, g_pTexture);
pGrid->DrawDirectXMesh(pd3dDevice);
pd3dDevice->EndScene();
// Present the backbuffer contents to the display
pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
}
// release and shutdown Direct3D
shutdownDirect3D();
// Release the DirectSound buffer created above
if (DSBuffer)
{
DSBuffer->Release();
DSBuffer = NULL;
}
// shutdown DirectSound
shutdownDirectSound();
return (int) msg.wParam;
}
推荐答案
我看不到DrawDirectXMesh内部发生了什么,但是如果您只能看到顶点而不是我看到的实际面只能假定使用D3DPT_POINTLIST
而不是D3DPT_TRIANGLELIST
进行渲染.自己设置地板的顶点然后进行渲染可能会更容易.
至于跟随球的地板,是因为您没有在渲染球后重置世界矩阵.您似乎也在两次画地板:
I can''t see what''s happening inside of DrawDirectXMesh but If you can only see the vertex points instead of the actual faces that I can only assume it''s rendering withD3DPT_POINTLIST
instead ofD3DPT_TRIANGLELIST
. It might be easier to set up the vertices for the floor yourself and then render them.
As for the floor following the ball, it''s because you didn''t reset the world matrix after rendering the ball. You also seem to be drawing the floor twice:
pd3dDevice->SetTransform(D3DTS_WORLD, &id);
pGrid->DrawDirectXMesh(pd3dDevice); //<-Drawing the grid in the right place
pd3dDevice->SetTransform(D3DTS_WORLD, &translate);
pBallMesh->DrawSubset(0);
pd3dDevice->SetTexture(0, g_pTexture);
pGrid->DrawDirectXMesh(pd3dDevice); //<- Drawing the grid again with the same translation as the ball
pGrid
到底是什么?
请使用添加评论"链接进行回复
What exactly is pGrid
?
Please use the ''Add Comment'' link to reply
这篇关于平铺纹理未正确平铺.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文