gpt4 book ai didi

c - 对于多个网格的 FBX 模型,网格未显示在正确的位置

转载 作者:行者123 更新时间:2023-11-30 21:48:29 25 4
gpt4 key购买 nike

我导入了一个由多个网格组成的 FBX 模型。不幸的是,我无法将每个网格显示在正确的位置。对于每个网格,我将网格的几何变换与网格的局部变换相乘,然后将其传递给着色器。我该如何解决这个问题?

OpenGL 着色器

gl_Position = modelViewProjectionMatrix *TransformationMatrix*vertexPositionsOfMesh;

创建变换矩阵

GLKMatrix4 LcLTransformation = createTransformationMatrix(
Mesh->LclRotation,
Mesh->LclScaling,
Mesh->LclTranslation);
GLKMatrix4 GeoTransformation = createTransformationMatrix(
Mesh->GeometricRotation,
Mesh->GeometricScaling,
Mesh->GeometricTranslation);
TransformationMatrix=GLKMatrix4Transpose(GLKMatrix4Multiply(LcLTransformation,
GeoTransformation));

创建变换矩阵

GLKMatrix4 createTransformationMatrix(float* _rotation, float* _scaling, float* _translation)
{
GLKMatrix4 Rx = GLKMatrix4Make(1, 0, 0, 0,
0, cos(_rotation[0]), -sin(_rotation[0]), 0,
0, sin(_rotation[0]), cos(_rotation[0]), 0,
0, 0, 0, 1
);

GLKMatrix4 Ry = GLKMatrix4Make(cos(_rotation[1]), 0, sin(_rotation[1]), 0,
0, 1, 0, 0,
-sin(_rotation[1]), 0, cos(_rotation[1]), 0,
0, 0, 0, 1
);

GLKMatrix4 Rz = GLKMatrix4Make(cos(_rotation[2]), -sin(_rotation[2]), 0, 0,
sin(_rotation[2]), cos(_rotation[2]), 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);

GLKMatrix4 Translation = GLKMatrix4Make(1, 0, 0, _translation[0],
0, 1, 0, _translation[1],
0, 0, 1, _translation[2],
0, 0, 0, 1
);
GLKMatrix4 Scaling = GLKMatrix4Identity;

Scaling.m00 = _scaling[0];
Scaling.m11 = _scaling[1];
Scaling.m22 = _scaling[2];

GLKMatrix4 Rotation = GLKMatrix4Multiply(GLKMatrix4Multiply(Rx, Ry), Rz);
Transformation = GLKMatrix4Multiply(Scaling, GLKMatrix4Multiply(Rotation, Translation));
return Transformation;
}

最佳答案

我在我的引擎中正确地从 MAX 导入了 fbx。

你必须:

WorldMatrix= [ParentWorldMatrix * ModelMatrix] * GeometricMatrix

您必须仅在获得层次结构的世界之后相乘几何矩阵。 “ParentMatrix”包含 GEOM。

所以模型应该是:

World = GrandGrandParentModel * [...] * GrandParentModel * ParentModel * Model * CurrentModelGeometric.

记住旋转是 ZYX。

代码:

void GRPNODE::UpdateWorldMatrix(bool * mustUpdate)
{
if (!parent)
return;

parent->UpdateWorldMatrix(mustUpdate);

if (worldmatrix_is_pending)
*mustUpdate = true;

if (*mustUpdate)
this->worldmatrix.GetMulplicationMatrix(parent->GetWorldMatrixPointer(), &modelmatrix);
}

之后我得到了节点的世界矩阵,当我变换顶点时:

void GRPELEMENT::ComputeMatrices(GRPMATRIX* viewmatrix, GRPMATRIX* viewprojection, GRPMATRIX* projection)
{
modelmatrix=node->GetWorldMatrix();
if (node->UsesGeometric)
modelmatrix.GetMulplicationMatrix(modelmatrix, (*node->GetGeometricMatrix()));

modelviewmatrix.GetMulplicationMatrix((*viewmatrix), modelmatrix);
modelviewprojectionmatrix.GetMulplicationMatrix(projection, &modelviewmatrix);
}

void GRPNODE::MaxUpdate()
{
// 1.0 Create Scale matrix
scalematrix.BuildScaleMatrix(scale.vector[0], scale.vector[1], scale.vector[2]);

// 1.1 Create current Rotation Translation Matrix
Rx.BuildRotationMatrixX (this->rotation.vector[0]);
Ry.BuildRotationMatrixY (this->rotation.vector[1]);
Rz.BuildRotationMatrixZ (this->rotation.vector[2]);

if (UsesPreRotation)
{
Rpre.GetMulplicationMatrix(&prerotationmatrix, &Rz);
Rt.GetMulplicationMatrix(&Rpre, &Ry);
rotationmatrix.GetMulplicationMatrix(&Rt, &Rx);
}
else
{
Rt.GetMulplicationMatrix(&Rz, &Ry);
rotationmatrix.GetMulplicationMatrix(&Rt, &Rx);
}

if (UsesPostRotation)
{
Rpost.GetMulplicationMatrix(&rotationmatrix, &postrotationmatrix);
rotationmatrix = Rpost;
}

translationmatrix.BuildTranslationMatrix(position);

//1.2. Create current model matrix (from stored matrix with rotation/translation)
m.GetMulplicationMatrix(translationmatrix, rotationmatrix);
modelmatrix.GetMulplicationMatrix(m, scalematrix);
}

关于c - 对于多个网格的 FBX 模型,网格未显示在正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29496325/

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