Moving on a sphere facing center
Posted on 2001-08-05
Is there an easy way (a supplied function or so) in DX8 to set the view matrix so that the viewer will be able to move around (as on a sphere) an object in all directions always facing the centre of the sphere?
What I do now is this (this allows me to move horizontally around the object in a circle and straight up and down always facing the object):
long lElapsedTime = timeGetTime() - m_dwTime;
m_dwTime = timeGetTime();
fHorzPos += fHorzSpeed * lElapsedTime;
vFromPt.x = sinf(fHorzPos) * 60.0f;
vFromPt.z = cosf(fHorzPos) * 60.0f;
fVertPos += fVertSpeed * lElapsedTime;
vFromPt.y = fVertPos * 60.0f;
D3DXMatrixLookAtLH(&matView, &vFromPt, &vLookatPt, &vUpVec);
What I want is that when I move up or down, I always have the same distance to the object.
Do I have to do the calculations myself or is there already a function for this in DX8?