Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 317791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:30:36+00:00 2026-05-12T08:30:36+00:00

In flash10 I can easly rotate an image around its center in 3D space.

  • 0

In flash10 I can easly rotate an image around its center in 3D space.

The flash10 example I have is at [http://jsc.sourceforge.net/examples/web/MatrixStuffExample/Application.htm
alt text
(source: sourceforge.net)

I want to port this example to WPF.

Is there an example how to do such 3D transformation in WPF within C# without XAML?

In silverlight 3 you’d be using Matrix3DProjection. How would you implement in WPF?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:30:36+00:00Added an answer on May 12, 2026 at 8:30 am

    I’ve set up a basic thin cube and rotated it round so you can see how the transform works through C#.

    Setup your Viewport in the xaml

    <Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <StackPanel>
    
            <Viewport3D Name="mainViewport" ClipToBounds="True" HorizontalAlignment="Stretch" Height="300">
                <Viewport3D.Camera>
                    <PerspectiveCamera 
                          LookDirection="0,0,-20"
                          UpDirection="0,1,0"
                          Position="0,0,50" 
                          />
                </Viewport3D.Camera>
                <ModelVisual3D>
                    <ModelVisual3D.Content>
                        <Model3DGroup x:Name="group3d">
    
                            <SpotLight Position="10,10,10" x:Name="mySpotLight" Color="Yellow"  InnerConeAngle="15" OuterConeAngle="100" Range="100" />
                        </Model3DGroup>
                    </ModelVisual3D.Content>
    
                </ModelVisual3D>
            </Viewport3D>
    
        </StackPanel>
    </Window>
    

    And heres the code behind, the transformation is the last method … hope this helps … give me a shout if you want more info!

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            Init();
        }
    
    
        private Timer _timer;
        private ModelVisual3D _model = new ModelVisual3D();
        private double _angle = 0;
    
        public void Init()
        {
            _model = GetCube(GetSurfaceMaterial(Colors.Red), new Point3D(10, 10, 1), new Point3D(-10,-10,-1));
            mainViewport.Children.Add(_model);    
            _timer = new Timer(10);
            _timer.Elapsed += TimerElapsed;
            _timer.Enabled = true;
        }
    
        void TimerElapsed(object sender, ElapsedEventArgs e)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, new Action<double>(Transform), 0.5d);
        }
    
        public MaterialGroup GetSurfaceMaterial(Color colour)
        {
            var materialGroup = new MaterialGroup();
            var emmMat = new EmissiveMaterial(new SolidColorBrush(colour));
            materialGroup.Children.Add(emmMat);
            materialGroup.Children.Add(new DiffuseMaterial(new SolidColorBrush(colour)));
            var specMat = new SpecularMaterial(new SolidColorBrush(Colors.White), 30);
            materialGroup.Children.Add(specMat);
            return materialGroup;
        }
    
        public ModelVisual3D GetCube(MaterialGroup materialGroup, Point3D nearPoint, Point3D farPoint)
        {
            var cube = new Model3DGroup();
            var p0 = new Point3D(farPoint.X, farPoint.Y, farPoint.Z);
            var p1 = new Point3D(nearPoint.X, farPoint.Y, farPoint.Z);
            var p2 = new Point3D(nearPoint.X, farPoint.Y, nearPoint.Z);
            var p3 = new Point3D(farPoint.X, farPoint.Y, nearPoint.Z);
            var p4 = new Point3D(farPoint.X, nearPoint.Y, farPoint.Z);
            var p5 = new Point3D(nearPoint.X, nearPoint.Y, farPoint.Z);
            var p6 = new Point3D(nearPoint.X, nearPoint.Y, nearPoint.Z);
            var p7 = new Point3D(farPoint.X, nearPoint.Y, nearPoint.Z);
            //front side triangles
            cube.Children.Add(CreateTriangleModel(materialGroup, p3, p2, p6));
            cube.Children.Add(CreateTriangleModel(materialGroup, p3, p6, p7));
            //right side triangles
            cube.Children.Add(CreateTriangleModel(materialGroup, p2, p1, p5));
            cube.Children.Add(CreateTriangleModel(materialGroup, p2, p5, p6));
            //back side triangles
            cube.Children.Add(CreateTriangleModel(materialGroup, p1, p0, p4));
            cube.Children.Add(CreateTriangleModel(materialGroup, p1, p4, p5));
            //left side triangles
            cube.Children.Add(CreateTriangleModel(materialGroup, p0, p3, p7));
            cube.Children.Add(CreateTriangleModel(materialGroup, p0, p7, p4));
            //top side triangles
            cube.Children.Add(CreateTriangleModel(materialGroup, p7, p6, p5));
            cube.Children.Add(CreateTriangleModel(materialGroup, p7, p5, p4));
            //bottom side triangles
            cube.Children.Add(CreateTriangleModel(materialGroup, p2, p3, p0));
            cube.Children.Add(CreateTriangleModel(materialGroup, p2, p0, p1));
            var model = new ModelVisual3D();
            model.Content = cube;
            return model;
        }
    
        private Model3DGroup CreateTriangleModel(Material material, Point3D p0, Point3D p1, Point3D p2)
        {
            var mesh = new MeshGeometry3D();
            mesh.Positions.Add(p0);
            mesh.Positions.Add(p1);
            mesh.Positions.Add(p2);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(2);
            var normal = CalculateNormal(p0, p1, p2);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
    
            var model = new GeometryModel3D(mesh, material);
    
            var group = new Model3DGroup();
            group.Children.Add(model);
            return group;
        }
    
        private Vector3D CalculateNormal(Point3D p0, Point3D p1, Point3D p2)
        {
            var v0 = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
            var v1 = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
            return Vector3D.CrossProduct(v0, v1);
        }
    
        void Transform(double adjustBy)
        {
            _angle += adjustBy;
    
    
            var rotateTransform3D = new RotateTransform3D {CenterX = 0, CenterZ = 0};
            var axisAngleRotation3D = new AxisAngleRotation3D {Axis = new Vector3D(0, 1, 0), Angle = _angle};
            rotateTransform3D.Rotation = axisAngleRotation3D;
            var myTransform3DGroup = new Transform3DGroup();
            myTransform3DGroup.Children.Add(rotateTransform3D);
            _model.Transform = myTransform3DGroup;
    
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please take a look at the image am attaching, as you can note its
I read Flash 10.1 supports HTTP adaptive streaming. Can you give me an example
I've been googling around and I still can't get it. Some people say: here
We have a C#/.NET 2.0 WinForm with an ActiveX ShockwaveFlashObject control on it. The
I have a server running at http://192.168.0.179 . It serves a flash file, WebSocketMain.swf
I have a couple of solutions, but none of them work perfectly. Platform ASP.NET
I am trying to figure out how to use http dynamic streaming with flash
I have been using Uploadify in my PHP application for the last couple months,
Apparently, in Flash 10, you can use the GPU to calculate shaders, and if
I have created a Paralax effect in Flash 10 where I have about 5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.