Start with a geometry viewer

The first steps into creating your own PlanningSynthesis tool is to create a geometry viewer. Please fist download the CPlan library or the code from the repository. In the CPlan library you find a custom OpenTK control, which we extended to provide you the basic view control functions as well as object picking and some other helpful things.

In the following we use VisualStudio 2012. We start the tutorial by creating a new WindowsFormsApplication:

To add a new component right-click on the ToolBar window and click ChooseItems…:


Click on browse and select CPlan.VisualObjects.dll. You can find it in the downloaded releas folder or you use a build of the source code from the repository. In the next dialog slect GLCameraControl to be added to the Toolbox Items:

Click ok.

Now you find the new GLCameraControl in the Toolbox:

Drag & drop the GLCameraControl on your Windows Form. Select it and set Dock = Full in the properties menue.
The component brings some references with it, which should have been added automatically to your project References:

Now you can run your program and you should see your new geometry viewer! The properies of the viewer, like BackgroundColor or Raster Color, can be changed in the Properties dialog of the component.

Use the right mouse button for pan, mouse wheel for zoom (or right mouse+ctrl for zoom), right mouse+shift and right mouse+alt for rotation. There are different rotate modes for the 3D mode that we investigate later.

Unfortunatley it was not possible to add the Resize event directly to the component. Therefore you have to add the Resize event to your GLCameraControl component on the form and add the following code:

using System.Windows.Forms;
using CPlan.VisualObjects;
using OpenTK.Graphics.OpenGL;

namespace MyGeometryViewer
	public partial class Form1 : Form
		public Form1()

		private void glCameraControl1_Resize(object sender, EventArgs e)
			var curCtrl = (GLCameraControl)sender;
			if (!curCtrl.Loaded) return;
			int w = curCtrl.Width;
			int h = curCtrl.Height;
			GL.Viewport(0, 0, w, h);


Finally you can add a button and assign the code for creating a geometry object:

private void button1_Click(object sender, EventArgs e)
	GRectangle myRect = new GRectangle(1, 1, 200, 100);
	myRect.Filled = true;
	myRect.FillColor = ConvertColor.CreateColor4(Color.LightGray);
	glCameraControl1.AllObjectsList.Add(myRect, true, true);

With these few lines of code you add a rectangle to the viewer, which is drawn automatically. Furthermore you have already mouse interaction. Try to drag&drop the rectagle – it works! By the two boolean parameters in the method

 glCameraControl1.AllObjectsList.Add(myRect, true, true); 

you can define with the first boolean, if the object is drawn, and with the second boolean, if mouse interaction is enabled. From here you may explore by your own the capabilities of the component and the VisualObjects that you can use (look into the Object Browser, CPlan.VisualObjects).

Download the sample MyGeometryViewer

Leave a Reply

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