• Advertisement
Sign in to follow this  

What is causing my first person camera not to yaw?

This topic is 1253 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i dont know why but i cant yaw and look around the scene, i can only pitch up and down


void Camera::update(float dt, Terrain* terrain, float offsetHeight)
    // Find the net direction the camera is traveling in (since the
    // camera could be running and strafing).
    // Poll keyboard.
    hr = mKeyboard->GetDeviceState(sizeof(mKeyboardState), (void**)&mKeyboardState);
    if (FAILED(hr))
        // Keyboard lost, zero out keyboard data structure.
        ZeroMemory(mKeyboardState, sizeof(mKeyboardState));

        // Try to acquire for next time we poll.
        hr = mKeyboard->Acquire();

    // Poll mouse.
    hr = mMouse->GetDeviceState(sizeof(DIMOUSESTATE2), (void**)&mMouseState);
    if (FAILED(hr))
        // Mouse lost, zero out mouse data structure.
        ZeroMemory(&mMouseState, sizeof(mMouseState));

        // Try to acquire for next time we poll.
        hr = mMouse->Acquire();

    D3DXVECTOR3 dir(0.0f, 0.0f, 0.0f);
    if( keyDown(DIK_W) )
        dir += mLookW;
    if( keyDown(DIK_S) )
        dir -= mLookW;
    if( keyDown(DIK_D) )
        dir += mRightW;
    if( keyDown(DIK_A) )
        dir -= mRightW;

    // Move at mSpeed along net direction.
    D3DXVec3Normalize(&dir, &dir);
    D3DXVECTOR3 newPos = mPosW + dir*mSpeed*dt;

    D3DXVECTOR3 tangent = newPos - mPosW;
    D3DXVec3Normalize(&tangent, &tangent);

    // Now move camera along tangent vector.
    mPosW += tangent*mSpeed*dt;

    mPosW = newPos;

    // We rotate at a fixed speed.
    pitch  = mouseDY() / 150.0f;
    yAngle = mouseDZ() / 150.0f;

    // Rotate camera's look and up vectors around the camera's right vector.
    D3DXMatrixRotationAxis(&R, &mRightW, pitch);
    D3DXVec3TransformCoord(&mLookW, &mLookW, &R);
    D3DXVec3TransformCoord(&mUpW, &mUpW, &R);

    // Rotate camera axes about the world's y-axis.
    D3DXMatrixRotationY(&R, yAngle);
    D3DXVec3TransformCoord(&mRightW, &mRightW, &R);
    D3DXVec3TransformCoord(&mUpW, &mUpW, &R);
    D3DXVec3TransformCoord(&mLookW, &mLookW, &R);

    // Rebuild the view matrix to reflect changes.

    //mViewProj = mView * mProj;


void Camera::buildView()
    // Keep camera's axes orthogonal to each other and of unit length.
    D3DXVec3Normalize(&mLookW, &mLookW);

    D3DXVec3Cross(&mUpW, &mLookW, &mRightW);
    D3DXVec3Normalize(&mUpW, &mUpW);

    D3DXVec3Cross(&mRightW, &mUpW, &mLookW);
    D3DXVec3Normalize(&mRightW, &mRightW);

    // Fill in the view matrix entries.

    float x = -D3DXVec3Dot(&mPosW, &mRightW);
    float y = -D3DXVec3Dot(&mPosW, &mUpW);
    float z = -D3DXVec3Dot(&mPosW, &mLookW);

    mView(0,0) = mRightW.x;
    mView(1,0) = mRightW.y;
    mView(2,0) = mRightW.z;
    mView(3,0) = x;   

    mView(0,1) = mUpW.x;
    mView(1,1) = mUpW.y;
    mView(2,1) = mUpW.z;
    mView(3,1) = y;  

    mView(0,2) = mLookW.x;
    mView(1,2) = mLookW.y;
    mView(2,2) = mLookW.z;
    mView(3,2) = z;   

    mView(0,3) = 0.0f;
    mView(1,3) = 0.0f;
    mView(2,3) = 0.0f;
    mView(3,3) = 1.0f;


Thanks if you can help

Share this post

Link to post
Share on other sites

What values have you looked at to determine the problem? What does MouseDZ() do? Is it ever non-zero? Have you tried using a time- or frame-varying value for yAngle to see if your rotation code works?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement