method interpolate(Transform4D other, float t)
float* a = @f + idx * 4
float* b = @other.f + other.idx * 4
float* r = @f + (idx + 25) * 4
for i = 0 to 24
r[i] = a[i] + (b[i] - a[i]) * t
next
idx += 25 ; Update the matrix index
end method
method interpolate_SSE(Transform4D other, float t)
float* a = @f + idx * 4
float* b = @other.f + other.idx * 4
float* r = @f + (idx + 25) * 4
; Load the interpolation factor into an SSE register
movss xmm7, t
shufps xmm7, xmm7, 0
; Perform interpolation using SSE instructions
mov ecx, 6 ; Loop counter (6 iterations for 24 elements)
mov esi, a
mov edi, b
mov edx, r
.loop:
movaps xmm0, [esi]
movaps xmm1, [edi]
subps xmm1, xmm0
mulps xmm1, xmm7
addps xmm0, xmm1
movaps [edx], xmm0
add esi, 16
add edi, 16
add edx, 16
dec ecx
jnz .loop
idx += 25 ; Update the matrix index
end method
method interpolate_AVX(Transform4D other, float t)
float* a = @f + idx * 4
float* b = @other.f + other.idx * 4
float* r = @f + (idx + 25) * 4
; Load the interpolation factor into an AVX register
vbroadcastss ymm7, t
; Perform interpolation using AVX instructions
mov rcx, 3 ; Loop counter (3 iterations for 24 elements)
mov rsi, a
mov rdi, b
mov rdx, r
.loop:
vmovaps ymm0, [rsi]
vmovaps ymm1, [rdi]
vsubps ymm1, ymm1, ymm0
vmulps ymm1, ymm1, ymm7
vaddps ymm0, ymm0, ymm1
vmovaps [rdx], ymm0
add rsi, 32
add rdi, 32
add rdx, 32
dec rcx
jnz .loop
idx += 25 ; Update the matrix index
end method
method interpolate(Transform4D other, float t)
if t < 0.0 or t > 1.0
print "Error: Interpolation factor t must be between 0 and 1."
return
endif
float* a = @f + idx * 4
float* b = @other.f + other.idx * 4
float* r = @f + (idx + 25) * 4
int i
for i = 0 to 24
r[i] = a[i] + (b[i] - a[i]) * t
next
idx += 25 ; Update the matrix index
end method
QuoteWhy not just use an electric heater?
method inverse()
float* m = @f + idx * 4
float* inv = @f + (idx + 25) * 4
; Calculate the adjugate matrix
inv[0] = m[6] * m[12] * m[18] - m[6] * m[13] * m[17] - m[11] * m[7] * m[18] + m[11] * m[8] * m[17] + m[16] * m[7] * m[13] - m[16] * m[8] * m[12]
inv[1] = -m[1] * m[12] * m[18] + m[1] * m[13] * m[17] + m[11] * m[2] * m[18] - m[11] * m[3] * m[17] - m[16] * m[2] * m[13] + m[16] * m[3] * m[12]
inv[2] = m[1] * m[7] * m[18] - m[1] * m[8] * m[17] - m[6] * m[2] * m[18] + m[6] * m[3] * m[17] + m[16] * m[2] * m[8] - m[16] * m[3] * m[7]
inv[3] = -m[1] * m[7] * m[13] + m[1] * m[8] * m[12] + m[6] * m[2] * m[13] - m[6] * m[3] * m[12] - m[11] * m[2] * m[8] + m[11] * m[3] * m[7]
inv[4] = -m[5] * m[12] * m[18] + m[5] * m[13] * m[17] + m[10] * m[7] * m[18] - m[10] * m[8] * m[17] - m[15] * m[7] * m[13] + m[15] * m[8] * m[12]
inv[5] = m[0] * m[12] * m[18] - m[0] * m[13] * m[17] - m[10] * m[2] * m[18] + m[10] * m[3] * m[17] + m[15] * m[2] * m[13] - m[15] * m[3] * m[12]
inv[6] = -m[0] * m[7] * m[18] + m[0] * m[8] * m[17] + m[5] * m[2] * m[18] - m[5] * m[3] * m[17] - m[15] * m[2] * m[8] + m[15] * m[3] * m[7]
inv[7] = m[0] * m[7] * m[13] - m[0] * m[8] * m[12] - m[5] * m[2] * m[13] + m[5] * m[3] * m[12] + m[10] * m[2] * m[8] - m[10] * m[3] * m[7]
inv[8] = m[5] * m[11] * m[18] - m[5] * m[13] * m[16] - m[10] * m[6] * m[18] + m[10] * m[8] * m[16] + m[15] * m[6] * m[13] - m[15] * m[8] * m[11]
inv[9] = -m[0] * m[11] * m[18] + m[0] * m[13] * m[16] + m[10] * m[1] * m[18] - m[10] * m[3] * m[16] - m[15] * m[1] * m[13] + m[15] * m[3] * m[11]
inv[10] = m[0] * m[6] * m[18] - m[0] * m[8] * m[16] - m[5] * m[1] * m[18] + m[5] * m[3] * m[16] + m[15] * m[1] * m[8] - m[15] * m[3] * m[6]
inv[11] = -m[0] * m[6] * m[13] + m[0] * m[8] * m[11] + m[5] * m[1] * m[13] - m[5] * m[3] * m[11] - m[10] * m[1] * m[8] + m[10] * m[3] * m[6]
inv[12] = -m[5] * m[11] * m[17] + m[5] * m[12] * m[16] + m[10] * m[6] * m[17] - m[10] * m[7] * m[16] - m[15] * m[6] * m[12] + m[15] * m[7] * m[11]
inv[13] = m[0] * m[11] * m[17] - m[0] * m[12] * m[16] - m[10] * m[1] * m[17] + m[10] * m[2] * m[16] + m[15] * m[1] * m[12] - m[15] * m[2] * m[11]
inv[14] = -m[0] * m[6] * m[17] + m[0] * m[7] * m[16] + m[5] * m[1] * m[17] - m[5] * m[2] * m[16] - m[15] * m[1] * m[7] + m[15] * m[2] * m[6]
inv[15] = m[0] * m[6] * m[12] - m[0] * m[7] * m[11] - m[5] * m[1] * m[12] + m[5] * m[2] * m[11] + m[10] * m[1] * m[7] - m[10] * m[2] * m[6]
inv[16] = m[4] * m[12] * m[18] - m[4] * m[13] * m[17] - m[9] * m[7] * m[18] + m[9] * m[8] * m[17] + m[14] * m[7] * m[13] - m[14] * m[8] * m[12]
inv[17] = -m[0] * m[12] * m[18] + m[0] * m[13] * m[17] + m[9] * m[2] * m[18] - m[9] * m[3] * m[17] - m[14] * m[2] * m[13] + m[14] * m[3] * m[12]
inv[18] = m[0] * m[7] * m[18] - m[0] * m[8] * m[17] - m[4] * m[2] * m[18] + m[4] * m[3] * m[17] + m[14] * m[2] * m[8] - m[14] * m[3] * m[7]
inv[19] = -m[0] * m[7] * m[13] + m[0] * m[8] * m[12] + m[4] * m[2] * m[13] - m[4] * m[3] * m[12] - m[9] * m[2] * m[8] + m[9] * m[3] * m[7]
inv[20] = -m[4] * m[11] * m[18] + m[4] * m[13] * m[16] + m[9] * m[6] * m[18] - m[9] * m[8] * m[16] - m[14] * m[6] * m[13] + m[14] * m[8] * m[11]
inv[21] = m[0] * m[11] * m[18] - m[0] * m[13] * m[16] - m[9] * m[1] * m[18] + m[9] * m[3] * m[16] + m[14] * m[1] * m[13] - m[14] * m[3] * m[11]
inv[22] = -m[0] * m[6] * m[18] + m[0] * m[8] * m[16] + m[4] * m[1] * m[18] - m[4] * m[3] * m[16] - m[14] * m[1] * m[8] + m[14] * m[3] * m[6]
inv[23] = m[0] * m[6] * m[13] - m[0] * m[8] * m[11] - m[4] * m[1] * m[13] + m[4] * m[3] * m[11] + m[9] * m[1] * m[8] - m[9] * m[3] * m[6]
inv[24] = m[4] * m[11] * m[17] - m[4] * m[12] * m[16] - m[9] * m[6] * m[17] + m[9] * m[7] * m[16] + m[14] * m[6] * m[12] - m[14] * m[7] * m[11]
inv[25] = -m[0] * m[11] * m[17] + m[0] * m[12] * m[16] + m[9] * m[1] * m[17] - m[9] * m[2] * m[16] - m[14] * m[1] * m[12] + m[14] * m[2] * m[11]
inv[26] = m[0] * m[6] * m[17] - m[0] * m[7] * m[16] - m[4] * m[1] * m[17] + m[4] * m[2] * m[16] + m[14] * m[1] * m[7] - m[14] * m[2] * m[6]
inv[27] = -m[0] * m[6] * m[12] + m[0] * m[7] * m[11] + m[4] * m[1] * m[12] - m[4] * m[2] * m[11] - m[9] * m[1] * m[7] + m[9] * m[2] * m[6]
; Calculate the determinant
float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12] + m[4] * inv[16]
; Check if the determinant is zero (matrix is not invertible)
if det == 0
print "Error: Matrix is not invertible"
return
endif
; Multiply the adjugate matrix by the reciprocal of the determinant
float invDet = 1.0 / det
for i = 0 to 24
inv[i] *= invDet
next
; Update the matrix index
idx += 25
end method
method inverse()
float* m = @f + idx * 4
float* inv = @f + (idx + 25) * 4
; Create an identity matrix
for i = 0 to 24
inv[i] = 0.0
inv[0] = 1.0
inv[6] = 1.0
inv[12] = 1.0
inv[18] = 1.0
inv[24] = 1.0
; Perform Gaussian elimination
for i = 0 to 4
; Find pivot element
float pivot = m[i * 5 + i]
int pivotRow = i
for j = i + 1 to 4
if abs(m[j * 5 + i]) > abs(pivot)
pivot = m[j * 5 + i]
pivotRow = j
; Swap rows if necessary
if pivotRow != i
for k = 0 to 4
float temp = m[i * 5 + k]
m[i * 5 + k] = m[pivotRow * 5 + k]
m[pivotRow * 5 + k] = temp
temp = inv[i * 5 + k]
inv[i * 5 + k] = inv[pivotRow * 5 + k]
inv[pivotRow * 5 + k] = temp
; Divide row by pivot element
float invPivot = 1.0 / pivot
for k = 0 to 4
m[i * 5 + k] *= invPivot
inv[i * 5 + k] *= invPivot
; Subtract row from other rows to eliminate pivot element
for j = 0 to 4
if j != i
float factor = m[j * 5 + i]
for k = 0 to 4
m[j * 5 + k] -= factor * m[i * 5 + k]
inv[j * 5 + k] -= factor * inv[i * 5 + k]
; Copy the inverted matrix back to the original matrix
for i = 0 to 24
m[i] = inv[i]
idx += 25 ; Update the matrix index
end method
[quote]This method uses Gaussian elimination to calculate the inverse of the current matrix. Here's how it works:
It starts by creating an identity matrix of the same size as the current matrix. This identity matrix will be transformed into the inverse matrix during the elimination process.
It performs Gaussian elimination on the current matrix and the identity matrix simultaneously. The steps are as follows:
For each row, it finds the pivot element (the element with the largest absolute value in the current column).
If necessary, it swaps rows to bring the pivot element to the diagonal position.
It divides the current row by the pivot element to make the pivot element equal to 1.
It subtracts multiples of the current row from the other rows to eliminate the pivot element from those rows.
After the elimination process, the identity matrix has been transformed into the inverse matrix.
Finally, it copies the inverted matrix back to the original matrix and updates the matrix index.
Note that this method assumes that the matrix is invertible. If the matrix is singular or non-invertible, the method may produce incorrect results or encounter division by zero.
Add to Conversation[/quote]
method setRotationX(float angle)
pushmatrix()
idx += 25
identity()
float g at @f + (idx * 4)
float c = cos(rad(angle))
float s = sin(rad(angle))
g[6] = c
g[7] = s
g[11] = -s
g[12] = c
mulmatrix()
end method
method setRotationY(float angle)
pushmatrix()
idx += 25
identity()
float g at @f + (idx * 4)
float c = cos(rad(angle))
float s = sin(rad(angle))
g[0] = c
g[2] = -s
g[10] = s
g[12] = c
mulmatrix()
end method
method setRotationZ(float angle)
pushmatrix()
idx += 25
identity()
float g at @f + (idx * 4)
float c = cos(rad(angle))
float s = sin(rad(angle))
g[0] = c
g[1] = s
g[5] = -s
g[6] = c
mulmatrix()
end method
method setRotationW(float angle)
pushmatrix()
idx += 25
identity()
float g at @f + (idx * 4)
float c = cos(rad(angle))
float s = sin(rad(angle))
g[0] = c
g[3] = s
g[15] = -s
g[18] = c
mulmatrix()
end method
method setTranslation(float x, y, z, w)
pushmatrix()
idx += 25
identity()
float g at @f + (idx * 4)
g[20] = x
g[21] = y
g[22] = z
g[23] = w
mulmatrix()
end method
method setScale(float x, y, z, w)
pushmatrix()
idx += 25
identity()
float g at @f + (idx * 4)
g[0] = x
g[6] = y
g[12] = z
g[18] = w
mulmatrix()
end method
method setShear(float xy, xz, yz, xw, yw, zw)
pushmatrix()
idx += 25
identity()
float g at @f + (idx * 4)
g[1] = xy
g[2] = xz
g[7] = yz
g[3] = xw
g[8] = yw
g[13] = zw
mulmatrix()
end method
method setPerspective(float fov, aspect, nearPlane, farPlane)
pushmatrix()
idx += 25
clear()
float g at @f + (idx * 4)
float f = 1.0 / tan(rad(fov) / 2.0)
g[0] = f / aspect
g[6] = f
g[12] = (farPlane + nearPlane) / (nearPlane - farPlane)
g[13] = (2.0 * farPlane * nearPlane) / (nearPlane - farPlane)
g[14] = -1.0
mulmatrix()
end method
method setOrthographic(float left, right, bottom, top, nearPlane, farPlane)
pushmatrix()
idx += 25
clear()
float g at @f + (idx * 4)
g[0] = 2.0 / (right - left)
g[6] = 2.0 / (top - bottom)
g[12] = -2.0 / (farPlane - nearPlane)
g[20] = -(right + left) / (right - left)
g[21] = -(top + bottom) / (top - bottom)
g[22] = -(farPlane + nearPlane) / (farPlane - nearPlane)
g[24] = 1.0
mulmatrix()
end method
method mulMatrixSIMD(Transform4D other)
float* a = @f + idx * 4
float* b = @other.f + other.idx * 4
float* r = @f + (idx + 25) * 4
; Assuming SSE instructions are available
; Perform matrix multiplication using SIMD instructions
; Unroll the loops for better performance
; Example using SSE intrinsics (pseudocode)
for i = 0 to 4
for j = 0 to 4
__m128 sum = _mm_setzero_ps()
for k = 0 to 4
__m128 a_vec = _mm_load_ps(a + i * 5 + k)
__m128 b_vec = _mm_load_ps(b + k * 5 + j)
__m128 prod = _mm_mul_ps(a_vec, b_vec)
sum = _mm_add_ps(sum, prod)
_mm_store_ps(r + i * 5 + j, sum)
idx += 25 ; Update the matrix index
end method
method inverse()
float* m = @f + idx * 4
float* inv = @f + (idx + 25) * 4
; Calculate the adjugate matrix
inv[0] = m[6] * m[12] * m[18] - m[6] * m[13] * m[17] - m[11] * m[7] * m[18] + m[11] * m[8] * m[17] + m[16] * m[7] * m[13] - m[16] * m[8] * m[12]
inv[1] = -m[1] * m[12] * m[18] + m[1] * m[13] * m[17] + m[11] * m[2] * m[18] - m[11] * m[3] * m[17] - m[16] * m[2] * m[13] + m[16] * m[3] * m[12]
inv[2] = m[1] * m[7] * m[18] - m[1] * m[8] * m[17] - m[6] * m[2] * m[18] + m[6] * m[3] * m[17] + m[16] * m[2] * m[8] - m[16] * m[3] * m[7]
inv[3] = -m[1] * m[7] * m[13] + m[1] * m[8] * m[12] + m[6] * m[2] * m[13] - m[6] * m[3] * m[12] - m[11] * m[2] * m[8] + m[11] * m[3] * m[7]
inv[4] = m[21] * m[12] * m[18] - m[21] * m[13] * m[17] - m[11] * m[22] * m[18] + m[11] * m[23] * m[17] + m[16] * m[22] * m[13] - m[16] * m[23] * m[12]
inv[5] = -m[5] * m[12] * m[18] + m[5] * m[13] * m[17] + m[10] * m[7] * m[18] - m[10] * m[8] * m[17] - m[15] * m[7] * m[13] + m[15] * m[8] * m[12]
inv[6] = m[5] * m[11] * m[18] - m[5] * m[13] * m[16] - m[10] * m[6] * m[18] + m[10] * m[8] * m[16] + m[15] * m[6] * m[13] - m[15] * m[8] * m[11]
inv[7] = -m[5] * m[11] * m[17] + m[5] * m[12] * m[16] + m[10] * m[6] * m[17] - m[10] * m[7] * m[16] - m[15] * m[6] * m[12] + m[15] * m[7] * m[11]
inv[8] = -m[21] * m[7] * m[18] + m[21] * m[8] * m[17] + m[6] * m[22] * m[18] - m[6] * m[23] * m[17] - m[16] * m[22] * m[8] + m[16] * m[23] * m[7]
inv[9] = m[20] * m[7] * m[18] - m[20] * m[8] * m[17] - m[6] * m[21] * m[18] + m[6] * m[23] * m[17] + m[16] * m[21] * m[8] - m[16] * m[23] * m[7]
inv[10] = -m[20] * m[7] * m[13] + m[20] * m[8] * m[12] + m[1] * m[22] * m[18] - m[1] * m[23] * m[17] - m[16] * m[22] * m[3] + m[16] * m[23] * m[2]
inv[11] = m[20] * m[7] * m[13] - m[20] * m[8] * m[12] - m[1] * m[21] * m[18] + m[1] * m[23] * m[17] + m[11] * m[21] * m[3] - m[11] * m[23] * m[2]
inv[12] = m[20] * m[2] * m[13] - m[20] * m[3] * m[12] - m[1] * m[22] * m[13] + m[1] * m[23] * m[12] + m[11] * m[22] * m[3] - m[11] * m[23] * m[2]
inv[13] = -m[20] * m[2] * m[8] + m[20] * m[3] * m[7] + m[1] * m[22] * m[8] - m[1] * m[23] * m[7] - m[6] * m[22] * m[3] + m[6] * m[23] * m[2]
inv[14] = m[5] * m[2] * m[18] - m[5] * m[3] * m[17] - m[1] * m[7] * m[18] + m[1] * m[8] * m[17] + m[16] * m[7] * m[3] - m[16] * m[8] * m[2]
inv[15] = -m[5] * m[2] * m[13] + m[5] * m[3] * m[12] + m[1] * m[7] * m[13] - m[1] * m[8] * m[12] - m[11] * m[7] * m[3] + m[11] * m[8] * m[2]
inv[16] = -m[20] * m[12] * m[18] + m[20] * m[13] * m[17] + m[10] * m[22] * m[18] - m[10] * m[23] * m[17] - m[15] * m[22] * m[13] + m[15] * m[23] * m[12]
inv[17] = m[5] * m[12] * m[18] - m[5] * m[13] * m[17] - m[10] * m[2] * m[18] + m[10] * m[3] * m[17] + m[15] * m[2] * m[13] - m[15] * m[3] * m[12]
inv[18] = -m[5] * m[11] * m[18] + m[5] * m[13] * m[16] + m[10] * m[1] * m[18] - m[10] * m[3] * m[16] - m[15] * m[1] * m[13] + m[15] * m[3] * m[11]
inv[19] = m[5] * m[11] * m[17] - m[5] * m[12] * m[16] - m[10] * m[1] * m[17] + m[10] * m[2] * m[16] + m[15] * m[1] * m[12] - m[15] * m[2] * m[11]
inv[20] = m[20] * m[2] * m[18] - m[20] * m[3] * m[17] - m[1] * m[22] * m[18] + m[1] * m[23] * m[17] + m[16] * m[22] * m[3] - m[16] * m[23] * m[2]
inv[21] = -m[20] * m[2] * m[13] + m[20] * m[3] * m[12] + m[1] * m[22] * m[13] - m[1] * m[23] * m[12] - m[11] * m[22] * m[3] + m[11] * m[23] * m[2]
inv[22] = m[20] * m[2] * m[8] - m[20] * m[3] * m[7] - m[1] * m[22] * m[8] + m[1] * m[23] * m[7] + m[6] * m[22] * m[3] - m[6] * m[23] * m[2]
inv[23] = -m[20] * m[2] * m[8] + m[20] * m[3] * m[7] + m[1] * m[21] * m[8] - m[1] * m[23] * m[7] - m[6] * m[21] * m[3] + m[6] * m[23] * m[2]
inv[24] = -m[5] * m[2] * m[8] + m[5] * m[3] * m[7] + m[1] * m[7] * m[8] - m[1] * m[8] * m[7] - m[6] * m[7] * m[3] + m[6] * m[8] * m[2]
; Calculate the determinant
float det = m[0] * inv[0] + m[1] * inv[5] + m[2] * inv[10] + m[3] * inv[15] + m[4] * inv[20]
; Check if the determinant is zero (matrix is not invertible)
if det == 0
print "Matrix is not invertible"
return
endif
; Multiply the adjugate matrix by the reciprocal of the determinant
float invDet = 1.0 / det
int i
for i = 0 to 24
inv[i] *= invDet
next
; Update the matrix index
idx += 25
end method
method interpolate(Transform4D other, float t)
float* a = @f + idx * 4
float* b = @other.f + other.idx * 4
float* r = @f + (idx + 25) * 4
int i
for i = 0 to 24
r[i] = a[i] + (b[i] - a[i]) * t
next
idx += 25 ; Update the matrix index
end method
method transformDirection(float dirX, float dirY, float dirZ)
float* m = @f + idx * 4
float rx, ry, rz
rx = m[0] * dirX + m[1] * dirY + m[2] * dirZ
ry = m[5] * dirX + m[6] * dirY + m[7] * dirZ
rz = m[10] * dirX + m[11] * dirY + m[12] * dirZ
; Return the transformed direction vector
float result[3]
result[0] = rx
result[1] = ry
result[2] = rz
return result
end method
method transformNormal(float normalX, normalY, normalZ)
float* m = @f + idx * 4
float nx = normalX
float ny = normalY
float nz = normalZ
normalX = m[0] * nx + m[1] * ny + m[2] * nz
normalY = m[5] * nx + m[6] * ny + m[7] * nz
normalZ = m[10] * nx + m[11] * ny + m[12] * nz
return normalX, normalY, normalZ
end method
method transformPoint(float pointX, pointY, pointZ)
float* m = @f + idx * 4
float px = pointX
float py = pointY
float pz = pointZ
pointX = m[0] * px + m[1] * py + m[2] * pz + m[3]
pointY = m[5] * px + m[6] * py + m[7] * pz + m[8]
pointZ = m[10] * px + m[11] * py + m[12] * pz + m[13]
float pw = m[15] * px + m[16] * py + m[17] * pz + m[18]
if pw != 0
pointX /= pw
pointY /= pw
pointZ /= pw
endif
return pointX, pointY, pointZ
end method
method decompose(float* translation, float* rotation, float* scale)
float* m = @f + idx * 4
; Extract translation
translation[0] = m[3]
translation[1] = m[8]
translation[2] = m[13]
translation[3] = m[18]
; Extract scale
float sx = sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2])
float sy = sqrt(m[5] * m[5] + m[6] * m[6] + m[7] * m[7])
float sz = sqrt(m[10] * m[10] + m[11] * m[11] + m[12] * m[12])
float sw = sqrt(m[15] * m[15] + m[16] * m[16] + m[17] * m[17])
scale[0] = sx
scale[1] = sy
scale[2] = sz
scale[3] = sw
; Extract rotation
if sx != 0
m[0] /= sx
m[1] /= sx
m[2] /= sx
endif
if sy != 0
m[5] /= sy
m[6] /= sy
m[7] /= sy
endif
if sz != 0
m[10] /= sz
m[11] /= sz
m[12] /= sz
endif
if sw != 0
m[15] /= sw
m[16] /= sw
m[17] /= sw
endif
; Store rotation values
rotation[0] = m[0]
rotation[1] = m[1]
rotation[2] = m[2]
rotation[3] = m[5]
rotation[4] = m[6]
rotation[5] = m[7]
rotation[6] = m[10]
rotation[7] = m[11]
rotation[8] = m[12]
rotation[9] = m[15]
rotation[10] = m[16]
rotation[11] = m[17]
end method
method compose(float* translation, float* rotation, float* scale)
float* m = @f + idx * 4
; Set translation
m[3] = translation[0]
m[8] = translation[1]
m[13] = translation[2]
m[18] = translation[3]
; Set rotation
m[0] = rotation[0] * scale[0]
m[1] = rotation[1] * scale[0]
m[2] = rotation[2] * scale[0]
m[5] = rotation[3] * scale[1]
m[6] = rotation[4] * scale[1]
m[7] = rotation[5] * scale[1]
m[10] = rotation[6] * scale[2]
m[11] = rotation[7] * scale[2]
m[12] = rotation[8] * scale[2]
m[15] = rotation[9] * scale[3]
m[16] = rotation[10] * scale[3]
m[17] = rotation[11] * scale[3]
; Set scale
m[0] *= scale[0]
m[6] *= scale[1]
m[12] *= scale[2]
m[18] *= scale[3]
end method
Page created in 0.179 seconds with 14 queries.