Skip to content

libobs/graphics: Fix component order in quat_set - #86

Merged
zackees merged 2 commits into
obs-rust:masterfrom
b7216309-jpg:fix/quat-set-order
Oct 10, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
b7216309-jpg:fix/quat-set-order

Conversation

@b7216309-jpg

Copy link
Copy Markdown
Contributor

Description

quat_set in libobs/graphics/quat.h stores the quaternion reversed:

dst->m = _mm_set_ps(x, y, z, w);   /* _mm_set_ps takes the high lane first */

So quat_set(&q, 1, 2, 3, 4) gives x=4, y=3, z=2, w=1, and quat_set(&q, 0, 0, 0, 1) is not the identity. This PR passes the lanes high first, _mm_set_ps(w, z, y, x), the way vec3_set and vec4_set already do.

It also fixes the quat_set entry in docs/sphinx/reference-libobs-graphics-quat.rst. The signature listed only x, y, and the z parameter was named y.

Motivation and Context

Found while porting axisang.c (#83): test_axisang.c built its inputs with quat_set and failed in Tier 2 with the original C (OFF). Nothing in the tree calls quat_set, but it is public API. obslua.i and obspython.i %include "graphics/quat.h", so Lua and Python scripts can call it. Any script that does gets a reversed quaternion today and the intended one after this change.

How Has This Been Tested?

  • Commits: a RED cmocka test first (test/cmocka/test_quat.c: component order, ptr[] aliasing, and quat_set(0, 0, 0, 1) == quat_identity), then the fix.
  • No cmocka here (Windows), so I checked the header itself with MSVC: a small program calling quat_set(&q, 1, 2, 3, 4) from graphics/quat.h prints x=4 y=3 z=2 w=1 on master and x=1 y=2 z=3 w=4 with the fix. The cmocka test first runs in Tier 2 CI. On Linux and macOS, _mm_set_ps comes from SIMDe with the same argument order.
  • python ci/local_gate.py --lane lint passes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

🤖 Generated with Claude Code

b7216309-jpg and others added 2 commits October 10, 2026 10:31
quat_set(&q, 1, 2, 3, 4) must give x=1, y=2, z=3, w=4, and
quat_set(&q, 0, 0, 0, 1) must equal quat_identity. Today it stores
x=4, y=3, z=2, w=1 (checked with MSVC against graphics/quat.h), so both
cases fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
quat_set passed x, y, z, w to _mm_set_ps, which takes its arguments
high lane first, so the quaternion was stored reversed: x got w, y got
z, z got y and w got x. vec3_set and vec4_set already pass the lanes
high first. Nothing in the tree calls quat_set, but it is public API
and the Lua and Python scripting bindings expose quat.h.

Also fixes the quat_set entry in the docs, which listed only x and y
in the signature and named the z parameter y.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zackees
zackees merged commit a60b38f into obs-rust:master Oct 10, 2026
22 checks passed
b7216309-jpg added a commit to b7216309-jpg/obs-studio that referenced this pull request Oct 10, 2026
obs-rust#86 fixed quat_set's component order, so the field-by-field helper
added to work around it is no longer needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants