CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Posts
    2

    Problem adding Viewport2DVisual3D from Code

    I'm trying to add a Viewport2DVisual3D to a Viewport3D in code, but the visual isn't showing up. Any help understanding why not would be appreciated. The following is the code for the main window.

    Is it sufficient to just add the Viewport2DVisual3D to the children of the Viewport3D in order for it to be rendered?

    public partial class Window1 : System.Windows.Window
    {

    public Window1()
    {
    InitializeComponent();

    this.Loaded += new RoutedEventHandler(temp);
    }


    public void temp(object sender, RoutedEventArgs e)
    {
    Viewport2DVisual3D test = new Viewport2DVisual3D();
    MeshGeometry3D testGeometry = new MeshGeometry3D();

    Vector3D CameraLookDirection = Main_Target_CameraOR20.LookDirection;

    // Calculate the Positions based on the Camera
    Point3DCollection myPoint3DCollection = new Point3DCollection();
    myPoint3DCollection.Add(new Point3D(-1, 1, 0));
    myPoint3DCollection.Add(new Point3D(-1, -1, 0));
    myPoint3DCollection.Add(new Point3D(1, -1, 0));
    myPoint3DCollection.Add(new Point3D(1, 1, 0));
    testGeometry.Positions = myPoint3DCollection;

    PointCollection myPointCollection = new PointCollection();
    myPointCollection.Add(new Point(0, 0));
    myPointCollection.Add(new Point(0, 1));
    myPointCollection.Add(new Point(1, 1));
    myPointCollection.Add(new Point(1, 0));
    testGeometry.TextureCoordinates = myPointCollection;

    Int32Collection triangleIndicesCollection = new Int32Collection();
    triangleIndicesCollection.Add(0);
    triangleIndicesCollection.Add(1);
    triangleIndicesCollection.Add(2);
    triangleIndicesCollection.Add(2);
    triangleIndicesCollection.Add(3);
    triangleIndicesCollection.Add(0);
    testGeometry.TriangleIndices = triangleIndicesCollection;


    DiffuseMaterial myDiffuseMaterial = new DiffuseMaterial(Brushes.White);
    Viewport2DVisual3D.SetIsVisualHostMaterial(myDiffuseMaterial, true);

    Transform3DGroup myTransform3DGroup = new Transform3DGroup();
    ScaleTransform3D myScaleTransform3D = new ScaleTransform3D();
    myScaleTransform3D.ScaleX = 2;
    myScaleTransform3D.ScaleY = 2;
    myScaleTransform3D.ScaleZ = 2;

    TranslateTransform3D myTranslateTransform3D = new TranslateTransform3D();

    myTranslateTransform3D.OffsetX = -27;
    myTranslateTransform3D.OffsetY = 13;
    myTranslateTransform3D.OffsetZ = 6;


    RotateTransform3D rotateTransform = new RotateTransform3D()
    {
    Rotation = new AxisAngleRotation3D
    {
    Angle = -50,
    Axis = new Vector3D(0, 1, 0)
    }
    };

    myTransform3DGroup.Children.Add(myTranslateTransform3D);
    myTransform3DGroup.Children.Add(myScaleTransform3D);
    myTransform3DGroup.Children.Add(rotateTransform);
    test.Transform = myTransform3DGroup;

    Button myButton = new Button();
    myButton.Content = "Test Button";

    test.Material = myDiffuseMaterial;
    test.Geometry = testGeometry;
    test.Visual = myButton;

    ZAM3DViewport3D.Children.Add(test);
    }
    }

  2. #2
    Join Date
    Mar 2010
    Posts
    2

    Re: Problem adding Viewport2DVisual3D from Code

    To answer the question, yes, it is sufficient to just add it to the collection of children in the Viewport3D to have it rendered.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured