Convert matrix_float3x3 rotation to SceneKit

I experimented with the GameplayKits GKAgent3D class to move the SCNNode inside the scene. I was able to update SCNNode with agent position, but not with rotation. The problem, which is agent rotation, is saved as matrix_float3x3, which does not correspond to any of the data types that SceneKit uses to store rotation information.

So, what identifier should know if there is a simple function or method that can convert the rotation stored as matrix_float3x3 to any SceneKit data types?

+4
source share
2 answers

@rickster, 3x3 4x4 Swift, simd iOS 11/tvOS 11/High Sierra SceneKit:

extension float4 {
    var xyz: float3 {
        return float3(x, y, z)
    }

    init(_ vec3: float3, _ w: Float) {
        self = float4(vec3.x, vec3.y, vec3.z, w)
    }
}

extension float4x4 {
    var upperLeft3x3: float3x3 {
        let (a,b,c,_) = columns
        return float3x3(a.xyz, b.xyz, c.xyz)
    }

    init(rotation: float3x3, position: float3) {
        let (a,b,c) = rotation.columns
        self = float4x4(float4(a, 0),
                        float4(b, 0),
                        float4(c, 0),
                        float4(position, 1))
    }
}

, node, :

agent.rotation = node.simdTransform.upperLeft3x3

, node "root" (, , rootNode), node worldTransform:

agent.rotation = node.simdWorldTransform.upperLeft3x3

: node SCNTransaction, node node :

agent.position = node.presentation.simdWorldPosition
agent.rotation = node.presentation.simdWorldTransform.upperLeft3x3

EDIT: , node .

node.simdTransform = float4x4(rotation: agent3d.rotation, position: agent3d.position)

, , node, kinematic, dynamic, node .

+4

SceneKit SCNMatrix4 SIMD matrix_float4x4: init(_ m: float4x4) Swift SCNMatrix4FromMat4 ObjC/++.

, SIMD 3x3 4x4, , 3x3 4x4. (, , SIMD-, Apple.)

: 4x4 , 3x3 ( float4 w) (0,0,0,1). ( , , .) float3x3 float4x4 SCNMatrix4.


: iOS 11/tvOS 11/macOS 10.13 ( MacOS 11 ?), SceneKit API SIMD float4x4 ; simdTransform. 3x3 4x4.

+5

Source: https://habr.com/ru/post/1671642/


All Articles