![]() |
#2
peach54602013-07-18 15:47
|
下面是显示代码:

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;
}
{
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};
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内显示出来的东西
只有本站会员才能查看附件,请 登录
二三图是之后显示出来的东西
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录