private Matrix4 getModelMatrix(IScale scale, IRotate rotate, ITranslate translate, IHasImage image, IJumpOffsetComponent jump, PointF areaScaling, PointF resolutionTransform, bool useCustomImageSize) { if (scale == null) { return(Matrix4.Identity); } float?customWidth = _customImageSize == null || !useCustomImageSize ? _nullFloat : (_customImageSize.Value.Width * scale.ScaleX); float?customHeight = _customImageSize == null || !useCustomImageSize ? _nullFloat : (_customImageSize.Value.Height * scale.ScaleY); float width = (customWidth ?? scale.Width) * areaScaling.X * resolutionTransform.X; float height = (customHeight ?? scale.Height) * areaScaling.Y * resolutionTransform.Y; PointF pivotOffsets = GetPivotOffsets(image == null ? PointF.Empty : image.Pivot, width, height); Matrix4 pivotMat = Matrix4.CreateTranslation(new Vector3(-pivotOffsets.X, -pivotOffsets.Y, 0f)); Matrix4 scaleMat = Matrix4.CreateScale(new Vector3(scale.ScaleX * areaScaling.X, scale.ScaleY * areaScaling.Y, 1f)); float radians = rotate == null ? 0f : MathUtils.DegreesToRadians(rotate.Angle); Matrix4 rotationMat = Matrix4.CreateRotationZ(radians); float x = translate == null ? 0f : translate.X * resolutionTransform.X; float y = translate == null ? 0f : translate.Y * resolutionTransform.Y; if (jump != null) { x += jump.JumpOffset.X * resolutionTransform.X; y += jump.JumpOffset.Y * resolutionTransform.Y; } Matrix4 translateMat = Matrix4.CreateTranslation(new Vector3(x, y, 0f)); return(scaleMat * pivotMat * rotationMat * translateMat); }
public override void AfterInit() { _entity.Bind <IAnimationComponent>( c => { _animationComponent = c; _animationComponent.PropertyChanged += onAnimationChanged; onSomethingChanged(); }, c => { _animationComponent = null; _animationComponent.PropertyChanged -= onAnimationChanged; onSomethingChanged(); }); _entity.Bind <IHasRoomComponent>( c => { _room = c; refreshAreaScaling(); subscribeRoom(); onSomethingChanged(); }, c => { unsubscribeRoom(c); _room = null; refreshAreaScaling(); onSomethingChanged(); }); _entity.Bind <IScaleComponent>( c => { _scale = c; c.PropertyChanged += onScaleChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onScaleChanged; _scale = null; onSomethingChanged(); }); _entity.Bind <ITranslateComponent>( c => { _translate = c; c.PropertyChanged += onTranslateChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onTranslateChanged; _translate = null; onSomethingChanged(); } ); _entity.Bind <IJumpOffsetComponent>( c => { _jump = c; c.PropertyChanged += onJumpOffsetChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onJumpOffsetChanged; _jump = null; onSomethingChanged(); } ); _entity.Bind <IRotateComponent>( c => { _rotate = c; c.PropertyChanged += onRotateChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onRotateChanged; _rotate = null; onSomethingChanged(); } ); _entity.Bind <IImageComponent>( c => { _image = c; subscribeLabelRenderer(); c.PropertyChanged += onImageChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onImageChanged; _image = null; onSomethingChanged(); } ); _entity.Bind <IDrawableInfoComponent>( c => { _drawable = c; c.PropertyChanged += onDrawableChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onDrawableChanged; _drawable = null; onSomethingChanged(); }); _entity.Bind <IInObjectTreeComponent>( c => { _tree = c; _parent = _tree.TreeNode.Parent; _tree.TreeNode.OnParentChanged.Subscribe(onParentChanged); _parent?.OnMatrixChanged.Subscribe(onSomethingChanged); onSomethingChanged(); }, c => { c.TreeNode.OnParentChanged.Unsubscribe(onParentChanged); c.TreeNode.Parent?.OnMatrixChanged.Unsubscribe(onSomethingChanged); _tree = null; _parent = null; onSomethingChanged(); }); }
public override void AfterInit() { Entity.Bind <IDrawableInfoComponent>( c => { _drawable = c; c.PropertyChanged += _onDrawbaleChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onDrawbaleChangedCallback; _drawable = null; onSomethingChanged(); }); Entity.Bind <IHasRoomComponent>( c => { _room = c; refreshAreaScaling(); subscribeRoom(); onSomethingChanged(); }, c => { unsubscribeRoom(c); _room = null; refreshAreaScaling(); onSomethingChanged(); }); Entity.Bind <IScaleComponent>( c => { _scale = c; c.PropertyChanged += _onScaleChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onScaleChangedCallback; _scale = null; onSomethingChanged(); }); Entity.Bind <ITranslateComponent>( c => { _translate = c; c.PropertyChanged += _onTranslateChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onTranslateChangedCallback; _translate = null; onSomethingChanged(); } ); Entity.Bind <IWorldPositionComponent>( c => { _worldPosition = c; c.PropertyChanged += _onWorldPositionChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onWorldPositionChangedCallback; _translate = null; onSomethingChanged(); } ); Entity.Bind <IJumpOffsetComponent>( c => { _jump = c; c.PropertyChanged += _onJumpOffsetChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onJumpOffsetChangedCallback; _jump = null; onSomethingChanged(); } ); Entity.Bind <IRotateComponent>( c => { _rotate = c; c.PropertyChanged += _onRotateChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onRotateChangedCallback; _rotate = null; onSomethingChanged(); } ); Entity.Bind <IImageComponent>( c => { _image = c; c.PropertyChanged += _onImageChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onImageChangedCallback; _image = null; onSomethingChanged(); } ); Entity.Bind <ITextComponent>( c => { _text = c; subscribeTextComponent(); }, _ => { unsubscribeTextComponent(); _text = null; } ); Entity.Bind <IInObjectTreeComponent>( c => { _tree = c; _parent = _tree.TreeNode.Parent; _tree.TreeNode.OnParentChanged.Subscribe(_onParentChangedCallback); _parent?.OnMatrixChanged.Subscribe(_onSomethingChangedCallback); onSomethingChanged(); }, c => { c.TreeNode.OnParentChanged.Unsubscribe(_onParentChangedCallback); c.TreeNode.Parent?.OnMatrixChanged.Unsubscribe(_onSomethingChangedCallback); _tree = null; _parent = null; onSomethingChanged(); }); }