I have multiple objects moving about in a 3D space and am looking for ways to, on button press, have the camera snap and follow the object chosen.
Is there a way to make
Is there a way to make use of each object's worldMatrix?
Object matrix can be represented this way:
objx.x objx.y objx.z 0 //m[0][0]..m[0][3] or _11, _12, _13, _14
objy.x objy.y objy.z 0 //m[1][0]..m[1][3] or _21, _22, _23, _24
objz.x objz.y objz.z 0 //m[2][0]..m[2][3] or _31, _32, _33, _34
objpos.x objpos.y objpos.z 1 //m[3][0]..m[3][3] or _41, _42, _43, _44
Where m[][]
and _11
.._44
are corresponding elements of D3DMATRIX
, objpos - object position vector, objx - object x ('local x" transformed to world space) vector, etc.
So as long as the last column (m[0..3][3]) is 0, 0, 0, 1 you can extract object position and its "x", "y", "z" vectors ("side", "up", "front" - which is which depends on application) from matrix. If last column is not "0, 0, 0, 1", then it is projection matrix and you can't extract object data from it this easily.
From there you could do anything you want with your camera.