Fix incorrect rotation on object polys
This commit is contained in:
parent
2a75e016ef
commit
a6e4e85470
|
@ -127,8 +127,16 @@ public class MeshBuilder
|
||||||
var model = new ModelFile(modelPath);
|
var model = new ModelFile(modelPath);
|
||||||
pos -= model.Header.Center;
|
pos -= model.Header.Center;
|
||||||
|
|
||||||
|
|
||||||
|
var scalePart = Matrix4x4.CreateScale(scale);
|
||||||
|
var rotPart = Matrix4x4.Identity;
|
||||||
|
rotPart *= Matrix4x4.CreateRotationX(float.DegreesToRadians(rot.X));
|
||||||
|
rotPart *= Matrix4x4.CreateRotationY(float.DegreesToRadians(rot.Y));
|
||||||
|
rotPart *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(rot.Z));
|
||||||
|
var transPart = Matrix4x4.CreateTranslation(pos);
|
||||||
|
var modelTrans = scalePart * rotPart * transPart;
|
||||||
|
|
||||||
// for each object modify the vertices
|
// for each object modify the vertices
|
||||||
// TODO: Almost perfect transform!
|
|
||||||
// TODO: Handle nested sub objects
|
// TODO: Handle nested sub objects
|
||||||
foreach (var subObj in model.Objects)
|
foreach (var subObj in model.Objects)
|
||||||
{
|
{
|
||||||
|
@ -140,11 +148,8 @@ public class MeshBuilder
|
||||||
var objTrans = subObj.Transform;
|
var objTrans = subObj.Transform;
|
||||||
jointTrans = jointRot * objTrans;
|
jointTrans = jointRot * objTrans;
|
||||||
}
|
}
|
||||||
var scalePart = Matrix4x4.CreateScale(scale);
|
|
||||||
var rotPart = Matrix4x4.CreateFromYawPitchRoll(float.DegreesToRadians(rot.Y), float.DegreesToRadians(rot.X),
|
var transform = jointTrans * modelTrans;
|
||||||
float.DegreesToRadians(rot.Z));
|
|
||||||
var transPart = Matrix4x4.CreateTranslation(pos);
|
|
||||||
var transform = jointTrans * scalePart * rotPart * transPart;
|
|
||||||
|
|
||||||
var start = subObj.PointIdx;
|
var start = subObj.PointIdx;
|
||||||
var end = start + subObj.PointCount;
|
var end = start + subObj.PointCount;
|
||||||
|
|
Loading…
Reference in New Issue