Use of the 3D view and 3D objects

Based on the sample „Start with a geometry viewer“, we add 3D objects to the viewer and change between 2D and 3D view. To add the additional functions, we place two new buttons on our form and name them “prism” and “view 2D/3D”:

Double click a button to assign a click event to it. For the prism buttons click event we add code to create a prism based on an ellipse with random properties:


        private void button2_Click(object sender, EventArgs e)
            Random rnd = new Random();
            // -- The ellipse is the basic shape to be extruded as prism. Try e.g. to exchange the ellipse with the rectangle below.
            GEllipse myEllipse = new GEllipse(new Vector2d(rnd.Next(100), rnd.Next(100)), rnd.Next(50), rnd.Next(50), 0.1f);
            //GRectangle myRect = new GRectangle(rnd.Next(100), rnd.Next(100), rnd.Next(50, 200), rnd.Next(50, 200));
            // -- From the 2D geometry objects one can create a prism by using the Poly property.
            GPrism myPrism = new GPrism(myEllipse.Poly, rnd.Next(100));
            myPrism.Transparency = 1;
            myPrism.BorderWidth = 2;
            myPrism.FillColor = ConvertColor.CreateColor4(Color.White);
            myPrism.Filled = true;
            myPrism.BorderColor = ConvertColor.CreateColor4(Color.Orange);
            glCameraControl1.AllObjectsList.Add(myPrism, true, true);


Try to exchange the ellipse with a rectangle (use the commented code).

To see our prism in 3D we have to change the camera used so far for our view. Therefore we add a click event to the “view 2D/3D” button that switch from 2D to 3D view and back:


        private void button3_Click(object sender, EventArgs e)
            // -- Change the used camera --
            if (glCameraControl1.Camera == glCameraControl1.Camera_2D)
                glCameraControl1.Camera = glCameraControl1.Camera_3D;
                glCameraControl1.Camera = glCameraControl1.Camera_2D;


To navigate in the 3D view you use the same keys as for the 2D view. Only the free rotation (right mouse+shift) is different in 3D. Finally your scene may look like the one below. You can also drag&drop objects in the 3D view. To manipulate a prism you need to pick its footprint.

At the moment we only have the prism object in 3D, which serves to extrude the 2D shapes. If you want to create your own geometry objects, be sure to inherit from surfaces for 2D and from volumes for 3D objects.

MyGeometryViewer MyGeometryViewer2 (This sample contains an updated VisualObjects.dll)

Leave a Reply

Your email address will not be published. Required fields are marked *