I have a camera that rotates around a target point on mouse move. How can I move the camera's position upwards/downwards related to the target position? So when camera is moved upwards the object is seen to go downwards and opposite.
I was trying to change target vector y, camera position vector y but none of it really worked:
void Camera::move(float dir)
{
m_target.y += dir;
}
and
void Camera::move(float dir)
{
m_pos.y += dir;
}
I got to confess I'm not strong at linear algebra and most likely that's the reason why I don't understand it well. I was trying to google it however all results are about forward/backward camera movement which is as easy as to change m_radius
class member.
My camera's position is described by radius, theta and phi angles (spherical coordinates it's called, I guess).
This is how I set position m_pos
and then call XMMatrixLookAtLH
setPosition(m_target.x + m_radius * cosf(m_theta) * cosf(m_phi), m_target.y + m_radius * sinf(m_theta), m_target.z + m_radius * cosf(m_theta) * sinf(m_phi));
setLookAt(XMLoadFloat3(&m_pos), XMVectorZero(), XMLoadFloat3(&m_up));
Target is always set in origin (0, 0, 0) because all my model data is loaded related to the origin.
I added target position effect to the setPosition()
method just in case I will ever need to change it.