示例#1
0
		public void RenderXyzCube(GLControl glControl, EditorCamera camera)
		{
			if (this.cube != null)
			{
				//graphicsContext.SetMaterial(null);
				this.graphicsContext.DisableLighting();

				//this.graphicsContext.SetTexture(0, this.cubeTex);
				//this.graphicsContext.SetTexture(1, null);
				//this.graphicsContext.SetTexture(2, null);
				//this.graphicsContext.SetTexture(3, null);
				//GL.Enable(EnableCap.CullFace);
				//GL.CullFace(CullFaceMode.Front);
				OpenTKHelper.Assert();

				var result = new Matrix4();
				float ww = 384;
				var left = -ww / 2;
				var right = ww / 2;
				var bottom = -ww / 2;
				var top = ww / 2;
				var zFar = ww * 2;
				var zNear = -ww * 2;
				float invRL = 1 / (right - left);
				float invTB = 1 / (top - bottom);
				float invFN = 1 / (zFar - zNear);

				result.M11 = 2 * invRL;
				result.M22 = 2 * invTB;
				result.M33 = -2 * invFN;

				result.M41 = -(right + left) * invRL;
				result.M42 = -(top + bottom) * invTB;
				result.M43 = -(zFar + zNear) * invFN;
				result.M44 = 1;

				this.graphicsContext.SetProjection(ref result);

				int w = Math.Min(Math.Min(180, glControl.Width / 2), glControl.Height / 2);

				var pos = Vector3.Transform(new Vector3(0, 0, 200), camera.Rot);
				Matrix4 view = Matrix4.Rotate(camera.Rot) * Matrix4.CreateTranslation(pos);
				view.Invert();
				this.graphicsContext.SetView(ref view);

				this.graphicsContext.SetViewport(glControl.Width - w, glControl.Height - w, w, w);
				//GL.Viewport(glControl.Width - w, glControl.Height - w, w, w);

				this.graphicsContext.Render(this.cube);
				OpenTKHelper.Assert();
			}
		}
示例#2
0
		//private GLControl glControl;

		#region Constructors and Destructors

		public Base3DEditor(
			IComponentContext context, IEditorOptions<Base3DEditorOptions> options, Base3DEditorContent content)
		{
			this.options = options;
			this.content = content;
			this.graphicsContext = context.Resolve<ToeGraphicsContext>();
			this.camera = new EditorCamera(context.Resolve<IEditorOptions<EditorCameraOptions>>());
			this.camera.PropertyChanged += this.OnCameraPropertyChanged;
			this.InitializeComponent();
			this.Dock = DockStyle.Fill;
			//this.glControl = new GLControl(GraphicsMode.Default, 1, 0, GraphicsContextFlags.Default);
			//this.glControl.Dock = DockStyle.Fill;
			this.glControl.Load += this.GLControlLoad;
			this.glControl.Paint += this.GLControlPaint;
			this.glControl.Resize += this.GLControlResize;
			this.Controls.Add(this.glControl);
			this.glControl.MouseMove += this.OnSceneMouseMove;
			this.glControl.MouseEnter += this.OnSceneMouseEnter;
			this.glControl.MouseLeave += this.OnSceneMouseLeave;
			this.glControl.MouseWheel += this.OnSceneMouseWheel;
			this.glControl.KeyDown += this.OnControlKeyDown;
			this.glControl.KeyUp += this.OnControlKeyUp;
			this.glControl.GotFocus += this.OnSceneGotFocus;
			this.glControl.LostFocus += this.OnSceneLostFocus;
			this.Camera.LookAt(new Vector3(512, 64, 1024), new Vector3(0, 0, 0));
			this.CameraController = new TargetCameraController { Camera = this.Camera };
			this.yUpToolStripMenuItem.Click += this.SelectYUp;
			this.zUpToolStripMenuItem.Click += this.SelectZUp;
			this.UpdateCoordinateSystemIcon();
			this.UpdateLighingIcon();
			this.UpdateWireframeIcon();
			this.UpdateNormalIcon();
		}