I'm having issues with rotating 3D objects towards a location.
As a test I tried to rotate every object towards the origin.
The main part of the code is below along with a resulting image.
(fyi my unit system is not standard, x-horazantal, z-depth(vertical from this images perspective), y-up(towards camera)
When the objects are positioned towards a point the flat surface points towards the target, looks perpendicular. The red lines drawn show when the objects point at the center correctly. If I add PI/2 to the rotation then the diagonals point at the center.
The resulting image should form a layered ring like design of aligned objects.
But it seems to create a series of 4 hyperbolas.
I'm guessing I made a simple error.
float3 origin = {0.0f, 0.0f, 0.0f};
float3 unitVector = normalize(make_float3(origin.x-object.x,
origin.y-object.y,
origin.z-object.z));
//x,z are the surface plain : y is vertical : atan2f returns -PI to PI
float rotationRadians = atan2f(unitVector.x, unitVector.z);
XMMATRIX rotateMat = XMMATRIX(
cosf(rotationRadians), 0.0f, sinf(rotationRadians), 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
-sinf(rotationRadians), 0.0f, cosf(rotationRadians), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);