void DestroyWorkAreaControl() { if (workAreaControl != null) { workAreaControl.Destroy(); workAreaControl.Dispose(); workAreaControl = null; } }
void InitWorkAreaControl() { DestroyWorkAreaControl(); if (workAreaViewsConfiguration != ViewsConfigurations.NoViews) { initializedWorkAreaViewsConfiguration = workAreaViewsConfiguration; workAreaControl = new MultiViewRenderTargetControl(); workAreaControl.Visible = false; dockPanel.Controls.Add(workAreaControl); Rect[] rectangles = null; switch (workAreaViewsConfiguration) { case ViewsConfigurations.OneView: rectangles = new Rect[] { new Rect(0, 0, 1, 1) }; break; case ViewsConfigurations.FourViews: rectangles = new Rect[] { new Rect(0, 0, .498f, .495f), new Rect(.502f, 0, 1, .495f), new Rect(0, .505f, .498f, 1), new Rect(.502f, .505f, 1, 1), }; break; } workAreaControl.SetViewsConfiguration(rectangles); workAreaControl.SetAutomaticUpdateFPSForAllViews(30); workAreaControl.Render += workAreaControl_Render; workAreaControl.RenderUI += workAreaControl_RenderUI; //subscribe events to first view RenderTargetUserControl control = workAreaControl.Views[0].Control; control.KeyDown += renderTargetUserControl1_KeyDown; control.KeyUp += renderTargetUserControl1_KeyUp; control.MouseDown += renderTargetUserControl1_MouseDown; control.MouseUp += renderTargetUserControl1_MouseUp; control.MouseMove += renderTargetUserControl1_MouseMove; control.Tick += renderTargetUserControl1_Tick; } }
void workAreaControl_RenderUI(MultiViewRenderTargetControl sender, int viewIndex, GuiRenderer renderer) { if (fontMedium == null) { fontMedium = FontManager.Instance.LoadFont("Default", .04f); } if (fontBig == null) { fontBig = FontManager.Instance.LoadFont("Default", .07f); } AddTextWithShadow(renderer, fontBig, string.Format("View {0}", viewIndex), new Vec2(.99f, .01f), HorizontalAlign.Right, VerticalAlign.Top, new ColorValue(1, 1, 1)); if (viewIndex == 0) { AddTextWithShadow(renderer, fontMedium, "Camera control: W A S D, right mouse button", new Vec2(.99f, .99f), HorizontalAlign.Right, VerticalAlign.Bottom, new ColorValue(1, 1, 1)); } Draw2DRectangles(renderer); }
void workAreaControl_RenderUI( MultiViewRenderTargetControl sender, int viewIndex, GuiRenderer renderer ) { if( fontMedium == null ) fontMedium = FontManager.Instance.LoadFont( "Default", .04f ); if( fontBig == null ) fontBig = FontManager.Instance.LoadFont( "Default", .07f ); AddTextWithShadow( renderer, fontBig, string.Format( "View {0}", viewIndex ), new Vec2( .99f, .01f ), HorizontalAlign.Right, VerticalAlign.Top, new ColorValue( 1, 1, 1 ) ); if( viewIndex == 0 ) { AddTextWithShadow( renderer, fontMedium, "Camera control: W A S D, right mouse button", new Vec2( .99f, .99f ), HorizontalAlign.Right, VerticalAlign.Bottom, new ColorValue( 1, 1, 1 ) ); } Draw2DRectangles( renderer ); }
void workAreaControl_Render( MultiViewRenderTargetControl sender, int viewIndex, Camera camera ) { //update camera if( Map.Instance != null ) { Vec3 position; Vec3 forward; Vec3 up; Degree fov; if( !freeCameraEnabled ) { //usual camera mode //add here your special camera management code and set "freeCameraEnabled = false;" position = Vec3.Zero; forward = new Vec3( 1, 0, 0 ); up = Vec3.ZAxis; fov = Map.Instance.Fov; //MapCamera mapCamera = Entities.Instance.GetByName( "MapCamera_0" ) as MapCamera; //if( mapCamera != null ) //{ // position = mapCamera.Position; // forward = mapCamera.Rotation * new Vec3( 1, 0, 0 ); // fov = mapCamera.Fov; //} } else { //free camera mode position = freeCameraPosition; forward = freeCameraDirection.GetVector(); up = Vec3.ZAxis; fov = Map.Instance.Fov; } //update control RenderTargetUserControl control = workAreaControl.Views[ viewIndex ].Control; if( viewIndex == 0 ) { //first view control.CameraNearFarClipDistance = Map.Instance.NearFarClipDistance; control.CameraFixedUp = up; control.CameraFov = fov; control.CameraPosition = position; control.CameraDirection = forward; } else { //all views except first view. set orthographic camera projection. control.CameraNearFarClipDistance = Map.Instance.NearFarClipDistance; control.CameraProjectionType = ProjectionTypes.Orthographic; control.CameraOrthoWindowHeight = 30; Vec3 lookAt = position; switch( viewIndex ) { case 1: control.CameraFixedUp = Vec3.ZAxis; control.CameraDirection = -Vec3.XAxis; control.CameraPosition = lookAt - control.CameraDirection * 100; break; case 2: control.CameraFixedUp = Vec3.ZAxis; control.CameraDirection = -Vec3.YAxis; control.CameraPosition = lookAt - control.CameraDirection * 100; break; case 3: control.CameraFixedUp = Vec3.YAxis; control.CameraDirection = -Vec3.ZAxis; control.CameraPosition = lookAt - control.CameraDirection * 100; break; } } } //update sound listener if( viewIndex == 0 && SoundWorld.Instance != null ) SoundWorld.Instance.SetListener( camera.Position, Vec3.Zero, camera.Direction, camera.Up ); //draw 2D graphics as 3D by means DebugGeometry if( workAreaViewsConfiguration == ViewsConfigurations.FourViews && viewIndex == 3 ) { const float cameraOffset = 10; Vec3 center = camera.Position + camera.Direction * cameraOffset; //draw box Vec3[] positions; int[] indices; GeometryGenerator.GenerateBox( new Vec3( 10, 4, 1 ), out positions, out indices ); Mat4 transform = new Mat4( Mat3.Identity, center ); camera.DebugGeometry.Color = new ColorValue( .5f, 0, 0 ); camera.DebugGeometry.AddVertexIndexBuffer( positions, indices, transform, false, true ); camera.DebugGeometry.Color = new ColorValue( 1, 1, 0 ); camera.DebugGeometry.AddVertexIndexBuffer( positions, indices, transform, true, true ); //draw axes camera.DebugGeometry.Color = new ColorValue( 1, 0, 0 ); camera.DebugGeometry.AddArrow( center, center + new Vec3( 5, 0, 0 ) ); camera.DebugGeometry.Color = new ColorValue( 0, 1, 0 ); camera.DebugGeometry.AddArrow( center, center + new Vec3( 0, 5, 0 ) ); camera.DebugGeometry.Color = new ColorValue( 0, 0, 1 ); camera.DebugGeometry.AddArrow( center, center + new Vec3( 0, 0, 5 ) ); } }
void DestroyWorkAreaControl() { if( workAreaControl != null ) { workAreaControl.Destroy(); workAreaControl.Dispose(); workAreaControl = null; } }
void InitWorkAreaControl() { DestroyWorkAreaControl(); if( workAreaViewsConfiguration != ViewsConfigurations.NoViews ) { initializedWorkAreaViewsConfiguration = workAreaViewsConfiguration; workAreaControl = new MultiViewRenderTargetControl(); workAreaControl.Visible = false; dockPanel.Controls.Add( workAreaControl ); Rect[] rectangles = null; switch( workAreaViewsConfiguration ) { case ViewsConfigurations.OneView: rectangles = new Rect[] { new Rect( 0, 0, 1, 1 ) }; break; case ViewsConfigurations.FourViews: rectangles = new Rect[] { new Rect( 0, 0, .498f, .495f ), new Rect( .502f, 0, 1, .495f ), new Rect( 0, .505f, .498f, 1 ), new Rect( .502f, .505f, 1, 1 ), }; break; } workAreaControl.SetViewsConfiguration( rectangles ); workAreaControl.SetAutomaticUpdateFPSForAllViews( 30 ); workAreaControl.Render += workAreaControl_Render; workAreaControl.RenderUI += workAreaControl_RenderUI; //subscribe events to first view RenderTargetUserControl control = workAreaControl.Views[ 0 ].Control; control.KeyDown += renderTargetUserControl1_KeyDown; control.KeyUp += renderTargetUserControl1_KeyUp; control.MouseDown += renderTargetUserControl1_MouseDown; control.MouseUp += renderTargetUserControl1_MouseUp; control.MouseMove += renderTargetUserControl1_MouseMove; control.Tick += renderTargetUserControl1_Tick; } }
internal View(MultiViewRenderTargetControl owner, Rect rectangle, RenderTargetUserControl control) { this.owner = owner; this.rectangle = rectangle; this.control = control; }
internal View( MultiViewRenderTargetControl owner, Rect rectangle, RenderTargetUserControl control ) { this.owner = owner; this.rectangle = rectangle; this.control = control; }
void workAreaControl_Render(MultiViewRenderTargetControl sender, int viewIndex, Camera camera) { //update camera if (Map.Instance != null) { Vec3 position; Vec3 forward; Vec3 up; Degree fov; if (!freeCameraEnabled) { //usual camera mode //add here your special camera management code and set "freeCameraEnabled = false;" position = Vec3.Zero; forward = new Vec3(1, 0, 0); up = Vec3.ZAxis; fov = Map.Instance.Fov; //MapCamera mapCamera = Entities.Instance.GetByName( "MapCamera_0" ) as MapCamera; //if( mapCamera != null ) //{ // position = mapCamera.Position; // forward = mapCamera.Rotation * new Vec3( 1, 0, 0 ); // fov = mapCamera.Fov; //} } else { //free camera mode position = freeCameraPosition; forward = freeCameraDirection.GetVector(); up = Vec3.ZAxis; fov = Map.Instance.Fov; } //update control RenderTargetUserControl control = workAreaControl.Views[viewIndex].Control; if (viewIndex == 0) { //first view control.CameraNearFarClipDistance = Map.Instance.NearFarClipDistance; control.CameraFixedUp = up; control.CameraFov = fov; control.CameraPosition = position; control.CameraDirection = forward; } else { //all views except first view. set orthographic camera projection. control.CameraNearFarClipDistance = Map.Instance.NearFarClipDistance; control.CameraProjectionType = ProjectionTypes.Orthographic; control.CameraOrthoWindowHeight = 30; Vec3 lookAt = position; switch (viewIndex) { case 1: control.CameraFixedUp = Vec3.ZAxis; control.CameraDirection = -Vec3.XAxis; control.CameraPosition = lookAt - control.CameraDirection * 100; break; case 2: control.CameraFixedUp = Vec3.ZAxis; control.CameraDirection = -Vec3.YAxis; control.CameraPosition = lookAt - control.CameraDirection * 100; break; case 3: control.CameraFixedUp = Vec3.YAxis; control.CameraDirection = -Vec3.ZAxis; control.CameraPosition = lookAt - control.CameraDirection * 100; break; } } } //update sound listener if (viewIndex == 0 && SoundWorld.Instance != null) { SoundWorld.Instance.SetListener(camera.Position, Vec3.Zero, camera.Direction, camera.Up); } //draw 2D graphics as 3D by means DebugGeometry if (workAreaViewsConfiguration == ViewsConfigurations.FourViews && viewIndex == 3) { const float cameraOffset = 10; Vec3 center = camera.Position + camera.Direction * cameraOffset; //draw box Vec3[] positions; int[] indices; GeometryGenerator.GenerateBox(new Vec3(10, 4, 1), out positions, out indices); Mat4 transform = new Mat4(Mat3.Identity, center); camera.DebugGeometry.Color = new ColorValue(.5f, 0, 0); camera.DebugGeometry.AddVertexIndexBuffer(positions, indices, transform, false, true); camera.DebugGeometry.Color = new ColorValue(1, 1, 0); camera.DebugGeometry.AddVertexIndexBuffer(positions, indices, transform, true, true); //draw axes camera.DebugGeometry.Color = new ColorValue(1, 0, 0); camera.DebugGeometry.AddArrow(center, center + new Vec3(5, 0, 0)); camera.DebugGeometry.Color = new ColorValue(0, 1, 0); camera.DebugGeometry.AddArrow(center, center + new Vec3(0, 5, 0)); camera.DebugGeometry.Color = new ColorValue(0, 0, 1); camera.DebugGeometry.AddArrow(center, center + new Vec3(0, 0, 5)); } }