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 SyncBody2Bone(OpenTK.Mathematics.Matrix4 world) { var mat = startTransform.Convert().Inverted() * Body.WorldTransform.Convert(); BoneController.GetBones[BoneID].PhysTransform = mat * world; BoneController.GetBones[BoneID].Phys = true; }
public void DrawUI(Mesh mesh) { OpenTK.Mathematics.Matrix4 modelMatrix = Rect.GetModelMatrix(); Material.SetMatrix("model", modelMatrix); Material.SetColor("color", Color); GraphicsAPI.UseMeshMaterial(mesh, Material); GraphicsAPI.DrawTriangles(mesh.GetIndiceCount()); }
public void SyncBody2BoneRot(OpenTK.Mathematics.Matrix4 world) { return; var temp = Body.WorldTransform.Convert(); temp.M41 = startTransform.M41; temp.M42 = startTransform.M42; temp.M43 = startTransform.M43; var mat = startTransform.Convert().Inverted() * temp; BoneController.GetBones[BoneID].PhysTransform = mat * world; BoneController.GetBones[BoneID].Phys = true; }
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 Bind(Camera camera, Transform transform) { if (DiffuseTexture != null) { DiffuseTexture.BindTexture(); } if (NormalTexture != null) { NormalTexture.BindTexture(); } if (SpecularTexture != null) { SpecularTexture.BindTexture(); } Shader.UseShader(); OpenTK.Mathematics.Matrix4 modelMatrix = transform.GetModelMatrix(); Shader.SetMatrix("model", ref modelMatrix); OpenTK.Mathematics.Matrix4 viewMatrix = camera.GetViewMatrix(); Shader.SetMatrix("view", ref viewMatrix); OpenTK.Mathematics.Matrix4 projectionMatrix = camera.ProjectionMatrix; Shader.SetMatrix("projection", ref projectionMatrix); Shader.SetVector3("ambientLightColor", ref Scene.CurrentScene.AmbientLightColor); Vector3 LightColor = new Vector3(1.0f, 1.0f, 1.0f); Shader.SetVector3("lightColor", ref LightColor); Vector3 LightPosition = new Vector3(0.0f, 0.0f, 0.0f); Shader.SetVector3("lightPos", ref LightPosition); Shader.SetFloat("ambientLightStrength", Scene.CurrentScene.AmbientLightStrength); Shader.SetVector3("objectColor", ref Color); }
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"); }
public void Draw(Camera camera) { bool depthEnabled = GL.IsEnabled(EnableCap.DepthTest); GL.Disable(EnableCap.DepthTest); bool cullingEnabled = GL.IsEnabled(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); GL.DepthFunc(DepthFunction.Lequal); Texture.BindTexture(); DefaultShader.UseShader(); OpenTK.Mathematics.Matrix4 viewMatrix = new OpenTK.Mathematics.Matrix4(new OpenTK.Mathematics.Matrix3(camera.GetViewMatrix())); DefaultShader.SetMatrix("view", ref viewMatrix); OpenTK.Mathematics.Matrix4 projectionMatrix = camera.ProjectionMatrix; DefaultShader.SetMatrix("projection", ref projectionMatrix); GL.BindVertexArray(ArrayHandle); GL.DrawArrays(PrimitiveType.Triangles, 0, 36); GL.BindVertexArray(0); Texture.UnbindTexture(); GL.DepthFunc(DepthFunction.Less); if (depthEnabled) { GL.Enable(EnableCap.DepthTest); } if (cullingEnabled) { GL.Enable(EnableCap.CullFace); } }
public void SetScene(OpenTK.Mathematics.Vector3[] mesh, int[] indexes, OpenTK.Mathematics.Matrix4 startTransform) { //convert openTK to BulentSharp var meshP = new Vector3[mesh.Length]; for (int i = 0; i < mesh.Length; i++) { meshP[i] = mesh[i].Convert(); } TriangleIndexVertexArray triangles = new TriangleIndexVertexArray(indexes, meshP); CollisionShape shape = new BvhTriangleMeshShape(triangles, true); shape.CalculateLocalInertia(0); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(0, new DefaultMotionState(startTransform.Convert()), shape, Vector3.Zero); RigidBody Body = new RigidBody(rbInfo); Body.CollisionFlags = CollisionFlags.StaticObject; Body.UserObject = "Ground"; Body.UserIndex = 10; World.AddRigidBody(Body, CollisionFilterGroups.StaticFilter, CollisionFilterGroups.CharacterFilter); /* * const float staticMass = 0; * RigidBody body; * CollisionShape shape = new TriangleMesh() * Matrix groundTransform = Matrix.Translation(0, -0.5f, 0); * using (var rbInfo = new RigidBodyConstructionInfo(staticMass, null, shape) * { * StartWorldTransform = groundTransform, * }) * { * body = new RigidBody(rbInfo); * } * World.AddRigidBody(body, CollisionFilterGroups.StaticFilter, CollisionFilterGroups.AllFilter); */ }
public Matrix4 LookAt(Vector3 direction) { return(Matrix4.LookAt(Position.X, Position.Y, Position.Z, Position.X + direction.X, Position.Y + direction.Y, Position.Z + direction.Z, Up.X, Up.Y, Up.Z)); }
public Matrix4 GetModelMatrix() { return(Matrix4.CreateScale(Scale.X, Scale.Y, Scale.X) * Matrix4.CreateFromQuaternion(Rotation.ToOTK()) * Matrix4.CreateTranslation(Position.X, Position.Y, Position.Z)); }
public void SyncBone2Body(OpenTK.Mathematics.Matrix4 world) { var mat = (BoneController.GetBone(BoneID).TransformMatrix *world).Convert(); Body.MotionState.WorldTransform = startTransform * mat; }
public void Reinstalize(OpenTK.Mathematics.Matrix4 world) { Body.WorldTransform = startTransform * world.Convert(); Body.InterpolationWorldTransform = Body.WorldTransform; Body.ClearForces(); }
public void SetMatrix(string name, ref Matrix4 matrix, bool transpose = false) { int location = GetUniformLocation(name); GL.UniformMatrix4(location, transpose, ref matrix); }