excessive / excessive/cpml

cpml.mat4.from_transform() computes the wrong rotation matrix.

Open
#83 1 comment 0 reactions 0 assignees View on GitHub
bug inconsistency
Dominant language
Lua
Stars
351
Forks
43
PR merge metrics
No merged PRs in 30d

Description

cpml/modules/mat4.lua:
```lua
local rx, ry, rz, rw = rot.x, rot.y, rot.z, rot.w

local rm = new {
1-2*(ry*ry+rz*rz), 2*(rx*ry-rz*rw), 2*(rx*rz+ry*rw), 0,
2*(rx*ry+rz*rw), 1-2*(rx*rx+rz*rz), 2*(ry*rz-rx*rw), 0,
2*(rx*rz-ry*rw), 2*(ry*rz+rx*rw), 1-2*(rx*rx+ry*ry), 0,
0, 0, 0, 1
}
```

Something about how that rotation matrix is calculated is wrong. Because when I replace it with my own function, that gets the rotation matrix the same way `mat4.from_quaternion` computes the matrix (using `q:to_angle_axis()`), I get the correct results that I was expecting:
```lua
function dbg_from_transform(trans, rot, scale)
local sm = cpml.mat4.new{
scale.x, 0, 0, 0,
0, scale.y, 0, 0,
0, 0, scale.z, 0,
0, 0, 0, 1,
}

local rm = cpml.mat4.from_angle_axis(rot:to_angle_axis())

local rsm = rm * sm

rsm[13] = trans.x
rsm[14] = trans.y
rsm[15] = trans.z

return rsm
end
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.