Animation Scenekit-绘制对象的轨迹

Animation Scenekit-绘制对象的轨迹,animation,scenekit,quaternions,Animation,Scenekit,Quaternions,好的,我不是很确定早期的转换公式,正如有人指出的(我只是在某个地方读过并尝试过),但现在我正在尝试一种方法,在船的边缘创建一个小盒子,当旋转应用到船上时,我不断读取它的位置。然后使用这些位置绘制几何图形。下面是相关代码: scene = [SCNScene sceneNamed:@"ship.scn"]; _viewpoint1.scene = scene; box = [SCNNode node]; box.geometry = [SCNBox boxWithWidth:.1 height

好的,我不是很确定早期的转换公式,正如有人指出的(我只是在某个地方读过并尝试过),但现在我正在尝试一种方法,在船的边缘创建一个小盒子,当旋转应用到船上时,我不断读取它的位置。然后使用这些位置绘制几何图形。下面是相关代码:

scene = [SCNScene sceneNamed:@"ship.scn"];
_viewpoint1.scene = scene;


box = [SCNNode node];
box.geometry = [SCNBox boxWithWidth:.1 height:.1 length:.1 chamferRadius:.1];
box.physicsBody = [SCNPhysicsBody staticBody];
// position the box to the end of the ship
box.position = SCNVector3Make(box.position.x, box.position.y, box.position.z +5.6);
[_viewpoint1.scene.rootNode addChildNode:box];
当应用程序接收到四元数时,飞船会旋转,顶端的盒子也会旋转,我会捕捉盒子的位置并将其存储在位置数组中

_viewpoint1.scene.rootNode.orientation = SCNVector4Make(f_q0, f_q1, f_q2, f_q3);
SCNVector3 pt = [box convertPosition:SCNVector3Make(box.position.x, box.position.y, box.position.z) toNode:nil];

[positions addObject:[NSValue valueWithSCNVector3:SCNVector3Make(pt.x, pt.y, pt.z)]];
稍后,使用此位置阵列创建几何体,如下所示:

SCNVector3 positions2[pointCount];
for (int j = 0; j < pointCount; j++)
    {
        SCNVector3 value = [[positions objectAtIndex:j] SCNVector3Value];
        SCNVector3 value1 = [_viewpoint2.scene.rootNode convertPosition:value fromNode:nil];
        positions2[j] = value1;
    };

    SCNGeometrySource *vertexSource1 =
    [SCNGeometrySource geometrySourceWithVertices:positions2 count:pointCount];

    NSData *indexData1 = [NSData dataWithBytes:indices2
                                       length:sizeof(indices2)];

    SCNGeometryElement *element1 =
    [SCNGeometryElement geometryElementWithData:indexData1
                                  primitiveType:SCNGeometryPrimitiveTypeLine
                                 primitiveCount:pointCount
                                  bytesPerIndex:sizeof(int)];

    SCNGeometry *geometry1 = [SCNGeometry geometryWithSources:@[vertexSource1]
                                                    elements:@[element1]];
    SCNNode* lineNode1 = [SCNNode nodeWithGeometry:geometry1];
    [_viewpoint2.scene.rootNode addChildNode:lineNode1];
SCInvector3位置2[pointCount];
对于(int j=0;j

我观察到的是,绘制的弧度大于船舶旋转,因此如果船舶旋转30度,绘制的弧度约为60度左右。它应该与船舶旋转相同……想知道我在这里做了什么不正确吗?

告诉我们您看到了什么,这与您期望看到的不同,以及您期望看到的原因。嗨,哈尔,我已经用相关信息编辑了这篇文章。谢谢你花时间帮忙。告诉我们你看到了什么,这与你期望看到的有什么不同,以及为什么你期望看到。嗨,哈尔,我已经用相关信息编辑了这篇文章。谢谢你花时间帮忙。