gpt4 book ai didi

c++ - FBXSDK,使用四元数设置旋转键?

转载 作者:行者123 更新时间:2023-11-28 04:53:03 26 4
gpt4 key购买 nike

我正在尝试使用 Autodesk FBXSDK 编写文件保存应用程序。我使用欧拉旋转可以很好地工作,但我需要更新它以使用四元数。

相关函数是:

bool CreateScene(FbxScene* pScene, double lFocalLength, int startFrame)
{
//Create Camera
FbxNode* lMyCameraNode = FbxNode::Create(pScene, "p_camera");
//connect camera node to root node
FbxNode* lRootNode = pScene->GetRootNode();
lRootNode->ConnectSrcObject(lMyCameraNode);
FbxCamera* lMyCamera = FbxCamera::Create(pScene, "Root_camera");
lMyCameraNode->SetNodeAttribute(lMyCamera);


// Create an animation stack
FbxAnimStack* myAnimStack = FbxAnimStack::Create(pScene, "My stack");

// Create the base layer (this is mandatory)
FbxAnimLayer* pAnimLayer = FbxAnimLayer::Create(pScene, "Layer0");

myAnimStack->AddMember(pAnimLayer);

// Get the camera’s curve node for local translation.

FbxAnimCurveNode* myAnimCurveNodeRot = lMyCameraNode->LclRotation.GetCurveNode(pAnimLayer, true);

//create curve nodes
FbxAnimCurve* myRotXCurve = NULL;
FbxAnimCurve* myRotYCurve = NULL;
FbxAnimCurve* myRotZCurve = NULL;

FbxTime lTime; // For the start and stop keys. int lKeyIndex = 0; // Index for the keys that define the curve



// Get the animation curve for local rotation of the camera.
myRotXCurve = lMyCameraNode->LclRotation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_X, true);
myRotYCurve = lMyCameraNode->LclRotation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y, true);
myRotZCurve = lMyCameraNode->LclRotation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z, true);


//This to add keys, per frame.
float frameNumber = startFrame;

for (int i = 0; i < rec.size(); i++)
{
lTime.SetFrame(frameNumber); //frame number

//rx
lKeyIndex = myRotXCurve->KeyAdd(lTime);
myRotXCurve->KeySet(lKeyIndex, lTime, recRotX[i], FbxAnimCurveDef::eInterpolationLinear);

//ry
lKeyIndex = myRotYCurve->KeyAdd(lTime);
myRotYCurve->KeySet(lKeyIndex, lTime, recRotY[i], FbxAnimCurveDef::eInterpolationLinear);

//rz
lKeyIndex = myRotZCurve->KeyAdd(lTime);
myRotZCurve->KeySet(lKeyIndex, lTime, recRotZ[i], FbxAnimCurveDef::eInterpolationLinear);

frameNumber += 1;

}

return true;
}

理想情况下,我想在这里传递四元数数据,而不是欧拉 x、y、z 值。 fbxsdk 可以吗?或者我需要先转换我的四元数数据,然后继续传入欧拉?谢谢。

最佳答案

您总是需要回到欧拉角,因为您只能获得 XYZ 旋转的动画曲线。您唯一可以控制的是轮换顺序。

但是,您可以使用 FbxQuaternion 进行计算,然后使用 .DecomposeSphericalXYZ() 获得 XYZ 欧拉角。

关于c++ - FBXSDK,使用四元数设置旋转键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47753266/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com