旋转的茶壶

来源:互联网 发布:js div 滚动条到底部 编辑:程序博客网 时间:2024/04/28 13:05
这里只贴关键代码,
void RenderScene(float _time){    D3DXMATRIX rx,ry;    static float y = 0.0f,x = 0.0f;    D3DXMatrixRotationY(&ry,y);    y+=_time;    if(y>=6.28f)    {        y =0.0f;    }    D3DXMatrixRotationX(&rx,x);    x+=_time;    if(x>=6.28f)    {        x = 0.0f;    }    D3DXMATRIX p = rx*ry;    g_device->SetTransform(D3DTS_WORLD,&p);    g_device->Clear(0,0,D3DCLEAR_TARGET  ,0xffffffff,1.0f,0);    g_device->BeginScene();    g_mesh->DrawSubset(0);    //    g_device->EndScene();    g_device->Present(0,0,0,0);}

//主函数WinMain里面
static float ftime = (float)timeGetTime();        while (msg.message!=WM_QUIT)    {        if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))        {             TranslateMessage (&msg);             DispatchMessage (&msg);        }        //        else        {            float starttime = (float)timeGetTime();            float timedelta = (starttime - ftime)*0.001f;            RenderScene(timedelta);            ftime = starttime;        }    }


原创粉丝点击