private void RemoveItem(TransformComponent item) { if (item.Parent != this) throw new InvalidOperationException("This TransformComponent's parent is not the expected value."); item.parent = null; }
internal void Update(TransformComponent transformComponent, ref Matrix worldMatrix) { if (!Enabled || modelViewHierarchy == null) return; // Check if scaling is negative bool isScalingNegative = false; { Vector3 scale, translation; Matrix rotation; if (worldMatrix.Decompose(out scale, out rotation, out translation)) isScalingNegative = scale.X*scale.Y*scale.Z < 0.0f; } // Update model view hierarchy node matrices modelViewHierarchy.NodeTransformations[0].LocalMatrix = worldMatrix; modelViewHierarchy.NodeTransformations[0].IsScalingNegative = isScalingNegative; modelViewHierarchy.UpdateMatrices(); // Update the bounding sphere / bounding box in world space var meshes = Model.Meshes; var modelBoundingSphere = BoundingSphere.Empty; var modelBoundingBox = BoundingBox.Empty; bool hasBoundingBox = false; Matrix world; foreach (var mesh in meshes) { var meshBoundingSphere = mesh.BoundingSphere; modelViewHierarchy.GetWorldMatrix(mesh.NodeIndex, out world); Vector3.TransformCoordinate(ref meshBoundingSphere.Center, ref world, out meshBoundingSphere.Center); BoundingSphere.Merge(ref modelBoundingSphere, ref meshBoundingSphere, out modelBoundingSphere); var boxExt = new BoundingBoxExt(mesh.BoundingBox); boxExt.Transform(world); var meshBox = (BoundingBox)boxExt; if (hasBoundingBox) { BoundingBox.Merge(ref modelBoundingBox, ref meshBox, out modelBoundingBox); } else { modelBoundingBox = meshBox; } hasBoundingBox = true; } // Update the bounds BoundingBox = modelBoundingBox; BoundingSphere = modelBoundingSphere; }
private void AddItem(TransformComponent item) { if (item.Parent != null) throw new InvalidOperationException("This TransformComponent already has a Parent, detach it first."); item.parent = this; }
/// <inheritdoc/> public override void Process(TransformComponent transformComponent) { // Waiting for roslyn ref locals to avoid having to pass world matrix modelComponent.Update(transformComponent, ref transformComponent.WorldMatrix); }