Skip to content

Conversation

Copy link

Copilot AI commented Nov 30, 2025

Implements the new vmath functions from Defold 1.9.4 (defold/defold#9438) in allocation-free xmath style.

New Functions

  • quat_matrix4(q, m) - Extract quaternion from matrix4 rotation component
  • matrix4_compose(m, translation, rotation, scale) - Compose TRS matrix from vector3/4 + quat + vector3
  • matrix4_scale(m, scale) - Create scale matrix from vector3, uniform number, or x/y/z numbers
  • clamp(...) - Clamp numbers or vectors per-component; supports scalar or vector min/max bounds

Usage

local q = vmath.quat()
local m = vmath.matrix4()
local v = vmath.vector3(5, 10, 15)

-- Extract rotation from matrix
xmath.quat_matrix4(q, some_matrix)

-- Compose TRS matrix
xmath.matrix4_compose(m, position, rotation, scale)

-- Scale matrix variants
xmath.matrix4_scale(m, vmath.vector3(2, 2, 2))
xmath.matrix4_scale(m, 2)        -- uniform
xmath.matrix4_scale(m, 1, 2, 3)  -- x, y, z

-- Clamp (returns value for numbers, modifies in-place for vectors)
local clamped = xmath.clamp(value, 0, 1)
xmath.clamp(v, v, 0, 10)  -- per-component with scalar bounds
xmath.clamp(v, v, min_vec, max_vec)  -- per-component with vector bounds
Original prompt

This section details on the original issue you should resolve

<issue_title>Support Defold 1.9.4 VMath Additions</issue_title>
<issue_description>defold/defold#9438

vmath.quat_matrix4 - get quaternion from matrix4
vmath.matrix4_compose - create matrix4 from translation (vector3|vector4), rotation (quaternion) and scale (vector3)
vmath.matrix4_scale - create matrix4 from scale (vector3) or from number (uniform scale) or 3 number (x, y, z)
vmath.clamp - clamp input value in range [min, max]. Input value can be number, vector, vector3, vector4. In case of vector type clamp applies per vector component. min, max also can be number, vector, vector3, vector4.</issue_description>

Comments on the Issue (you are @copilot in this section)

@thejustinwalsh Nice, i'll take a crack this weekend.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits November 30, 2025 02:18
…ix4_scale, clamp

Co-authored-by: thejustinwalsh <72912+thejustinwalsh@users.noreply.github.com>
…ation

Co-authored-by: thejustinwalsh <72912+thejustinwalsh@users.noreply.github.com>
Co-authored-by: thejustinwalsh <72912+thejustinwalsh@users.noreply.github.com>
Co-authored-by: thejustinwalsh <72912+thejustinwalsh@users.noreply.github.com>
Copilot AI changed the title [WIP] Support Defold 1.9.4 vmath additions Support Defold 1.9.4 VMath Additions Nov 30, 2025
Copilot AI requested a review from thejustinwalsh November 30, 2025 02:23
Copilot finished work on behalf of thejustinwalsh November 30, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Defold 1.9.4 VMath Additions

2 participants