# How do I move a target camera along Y axis

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_posand 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));


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.

• Spherical coordinates are used to calculate the camera's lookat, up and right vectors, not position. Jan 9, 2018 at 10:19
• @Hermetix so there is no way I can achieve the desired result with such coordinate system? Jan 9, 2018 at 10:33
• You will have to show us your code that calculates the camera's orientation/position. Basically we don't know exactly what "m_target" and "m_pos" represent. Jan 9, 2018 at 11:03
• @Hermetix added Jan 9, 2018 at 11:18