关于DirectX 3D中画图问题

Koo 2013-07-18 03:14:35
我想画个圆柱体
下面是显示代码:
bool Display(float timeDelta)
{
if( Device )
{
static float angle = (3.0f * D3DX_PI) / 2.0f;
static float height = 5.0f;
if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f )
angle -= 0.5f * timeDelta;

if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f )
angle += 0.5f * timeDelta;

if( ::GetAsyncKeyState(VK_UP) & 0x8000f )
height += 5.0f * timeDelta;
if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f )
height -= 5.0f * timeDelta;
D3DXVECTOR3 position( cosf(angle) * 7.0f, height, sinf(angle) * 7.0f );
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX V;
D3DXMatrixLookAtLH(&V, &position, &target, &up);
Device->SetTransform(D3DTS_VIEW, &V);
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
Device->BeginScene();
if((float)timeGetTime()-timenow<500)
{
for(int i = 0; i < 3; i++)
{
Device->SetMaterial(&Mtrls[i]);
Device->SetTransform(D3DTS_WORLD, &Worlds[i]);
Objects[i]->DrawSubset(0);
}
}
else
{
//timenow=(float)timeGetTime();
srand((unsigned)time(NULL));
int r=rand()%6;
D3DXMATRIX Rx,Ry,Rz,R,p;
D3DXMatrixRotationX(&Rx,(float)atan(DirectionSet[r][1]/DirectionSet[r][2]));
D3DXMatrixRotationX(&Ry,(float)atan(DirectionSet[r][2]/DirectionSet[r][0]));
D3DXMatrixRotationX(&Rz,(float)atan(DirectionSet[r][0]/DirectionSet[r][1]));
D3DXMatrixTranslation(&p,len[0]*DirectionSet[r][0]/2,len[0]*DirectionSet[r][1]/2,len[0]*DirectionSet[r][2]/2);
p=Rx*Ry*Rz*R;
Device->SetTransform(D3DTS_WORLD,&p);
Device->SetMaterial(&Mtrls[0]);
Objects[0]->DrawSubset(0);
}
Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}

我就一共定义了6个方向,我想让它0.5s以后随机转变方向
float len[3]={0.5f,2.0f,2.5f};
float CurrentDirection[3][3]={0.0f,0.0f,1.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f};
float DirectionSet[6][3]={1.0f,0.01f,0.01f,0.01f,0.01f,1.0f,-1.0f,0.01f,0.01f,0.01f,0.01f,-1.0f,0.01f,1.0f,0.01f,0.01f,-1.0f,0.01f};

但是0.5s以后它画出来的怎么是乱七八糟的东西,连圆柱都没有了?
这是一开始的0.5s内显示出来的东西

然后0.5s之后就显示这些乱七八糟的了。。。

...全文
115 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
leizh007 2013-07-18
  • 打赏
  • 举报
回复
D3DXMatrixRotationX(&Rx,(float)atan(DirectionSet[r][1]/DirectionSet[r][2]));
            D3DXMatrixRotationY(&Ry,(float)atan(DirectionSet[r][2]/DirectionSet[r][0]));
            D3DXMatrixRotationZ(&Rz,(float)atan(DirectionSet[r][0]/DirectionSet[r][1]));
            D3DXMatrixTranslation(&R,len[0]*DirectionSet[r][0]/2,len[0]*DirectionSet[r][1]/2,len[0]*DirectionSet[r][2]/2);

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧