RE: LDView 4.2 Released
2017-10-22, 20:52 (This post was last modified: 2017-10-22, 22:20 by Michael Horvath.)
2017-10-22, 20:52 (This post was last modified: 2017-10-22, 22:20 by Michael Horvath.)
(2017-10-22, 4:16)Travis Cobbs Wrote:(2017-10-22, 0:24)Michael Horvath Wrote: Could you explain this more? I thought that "camera.rotate" takes three Euler angles as input. Am I wrong? I have written a routine for another program that can convert a matrix to Euler angles, and could adapt that to here. Will that approach not work?
LDLCamera::rotate should in fact take the Euler angles, but a transformation matrix has a lot more in it than just that. If you have a rotation-only transformation matrix, then what you're doing is probably fine.
Will this create the correct type of matrix?
Code:
TCFloat identity[16] =
{
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
TCVector::calcRotationMatrix(cameraXRotate, cameraYRotate, identity);
Also, I have written a matrix to euler converter in Lua for another project. Could someone explain how to convert it to C++?
Code:
-- Adapted from https://www.geometrictools.com/Documentation/EulerAngles.pdf, section 2.6
function MatrixToEuler(in_matrix)
local r00 = in_matrix[9]
local r01 = in_matrix[8]
local r02 = in_matrix[7]
local r10 = in_matrix[6]
local r11 = in_matrix[5]
local r12 = in_matrix[4]
local r20 = in_matrix[3]
local r21 = in_matrix[2]
local r22 = in_matrix[1]
local angleX = 0
local angleY = 0
local angleZ = 0
if (r20 < 1) then
if (r20 > -1) then
angleX = atan2(r10, r00)
angleY = asin(-r20)
angleZ = atan2(r21, r22)
else
angleX = -atan2(-r12, r11)
angleY = 90
angleZ = 0
end
else
angleX = atan2(-r12, r11)
angleY = -90
angleZ = 0
end
return {angleX, angleY, angleZ}
end