public void Render(TargetBase target, TargetView targetView) { //background colour var immlColour = _Context.GetBackgroundColorOrDefault(Imml.Drawing.Color3.White); var bgColour = new Color4(immlColour.R, immlColour.G, immlColour.B, 1); target.DeviceManager.ContextDirect3D.ClearRenderTargetView(target.RenderTargetView, bgColour); var camera = _Context.GetActiveCamera(); if (camera != null) { var lookAt = new Vector3( (float)Math.Sin(camera.WorldRotation.X) + camera.WorldPosition.X, camera.WorldPosition.Y, (float)Math.Cos(camera.WorldRotation.Z) + camera.WorldPosition.Z); targetView.View = Matrix.LookAtLH(camera.WorldPosition.ToSharpDxVector(), lookAt, Vector3.UnitY); } }
public void Render(TargetBase target, TargetView targetView) { if (!_Context.IsVisible) { return; } var d3dContext = target.DeviceManager.ContextDirect3D; var view = targetView.View; var proj = Matrix.PerspectiveFovLH(targetView.FieldOfView, (float)target.RenderTargetSize.Width / (float)target.RenderTargetSize.Height, targetView.NearPlane, targetView.FarPlane); var viewProj = Matrix.Multiply(view, proj); var time = (float)(_Stopwatch.ElapsedMilliseconds / 1000f); var scale = _Context.WorldSize.ToSharpDxVector(); var rotation = _Context.WorldRotation.ToSharpDxVector(); var translation = _Context.WorldPosition.ToSharpDxVector(); var worldMatrix = Matrix.Scaling(scale) * Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation) * viewProj; worldMatrix.Transpose(); // Setup the pipeline d3dContext.InputAssembler.SetVertexBuffers(0, _VertexBufferBinding); d3dContext.InputAssembler.InputLayout = _InputLayout; d3dContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; d3dContext.VertexShader.SetConstantBuffer(0, _ConstantBuffer); d3dContext.VertexShader.Set(_VertexShader); d3dContext.PixelShader.Set(_PixelShader); d3dContext.UpdateSubresource(ref worldMatrix, _ConstantBuffer, 0); d3dContext.Draw(36, 0); }