Page 1 of 1

Manipulation and RenderTransform

Posted: 20 Jul 2015, 16:47
by themirrortruth
Hello.
I'm trying to made an app that use manipulation to change RenderTransform of some objects.
I'm doing it using your tutorial http://www.noesisengine.com/docs/Gui.Co ... orial.html but it's not working. When i'm starting manipulation the object does not react. Also I looked this topic viewtopic.php?f=3&t=751 and I tried to make do like it says but again it not work. I do not understand what the problem is. Can you help with this please. The project is spread here.
https://www.dropbox.com/s/3a6l5ggzjpoio ... n1.7z?dl=0

Re: Manipulation and RenderTransform

Posted: 20 Jul 2015, 18:11
by jsantos
What platform are you testing? Manipulation is based in touch events, and Unity only generates touch events in Android, iOS and Windows Mobile.

Re: Manipulation and RenderTransform

Posted: 21 Jul 2015, 02:15
by themirrortruth
Yes, of course I know that. I'm running it on android.

Re: Manipulation and RenderTransform

Posted: 21 Jul 2015, 02:55
by jsantos
Does the tutorial sample work for you? What version of NoesisGUI are you using?

Re: Manipulation and RenderTransform

Posted: 21 Jul 2015, 04:36
by themirrortruth
Noesis 1.2.3, Unity 5.0.1f1 (64-bit). It feels like I'm doing something wrong. Because if i execute this code, the values of the rotation, scale and translation for some reason very little, as if they are always somewhere to zero.
        private Rectangle rectangle;
        private Rectangle manipulationRectangle;
        private TextBlock rotate;
        private TextBlock scale;
        private TextBlock translate;

        public void OnPostInit()
        {
            rectangle = FindName("rectangle") as Rectangle;

            manipulationRectangle = FindName("manipulationRectangle") as Rectangle;

            rotate = FindName("rotate") as TextBlock;
            scale = FindName("scale") as TextBlock;
            translate = FindName("translate") as TextBlock;

            manipulationRectangle.ManipulationStarting += delegate(object sender, ManipulationStartingEventArgs e)
            {
                e.Mode = ManipulationModes.All;
                e.Handled = true;
            };
           
            manipulationRectangle.ManipulationDelta += delegate(object sender, ManipulationDeltaEventArgs e)
            {
                rotate.Text = "Rotate: " + e.DeltaManipulation.rotation.ToString();
                scale.Text = "Scale: " + e.DeltaManipulation.scale.ToString();
                translate.Text = "X: " + e.DeltaManipulation.translation.X.ToString() + "  Y: " +              e.DeltaManipulation.translation.Y.ToString();

                e.Handled = true;
            };
        }
<Grid x:Name="LayoutRoot"><Rectangle x:Name="rectangle" Fill="Red" IsManipulationEnabled="True" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" Height="300"/>
	<TextBlock x:Name="rotate" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="26.667"><Run Text="Rotate:"/><LineBreak/><Run/></TextBlock>
	<TextBlock x:Name="translate" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="26.667" Text="X: Y:" Margin="0,48,0,0"/>
	<TextBlock x:Name="scale" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="26.667" Margin="0,102,0,0"><Run Text="Scale:"/><LineBreak/><Run/></TextBlock>
	<Rectangle x:Name="manipulationRectangle" Fill="#FF1919E0" Opacity="0" IsManipulationEnabled="True" Width="640" Height="480" HorizontalAlignment="Center" VerticalAlignment="Center"/>
Image

Re: Manipulation and RenderTransform

Posted: 21 Jul 2015, 04:37
by themirrortruth

Re: Manipulation and RenderTransform

Posted: 21 Jul 2015, 05:31
by themirrortruth
I solved the problem. Code
public class ViewControl : UserControl
    {
        private Rectangle rectangle;
        private Rectangle manipulationRectangle;
        private TextBlock rotate;
        private TextBlock scale;
        private TextBlock translate;
        private TextBlock source;
        private TextBlock container;

        private float translateX = 0f;
        private float translateY = 0f;
        private float angle = 0f;
        private float zoom = 1f;

        public void OnPostInit()
        {
            rectangle = FindName("rectangle") as Rectangle;

            manipulationRectangle = FindName("manipulationRectangle") as Rectangle;

            rotate = FindName("rotate") as TextBlock;
            scale = FindName("scale") as TextBlock;
            translate = FindName("translate") as TextBlock;
            source = FindName("source") as TextBlock;
            container = FindName("container") as TextBlock;

            manipulationRectangle.ManipulationStarting += delegate(object sender, ManipulationStartingEventArgs e)
            {
                e.Mode = ManipulationModes.All;
                source.Text = "Source: " + ((Rectangle)e.Source).Name;
                container.Text = "Container: " + e.ManipulationContainer.GetType().Name;

                e.Handled = true;
            };

            manipulationRectangle.ManipulationCompleted += delegate(object sender, ManipulationCompletedEventArgs e)
            {

            };

            manipulationRectangle.ManipulationDelta += delegate(object sender, ManipulationDeltaEventArgs e)
            {
                translateX += e.DeltaManipulation.translation.X;
                translateY += e.DeltaManipulation.translation.Y;
                angle += e.DeltaManipulation.rotation;
                zoom *= e.DeltaManipulation.scale;
                zoom = Mathf.Clamp(zoom, 1f, 2f);

                rotate.Text = "Rotate: " + angle;
                scale.Text = "Scale: " + zoom;
                translate.Text = "X: " + translateX + "  Y: " + translateY;

                TransformGroup group = new TransformGroup();
                group.Children.Add(new RotateTransform { CenterX = rectangle.Width / 2f, CenterY = rectangle.Height / 2f, Angle = angle});
                group.Children.Add(new ScaleTransform { CenterX = rectangle.Width / 2f, CenterY = rectangle.Height / 2f, ScaleX = zoom, ScaleY = zoom });
                group.Children.Add(new TranslateTransform { X = translateX, Y = translateY});

                rectangle.RenderTransform = group;

                e.Handled = true;
            };
        }

Re: Manipulation and RenderTransform

Posted: 23 Jul 2015, 00:05
by jsantos
As you discovered, DeltaManipulation provides changes since the last frame. If you want the cumulative changes since the manipulation started you can use the property CumulativeManipulation.