I'm now trying to handle a complex model generated from a file.
The origin of the model is at the model's bottom, and obviously that's not where the center of mass is, so I record the offset generated by the model and that all works well.
I render essentially with "offset * Transform" where "transform" is the exact same calculations I used to render cuboids. Solid, right? Nope! The monster I've created insists on floating and/or going inside the floor and just all around rotating on definitely not anything logical.
My code:
Code: Select all
public override void SpawnBody()
{
model = TheClient.Models.GetModel(mod);
Shape = TheClient.Models.Handler.MeshToBepu(model.OriginalModel);
Assimp.Matrix4x4 mat = model.OriginalModel.RootNode.Transform;
offset = Location.FromBVector(Shape.Position);
Matrix4 root = new Matrix4(mat.A1, mat.A2, mat.A3, mat.A4, mat.B1, mat.B2, mat.B3, mat.B4, mat.C1, mat.C2, mat.C3, mat.C4, mat.D1, mat.D2, mat.D3, mat.D4);
transform = Matrix4.CreateTranslation(offset.ToOVector()) * root;
base.SpawnBody();
}
public override void Render()
{
Matrix4 orient = GetOrientationMatrix();
Matrix4 mat = transform * (Matrix4.CreateScale(scale.ToOVector()) * orient * Matrix4.CreateTranslation((GetPosition()).ToOVector()));
GL.UniformMatrix4(2, false, ref mat);
TheClient.Rendering.SetMinimumLight(0.0f);
model.Draw();
}
Also note that Scale = (1, 1, 1).
GetPosition() returns the BEPU entity's position.
The variable "transform" is not touched outside this code.
I'm going to assume you're capable of picture "rotating wrong" and not post images of flying and/or half-submerged poorly-modeled corpses.
I can find a model that's less terribly ugly and get screenshots/gifs if it would be helpful.