public OrthographicCameraComponent(SurfaceSize surface) { this.prevScreenWidth = surface.Width; this.prevScreenHeight = surface.Height; Scale = 1; ResetToDefault(); }
public IExecutionResult Initialize(string surfaceSizeInput) { SurfaceSize surfaceSize = null; if (!string.IsNullOrWhiteSpace(surfaceSizeInput)) { var gridSize = surfaceSizeInput.Split(' '); if (gridSize.Length == 2) { if (int.TryParse(gridSize[0], out int width)) { if (int.TryParse(gridSize[1], out int height)) { surfaceSize = new SurfaceSize(width, height); } } } } if (surfaceSize == null) { return(null); } Emit(new InitializePlateauEvent(surfaceSize)); return(ExecutionResult.Success()); }
private void OnControlResized(object sender, EventArgs e) { var width = (float)control.Width; var height = (float)control.Height; Size = new SurfaceSize(width, height); Resized(); }
public static GameStructBuffer FromCameraState(CameraState state, SurfaceSize size) { return(new GameStructBuffer( Matrix4x4.Transpose(state.ViewMatrix), Matrix4x4.Transpose(state.ProjectionMatrix), state.LookDirection, state.UpDirection, state.Position, size)); }
public override Matrix4x4 UpdateProjectionMatrix(SurfaceSize size) { float aspectRatio = size.Width / size.Height; ProjectionMatrix = Matrix4x4.CreatePerspectiveFieldOfView( FieldOfViewRadians, aspectRatio, NearPlaneDistance, FarPlaneDistance); return(ProjectionMatrix); }
public WpfWindows(WinFormsD3DControl control, WindowsFormsHost host, DefaultInputObserver input) { InputManager = new InputManager(input); this.control = control; this.control.Resize += OnControlResized; this.control.Paint += OnControlPaint; host.SizeChanged += OnHostSizeChanged; var width = (float)control.Width; var height = (float)control.Height; Size = new SurfaceSize(width, height); }
public override Matrix4x4 UpdateProjectionMatrix(SurfaceSize size) { this.prevScreenWidth = size.Width; this.prevScreenHeight = size.Height; float aspectRatio = size.Width / size.Height; var frameWidth = Width * Scale; ProjectionMatrix = Matrix4x4.CreateOrthographic( frameWidth, frameWidth / aspectRatio, NearPlaneDistance, FarPlaneDistance); return(ProjectionMatrix); }
void CreateBuffers(int width, int height) { Size = new SurfaceSize(width, height); var zBufferTextureDescription = new Texture2DDescription { Format = Format.D32_Float_S8X24_UInt,//D24_UNorm_S8_UInt ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }; using (var zBufferTexture = new Texture2D(directX.D3DDevice, zBufferTextureDescription)) { DepthStencilView = new DepthStencilView(directX.D3DDevice, zBufferTexture); } var depthEnabledStencilState = new DepthStencilState(directX.D3DDevice, D3DDepthStencilStateDescriptions.DepthEnabled); var viewport = new SharpDX.Viewport(0, 0, width, height, 0f, 1.0f); ImmediateContext.Rasterizer.SetViewport(viewport); ImmediateContext.OutputMerger.SetTargets(DepthStencilView, directX.RenderTarget); //no zbuffer and DepthStencil //ImmediateContext.OutputMerger.SetRenderTargets(renderTargetView); //with zbuffer / DepthStencil ImmediateContext.OutputMerger.SetDepthStencilState(depthEnabledStencilState, 0); //var blendStateDesc = new BlendStateDescription(); //blendStateDesc.RenderTarget[0].IsBlendEnabled = true; //blendStateDesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; //blendStateDesc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; //blendStateDesc.RenderTarget[0].BlendOperation = BlendOperation.Add; //blendStateDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; //blendStateDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero; //blendStateDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; //blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; //var blend = new BlendState(Device, blendStateDesc); //var blendFactor = new Color4(0, 0, 0, 0); //Device.ImmediateContext.OutputMerger.SetBlendState(blend, blendFactor, -1); }
public InitializePlateauEvent(SurfaceSize surfaceSize) { Size = surfaceSize; }
public abstract Matrix4x4 UpdateProjectionMatrix(SurfaceSize size);
public void Define(int width, int height) { Size = new SurfaceSize(width, height); }
public void Define(string surfaceSizeInput) { var result = commandSplitter.Split(surfaceSizeInput); Size = new SurfaceSize(result.Width, result.Height); }
// public GameStructBuffer(Matrix4x4 view, Matrix4x4 proj, Vector3 lookDirection, Vector3 up, Vector3 pos, SurfaceSize size) { View = view; Projection = proj; CameraLook = new Vector4(Vector3.Normalize(lookDirection), 0);// Matrix4x4.Identity ;// lookDirection; CameraUp = new Vector4(Vector3.Normalize(up), 0); CameraPosition = new Vector4(pos, 1); Viewport = new Vector4(size.Width, size.Height, 1f / size.Width, 1f / size.Height); }