OpenGL - Arcball camera rotation

I'm implementing arcball camera rotation, whereby a camera is looking at a coordinate and rotates around it in the x-axis or the y-axis such that the camera is circulating around it; the y-axis will be capped to prevent flipping.

Suffice it to say it's not producing the output I want as it isn't rotating around the target. I'm not sure where the problem may lie, though my code:

void Camera::rotate(float x, float y)
{
x *= pMouseSensitivity;
y *= pMouseSensitivity;

pYaw += x;
pPitch += y;

if (pPitch > 89.0f)
pPitch = 89.0f;
if (pPitch < -89.0f)
pPitch = -89.0f;

pPosition = glm::rotate(pPosition, -x, pUp);
pPosition = glm::rotate(pPosition, -y, pRight);
}


The rotate function takes in x and y from where the mouse position is at. These values are then added to yaw and pitch respectively before the position of the camera is rotated based on the x and y. I update the camera as follows:

void Camera::update()
{
pForward = pPosition - pTarget;
pRight = glm::normalize(glm::cross(pForward, pWorldUp));
pUp = glm::normalize(glm::cross(pForward, pRight));

pViewMat = glm::lookAt(pPosition, pTarget, pUp);
pProjMat = glm::perspective(pFieldView, pAspectRatio, pNearPlane, pFarPlane);
}


The world up vector is always vec3(0, 1, 0) and is unchanged throughout, for resetting the camera. I set the target of the camera with:

void Camera::orbitAround(glm::vec3 focus)
{
pTarget = focus;
}


This function would then take in an arbitrary point or even the position of a 3D rendered model. I have been looking at a few tutorials regarding arcball rotation, and from what I can understand it involves pTarget being what's looked at, and the rotation revolving around it. What does strike me is that I'm not using pitch and yaw, so will have to look into what I should be doing with them. Producing the arcball rotation is what confuses me, and I require some help on it. Pseudocode would be great!

• ...you're not doing anything with the 'pPitch' or 'pYaw' values. You put numbers into them and clamp them, but they don't actually influence anything in any of the code you show here. – Trevor Powell Jan 9 '15 at 14:19
• There's not enough information here to actually tell us what problem you're having, but if I was a betting man, I'd bet that you have code not shown that's using those 'pPitch' and 'pYaw' values to set the view matrix, instead of actually using the 'pViewMat' matrix that you set up in Camera::update(). Since your pPitch and pYaw values are crazypants and not actually related to the camera position or target position in any way, that'd explain why the camera isn't pointing at the target. – Trevor Powell Jan 9 '15 at 14:22
• That's what I think is the issue too. How can I use pitch and yaw to rotate around a point? – Poriferous Jan 9 '15 at 14:53
• You can't implement arcball control that way. If you're using pitch and yaw accumulators (such as your 'pPitch' and 'pYaw' values), then you're not building an arcball; you're just using normal euler angles, like you'd see in a ground-based FPS shooter. You already have all the right pieces in your code; you just want to actually render using 'pViewMat' as your view matrix, instead of using 'pPitch' and 'pYaw' to build a new one. – Trevor Powell Jan 10 '15 at 1:34
• Wherein, pitch and yaw are useless? I just remove the variables completely? Btw, unless I rotate a model around X by 90 degrees, the arcball rotation (where it rotates around a model) won't work properly. I find it quite strange, and without changing the camera code the arcball rotation either works or doesn't. – Poriferous Jan 12 '15 at 9:03