Implement Interactive3DDecorator, TrackballDecorator in c#

Topics: User Forum
Feb 12, 2011 at 1:45 PM

Hello all.

I am trying to implement the trackball functionality in a Powerbuilder .Net WPF window. I understand not many people on this forum (if any) user powerbuilder so I asked for c# code since I can understand that and re-write it for Powerbuilder. I have very simple Powerbuilder WPF window with this code to draw a simple 3D cube. I have included the xaml and window code to draw the cube below. I can not figure out how to implement the trackball wrapper so I can rotate/spin, zoom the cube. If I wrap the viewport3D control with:

 <interactive3D:TrackballDecorator>
    <interactive3D:Interactive3DDecorator>

    </interactive3D:Interactive3DDecorator>
  </interactive3D:TrackballDecorator>

It compiles but I get a runtime error on this line:     myGrid.Children.Add(mainViewport)

"Error: Exception thrown has not been handled:
System.InvalidOperationException at line 57"

--------------Powerbuilder code to draw cube ------------------------------------------------------

System.Windows.Media.Media3D.Model3DGroup myCube
myCube = create System.Windows.Media.Media3D.Model3DGroup()

System.Windows.Media.SolidColorBrush myBrush
myBrush = create System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red)

System.Windows.Media.Media3D.Point3D p0
System.Windows.Media.Media3D.Point3D p1
System.Windows.Media.Media3D.Point3D p2
System.Windows.Media.Media3D.Point3D p3
System.Windows.Media.Media3D.Point3D p4
System.Windows.Media.Media3D.Point3D p5
System.Windows.Media.Media3D.Point3D p6
System.Windows.Media.Media3D.Point3D p7

p0 = create System.Windows.Media.Media3D.Point3D(0, 0, 0)
p1 = create System.Windows.Media.Media3D.Point3D(5, 0, 0)
p2 = create System.Windows.Media.Media3D.Point3D(5, 0, 5)
p3 = create System.Windows.Media.Media3D.Point3D(0, 0, 5)
p4 = create System.Windows.Media.Media3D.Point3D(0, 5, 0)
p5 = create System.Windows.Media.Media3D.Point3D(5, 5, 0)
p6 = create System.Windows.Media.Media3D.Point3D(5, 5, 5)
p7 = create System.Windows.Media.Media3D.Point3D(0, 5, 5)

// front, right, back, left, top, bottom-trianagles
myCube.Children.Add(CreateTriangle(p3, p2, p6))
myCube.Children.Add(CreateTriangle(p3, p6, p7))

myCube.Children.Add(CreateTriangle(p2, p1, p5))
myCube.Children.Add(CreateTriangle(p2, p5, p6))

myCube.Children.Add(CreateTriangle(p1, p0, p4))
myCube.Children.Add(CreateTriangle(p1, p4, p5))

myCube.Children.Add(CreateTriangle(p0, p3, p7))
myCube.Children.Add(CreateTriangle(p0, p7, p4))

myCube.Children.Add(CreateTriangle(p7, p6, p5))
myCube.Children.Add(CreateTriangle(p7, p5, p4))

myCube.Children.Add(CreateTriangle(p2, p3, p0))
myCube.Children.Add(CreateTriangle(p2, p0, p1))

System.Windows.Media.Media3D.ModelVisual3D model
model = create System.Windows.Media.Media3D.ModelVisual3D()
model.Content = myCube
mainViewport.Children.Add(model)
           
Grid myGrid
myGrid = create Grid
This.InnerControl.Content = myGrid
 myGrid.Children.Add(mainViewport)
 This.InnerControl.show()            

----------------------------- XAML code for window ------------------------------------------------

<pbwpf:Window x:Class="w_window3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:_3DTools;assembly=3DTools"
             
    xmlns:pbwpf="clr-namespace:Sybase.PowerBuilder.WPF.Controls;assembly=Sybase.PowerBuilder.WPF.Controls"
    PBTitle="Window Title" PBHeight="2000" PBWidth="2500" MinBox="True" MaxBox="True" TitleBar="True" ControlMenu="True"
    Center="True" Resizable="True" Uid="5" >

            <Viewport3D Name="mainViewport" ClipToBounds="True">
            <Viewport3D.Camera>
                <PerspectiveCamera
                        Position="10,8,9"
                        LookDirection="-11,-9,-10"
                        FarPlaneDistance="100"
                        UpDirection="0,1,0"
                        NearPlaneDistance="1"
                        FieldOfView="70" >
                   
                </PerspectiveCamera>
            </Viewport3D.Camera>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <DirectionalLight
                        Color="White"
                        Direction="-2,-3,-1" />
                </ModelVisual3D.Content>
            </ModelVisual3D>
            </Viewport3D>
       
</pbwpf:Window>

 

Any help would be appreciated