private Matrix44 CorrectCameraTransform(Matrix44 origin) { origin.Decompose(out var scale, out Matrix44 rotationMatrix, out var translation); var newRotation = rotationMatrix.Rotation * CameraPostRotation; return(Matrix44.CreateRotation(newRotation) * Matrix44.CreateScale(scale) * Matrix44.CreateTranslation(translation)); }
Matrix44 CalcGizmoTransform(Matrix44 modelGlobalTransform, float gizmoRadiusInPixels) { var viewport = GetCurrentViewport3D(); var camera = viewport.Camera; Vector3 scale, translation; Quaternion rotation; modelGlobalTransform.Decompose(out scale, out rotation, out translation); float distance = (camera.Position - translation).Length; var vfov = camera.FieldOfView / camera.AspectRatio; float s = gizmoRadiusInPixels * distance * (2 * (float)Math.Tan(vfov / 2) / viewport.Height); return(Matrix44.CreateRotation(rotation) * Matrix44.CreateScale(s, s, s) * Matrix44.CreateTranslation(translation)); }