public void Draw(Camera camera) { if (Target == null) { return; } bool depthState = GL.IsEnabled(EnableCap.DepthTest); GL.Disable(EnableCap.DepthTest); DefaultShader.UseShader(); float distance = Vector3.Distance(camera.transform.Position, Target.Position); Matrix4 modelMatrix = Matrix4.Identity * Matrix4.CreateScale(Scale.X * (distance / 32.0f), Scale.Y * (distance / 32.0f), Scale.Z * (distance / 32.0f)) * Matrix4.CreateTranslation(Target.Position.X, Target.Position.Y, Target.Position.Z); DefaultShader.SetMatrix("model", ref modelMatrix); Matrix4 viewMatrix = camera.GetViewMatrix(); DefaultShader.SetMatrix("view", ref viewMatrix); Matrix4 projectionMatrix = camera.ProjectionMatrix; DefaultShader.SetMatrix("projection", ref projectionMatrix); // Draw X Axis DefaultShader.SetVector3("lineColor", ref xAxisColor); GLException.CheckError("AxisRenderer Shader"); VAO.Draw(PrimitiveType.LineStrip, 0, vert_offset); // Draw Y Axis DefaultShader.SetVector3("lineColor", ref yAxisColor); GLException.CheckError("AxisRenderer Shader"); VAO.Draw(PrimitiveType.LineStrip, vert_offset, vert_offset * 2); // Draw Z Axis DefaultShader.SetVector3("lineColor", ref zAxisColor); GLException.CheckError("AxisRenderer Shader"); VAO.Draw(PrimitiveType.LineStrip, vert_offset * 2, vert_offset * 3); if (depthState) { GL.Enable(EnableCap.DepthTest); } GLException.CheckError("AxisRenderer VAO"); }
public void Draw(Camera camera) { bool blendState = GL.IsEnabled(EnableCap.Blend); GL.Enable(EnableCap.Blend); GL.BlendEquation(BlendEquationMode.FuncAdd); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); DefaultShader.UseShader(); OpenTK.Mathematics.Matrix4 modelMatrix = OpenTK.Mathematics.Matrix4.Identity * OpenTK.Mathematics.Matrix4.CreateTranslation(0, 0.0f, 0); DefaultShader.SetMatrix("model", ref modelMatrix); OpenTK.Mathematics.Matrix4 viewMatrix = camera.GetViewMatrix(); DefaultShader.SetMatrix("view", ref viewMatrix); OpenTK.Mathematics.Matrix4 projectionMatrix = camera.ProjectionMatrix; DefaultShader.SetMatrix("projection", ref projectionMatrix); DefaultShader.SetVector3("lineColor", ref GridColor); DefaultShader.SetVector3("cam_pos", ref camera.transform.Position); GLException.CheckError("LineGridRenderer Shader"); VAO.Draw(); if (!blendState) { GL.Disable(EnableCap.Blend); } GLException.CheckError("LineGridRenderer VAO"); }
public void Draw(Camera camera, GameObject gameObject) { bool blendState = GL.IsEnabled(EnableCap.Blend); GL.Disable(EnableCap.Blend); //GL.BlendEquation(BlendEquationMode.FuncAdd); //GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); DefaultShader.UseShader(); // compute custom model matrix based on the physics stuff OpenTK.Mathematics.Matrix4 min = OpenTK.Mathematics.Matrix4.CreateTranslation(gameObject.BodyReference.BoundingBox.Min.X, gameObject.BodyReference.BoundingBox.Min.Y, gameObject.BodyReference.BoundingBox.Min.Z); //OpenTK.Mathematics.Matrix4 max = OpenTK.Mathematics.Matrix4.CreateTranslation(gameObject.BodyReference.BoundingBox.Max.X, gameObject.BodyReference.BoundingBox.Max.Y, gameObject.BodyReference.BoundingBox.Max.Z); OpenTK.Mathematics.Matrix4 modelMatrix = gameObject.transform.GetModelMatrix(); DefaultShader.SetMatrix("model", ref modelMatrix); OpenTK.Mathematics.Matrix4 viewMatrix = camera.GetViewMatrix(); DefaultShader.SetMatrix("view", ref viewMatrix); OpenTK.Mathematics.Matrix4 projectionMatrix = camera.ProjectionMatrix; DefaultShader.SetMatrix("projection", ref projectionMatrix); DefaultShader.SetVector3("lineColor", ref Color); GLException.CheckError("LineShapeRenderer Shader"); VAO.Draw(); if (blendState) { GL.Enable(EnableCap.Blend); } GLException.CheckError("LineShapeRenderer VAO"); }