Hello, I used Lighting fundamentals to create cylinders and spheres to represent atoms and connections in proteins. Everything works fine except colours and lighting.
To connect 2 atoms, I calculated vector between atomA and atomB and used float3(0, 1, 0) vector to find the correct rotation matrix with this function:
private func rotateMatrix(v1: float3, v2: float3)->float4x4
{
let axis: float3 = cross(v1, v2);
let cosA: Float = dot( v1, v2 );
let k = 1.0 / (1.0 + cosA);
let result = float4x4( [(axis.x * axis.x * k) + cosA,
(axis.y * axis.x * k) - axis.z,
(axis.z * axis.x * k) + axis.y, 0],
[(axis.x * axis.y * k) + axis.z,
(axis.y * axis.y * k) + cosA,
(axis.z * axis.y * k) - axis.x, 0],
[(axis.x * axis.z * k) - axis.y,
(axis.y * axis.z * k) + axis.x,
(axis.z * axis.z * k) + cosA, 0],
[0,0,0,1]
);
return result;
}
So in the end I changed modelMatrix property in Transform extension to return translation * rotateMatrix(v1,v2)* scale
What do you think where to look to fix this problem?