Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

OpenGL [C++ Direct3D9] 3rd Person Camera problems

This topic is 2716 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 based my code for a 3rd person camera off of a tutorial by swiftless, and it works just fine for my OpenGL projects (only the mouse input isn't as smooth). It's simple and yet effective. When I ported this code to use Direct3D and XInput for Xbox gamepads, the strafing doesn't work properly but everything else does so far. It likes to strafe in only one direction (axis). I've been at it for a while and can't figure out what's going on. Here's my code I use to update the camera (feel free to compare it to the above link).


/*
* Third person camera control functions
*/
void ThirdPersonCamera_Update( const XINPUT_GAMEPAD* pGamepad, float fTimeElapsed )
{
/*
* Right thumbstick (look)
*/
if( pGamepad->sThumbRY < -8000 )
{
TPCamera.vecRot.x += TPCamera.fRotSpeed; //= -3.0f * fTimeElapsed;
if( TPCamera.vecRot.x > 360.0f ) TPCamera.vecRot.x -= 360.0f;
}
if( pGamepad->sThumbRY > +8000 )
{
TPCamera.vecRot.x -= TPCamera.fRotSpeed; //= +3.0f * fTimeElapsed;
if( TPCamera.vecRot.x < -360.0f ) TPCamera.vecRot.x += 360.0f;
}
if( pGamepad->sThumbRX < -8000 )
{
TPCamera.vecRot.y += TPCamera.fRotSpeed; //= +3.0f * fTimeElapsed;
if( TPCamera.vecRot.y > 360.0f ) TPCamera.vecRot.y -= 360.0f;
}
if( pGamepad->sThumbRX > +8000 )
{
TPCamera.vecRot.y -= TPCamera.fRotSpeed; //= -3.0f * fTimeElapsed;
if( TPCamera.vecRot.y < -360.0f ) TPCamera.vecRot.y += 360.0f;
}

/*
* Left thumbstick (movement)
*/

// Move forward/backward
if( pGamepad->sThumbLY > +8000 )
{
float xrotrad, yrotrad;
yrotrad = ( TPCamera.vecRot.y / 180.0f * D3DX_PI );
xrotrad = ( TPCamera.vecRot.x / 180.0f * D3DX_PI );
TPCamera.vecPos.x += (float)(sin(yrotrad));
TPCamera.vecPos.y -= (float)(cos(yrotrad));
TPCamera.vecPos.z -= (float)(sin(xrotrad));
}
if( pGamepad->sThumbLY < -8000 )
{
float xrotrad, yrotrad;
yrotrad = ( TPCamera.vecRot.y / 180.0f * D3DX_PI );
xrotrad = ( TPCamera.vecRot.x / 180.0f * D3DX_PI );
TPCamera.vecPos.x -= (float)(sin(yrotrad));
TPCamera.vecPos.y += (float)(cos(yrotrad));
TPCamera.vecPos.z += (float)(sin(xrotrad));
}

// Move left/right (strafe)
if( pGamepad->sThumbLX < -8000 )
{
float yrotrad;
yrotrad = ( TPCamera.vecRot.y / 180.0f * D3DX_PI );
TPCamera.vecPos.x += (float)(cos(yrotrad)) * 0.5f;
TPCamera.vecPos.z += (float)(sin(yrotrad)) * 0.5f;
}
if( pGamepad->sThumbLX > +8000 )
{
float yrotrad;
yrotrad = ( TPCamera.vecRot.y / 180.0f * D3DX_PI );
TPCamera.vecPos.x -= (float)(cos(yrotrad)) * 0.5f;
TPCamera.vecPos.z -= (float)(sin(yrotrad)) * 0.5f;
}

if( TPCamera.vecRot.x < -30.0f )
TPCamera.vecRot.x = -30.0f;
if( TPCamera.vecRot.x > 90.0f )
TPCamera.vecRot.x = 90.0f;

// Camera zoom
if( pGamepad->wButtons & XINPUT_GAMEPAD_DPAD_DOWN )
TPCamera.fRadius += 5.0f;
if( pGamepad->wButtons & XINPUT_GAMEPAD_DPAD_UP )
TPCamera.fRadius -= 5.0f;
}



You can pretty much ignore the code that comes after the strafing part. Is it the strafing code, or does it have to do with my movement or rotation code? Been at this for hours and can't seem to get it working like I did with OpenGL. This sucks. Any ideas? Thanks.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!