Mesh rotation: Keep rendered mesh inside shape

liquid_container
Nicolas Hake 2016-04-03 12:22:11 +02:00
parent de1d00eb68
commit 3641509462
2 changed files with 8 additions and 0 deletions

View File

@ -145,6 +145,11 @@ struct StdMeshBox
{
float x1, y1, z1;
float x2, y2, z2;
StdMeshVector GetCenter() const
{
return StdMeshVector{ (x2 + x1) / 2.0f, (y2 + y1) / 2.0f, (z2 + z1) / 2.0f };
}
};
class StdSubMesh

View File

@ -584,7 +584,10 @@ void C4Object::DrawFaceImpl(C4TargetFacet &cgo, bool action, float fx, float fy,
if (fix_r != Fix0)
{
const auto mesh_center = pMeshInstance->GetMesh().GetBoundingBox().GetCenter();
matrix = StdMeshMatrix::Translate(-mesh_center.x, -mesh_center.y, -mesh_center.z) * matrix;
matrix = StdMeshMatrix::Rotate(fixtof(fix_r) * (M_PI / 180.0f), 0.0f, 0.0f, 1.0f) * matrix;
matrix = StdMeshMatrix::Translate(mesh_center.x, mesh_center.y, mesh_center.z) * matrix;
}
if(twdt != fwdt || thgt != fhgt)