Problem having elements in world space.
Posted: 13 Jul 2020, 05:26
I'm trying to have a canvas for all of the elements that need to pretend like they exist in the world space (health bars, etc).
I'm having a problem with how the Canvas.Left & Canvas.Top interacts with RenderTransformOrigin. It seems that, despite being set to 0.5, 0.5, the canvas position is always the top left corner. However, when a rotate transform is set to it, it will rotate from the center like it is supposed to do.
The element:
This is inside an ItemsControl, so the canvas's left & top are being set in the ItemsContainerStyle (to Position shown below this).
How I get the position:
is what it looks like when the scale is 1, and
is the scale at two (from zooming out). You can see that the element is now off from its position. It seems not only that the render origin isn't setting the control to the center, but it becomes offset once a scale is set.
I'm having a problem with how the Canvas.Left & Canvas.Top interacts with RenderTransformOrigin. It seems that, despite being set to 0.5, 0.5, the canvas position is always the top left corner. However, when a rotate transform is set to it, it will rotate from the center like it is supposed to do.
The element:
Code: Select all
<Grid
Width="250"
Height="100"
Background="Black"
RenderTransformOrigin="0.5, 0.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding Scale}" ScaleY="{Binding Scale}" />
</TransformGroup>
</Grid.RenderTransform>
<TextBlock Text="{Binding ElementName=IDK, Path=ActualWidth}" />
</Grid>
How I get the position:
Code: Select all
var point = Camera.main.WorldToViewportPoint(Viewer.Behavior.transform.position);
Scale = _zoomBehavior.DefaultZoom / _zoomBehavior.Zoom;
var noesisSize = new Vector2(3100, 1560);
point *= noesisSize;
var position = new Vector2f(point.x, noesisSize.y - point.y);
Position = position;