简体   繁体   English

3D表面上的可拖动图像

[英]Draggable images on 3D surface

I'm creating 3D program in WPF in C#. 我正在C#中的WPF中创建3D程序。 I'd like to move images which are place on 3D surface. 我想移动放置在3D曲面上的图像。 In my case they're situated on square. 就我而言,它们位于广场上。 The problem is when I try to move the image, other images change their sizes. 问题是当我尝试移动图像时,其他图像会更改其大小。 I tried setting contstraints but it seems that the problem is that images and canvas are placed in 3D. 我尝试设置约束,但问题似乎是图像和画布以3D放置。

Does anybod have an idea how to get rid of this problem ? 有没有一个想法如何摆脱这个问题?

Part of wpf code: wpf代码的一部分:

    <Viewport2DVisual3D
  Material="{StaticResource visualHostMaterial}" 
  Geometry="{StaticResource squareMeshFrontRight}">
        <Canvas Grid.Row="1" HorizontalAlignment="Center" 
        VerticalAlignment="Center" x:Name="ImageHolder"  >
            <Image Canvas.Left="36" MouseWheel="Img_MouseWheel" MouseMove="Img_MouseMove" 
           MouseDown="Img_MouseDown" MouseUp="Img_MouseUp" Panel.ZIndex="0" 
           Cursor="Hand" Canvas.Top="33" Height="150" Width="150" Source="sketch.jpg" 
           x:Name="Img" HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="60" MinHeight="60" MaxWidth="60" MaxHeight="60">
            </Image>
            <Image Canvas.Left="341" MouseWheel="Img_MouseWheel" MouseMove="Img_MouseMove" 
           MouseDown="Img_MouseDown" MouseUp="Img_MouseUp" Panel.ZIndex="0" 
           Cursor="Hand" Canvas.Top="22" Height="72" Width="77" Source="GreenSquare.jpg" 
           x:Name="Img2">
            </Image>
        </Canvas>
    </Viewport2DVisual3D>

Methods used for moving imgaes: 用于移动图像的方法:

    Point p;
    Image tmpImg;

    private void Img_MouseMove(object sender, MouseEventArgs e)
    {
        tmpImg = sender as Image;
        Point x = e.GetPosition(ImageHolder);

        if (e.LeftButton == MouseButtonState.Pressed)
        {
            Canvas.SetLeft(tmpImg, Canvas.GetLeft(tmpImg) + (x.X - p.X));

            Canvas.SetTop(tmpImg, Canvas.GetTop(tmpImg) + (x.Y - p.Y));
        }
        p = x;
    }

    private void Img_MouseDown(object sender, MouseButtonEventArgs e)
    {
        tmpImg = sender as Image;
        tmpImg.CaptureMouse();
        p = e.GetPosition(ImageHolder);
    }

    private void Img_MouseUp(object sender, MouseButtonEventArgs e)
    {
        tmpImg = sender as Image;
        tmpImg.ReleaseMouseCapture();
    }

I move images around in 3d, under animated control rather than user dragging, but i am pretty sure that the mechanism for moving them would be the same. 我在动画控制下而不是用户拖动的情况下以3d方式移动图像,但是我很确定移动图像的机制是相同的。

first, make just to make sure that the outer canvas isnt getting autosized or something weird like that set it to a fixed width/height. 首先,请确保外部画布不会自动调整大小,或者将其设置为固定的宽度/高度。

and with the setting of the position of the images within the Viewport2DVisual3D, I used RenderTransform on the image to set it to its new position. 并设置了Viewport2DVisual3D中图像的位置,我在图像上使用了RenderTransform将其设置为新位置。

cheers Anton 欢呼安东

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM