Directx11教程(58) 鼠标控制摄像机

       本篇教程我们实现鼠标旋转摄像机的操作。主要就是按下鼠标左键的时候,根据鼠标的移动对摄像机进行pitch, raw的组合旋转。具体修改代码是在D3CClass类中,增加对鼠标事件的处理:

case WM_LBUTTONDOWN:
    if( wparam & MK_LBUTTON )
        {
        SetCapture(hwnd);

        m_OldMousePos.x = LOWORD(lparam);
        m_OldMousePos.y = HIWORD(lparam);
        }
    return 0;

case WM_LBUTTONUP:
    ReleaseCapture();
    return 0;

case WM_MOUSEMOVE:
    if( wparam & MK_LBUTTON )
        {
        mousePos.x = (int)LOWORD(lparam);
        mousePos.y = (int)HIWORD(lparam);

        dx = mousePos.x - m_OldMousePos.x;
        dy = mousePos.y - m_OldMousePos.y;
        //通过鼠标转动摄像机
        m_Graphics->m_Camera->pitch(dy * 0.0087266f);
        m_Graphics->m_Camera->yaw(dx * 0.0087266f);

        m_OldMousePos = mousePos;
        }
    return 0;

完整的代码请参考:

工程文件myTutorialD3D11_53

代码下载:

https://files.cnblogs.com/mikewolf2002/d3d1150-58.zip

https://files.cnblogs.com/mikewolf2002/pictures.zip

posted on 2012-08-10 19:42  迈克老狼2012  阅读(1828)  评论(0编辑  收藏  举报

导航