/// <summary> /// Construct a Matrix4x4d specifying the matrix columns. /// </summary> public Matrix4x4d(Vertex4d c0, Vertex4d c1, Vertex4d c2, Vertex4d c3) { Column0 = c0; Column1 = c1; Column2 = c2; Column3 = c3; }
/// <summary> /// Creates a normalized plane. /// </summary> /// <param name="r"> /// A <see cref="Vertex4d"/> that specify the plane parameters. Distance is the last component of <paramref name="r"/>. /// </param> /// <returns> /// It returns the normalized plane. /// </returns> private static Plane NormalizePlane(string name, Vertex4d r) { // Normalize plane Vertex3d normal = new Vertex3d(r.x, r.y, r.z); return(new Plane(name, (Vertex3f)normal.Normalized, (float)(r.W / normal.Module()))); }
/// <summary> /// Extract the far plane from a model-view-projection matrix. /// </summary> /// <param name="modelViewProjection"> /// The <see cref="IMatrix4x4"/> that specify the matrix used for drawing the clipped object. /// </param> /// <returns> /// It returns a <see cref="Plane"/> defining the far clipping plane. /// </returns> public static Plane GetFrustumFarPlane(IMatrix4x4 modelViewProjection) { // Compute plane Vertex4d a = new Vertex4d(modelViewProjection.GetRow(2)); Vertex4d b = new Vertex4d(modelViewProjection.GetRow(3)); return(NormalizePlane(NameFar, b - a)); }
/// <summary> /// Extract the top plane from a model-view-projection matrix. /// </summary> /// <param name="modelViewProjection"> /// The <see cref="IMatrix4x4"/> that specify the matrix used for drawing the clipped object. /// </param> /// <returns> /// It returns a <see cref="Plane"/> defining the top clipping plane. /// </returns> public static Plane GetFrustumTopPlane(IMatrix4x4 modelViewProjection) { // Compute plane Vertex4d a = new Vertex4d(modelViewProjection.GetRow(3)); Vertex4d b = new Vertex4d(modelViewProjection.GetRow(1)); return(NormalizePlane(NameTop, a - b)); }
/// <summary> /// Set a default value to a shader attribute. /// </summary> /// <<param name="defaultValue"> /// A <see cref="Vertex4d"/> that specify the default value of the attribute. /// </param> /// <param name="attributeName"> /// A <see cref="String"/> that specify the name of the attribute variable. /// </param> /// <param name="blockName"> /// A <see cref="String"/> that specify the name of the input block encolosing <paramref name="inputName"/>. It /// can be null. /// </param> /// <exception cref="ArgumentException"> /// Exception thrown if <paramref name="inputName"/> is null or is not a valid input name. /// </exception> public void SetArrayDefault(Vertex4d defaultValue, string attributeName, string blockName) { if (String.IsNullOrEmpty(attributeName)) { throw new ArgumentException("invalid name", "attributeName"); } // Set vertex array SetVertexArray(new DefaultVertexArray(defaultValue), attributeName, blockName); }
public void TestUniform4d() { if (!HasVersion(4, 0) && !IsGlExtensionSupported("GL_ARB_gpu_shader_fp64")) { Assert.Inconclusive("required features not implemented"); } using (Device device = new Device()) using (new GLContext(device)) { uint program = CreateProgramUniform4d(); try { Vertex4d uniformStruct; double[] uniformValue; int uniformLoc = Gl.GetUniformLocation(program, "uVec"); if (uniformLoc < 0) { throw new InvalidOperationException("no uniform variable"); } // glGetUniformdv uniformValue = Array4(1.0); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array4(0.0), uniformValue); // glGetUniformdv (ref) uniformStruct = new Vertex4d(1.0); Gl.GetUniformd(program, uniformLoc, ref uniformStruct); Assert.AreEqual(Vertex4d.Zero, uniformStruct); // glUniform4d uniformValue = Array4(0.0); Gl.Uniform4(uniformLoc, Array4(1.0)); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array4(1.0), uniformValue); // glUniform4dv uniformValue = Array4(0.0); Gl.Uniform4(uniformLoc, Array4(9.0)); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array4(9.0), uniformValue); // glUniform4dv (ref) uniformValue = Array4(0.0); uniformStruct = new Vertex4d(5.0); Gl.Uniform4d(uniformLoc, 1, ref uniformStruct); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array4(5.0), uniformValue); } finally { Gl.DeleteProgram(program); } } }
/// <summary> /// Extract the far plane from a model-view-projection matrix. /// </summary> /// <param name="modelViewProjection"> /// The <see cref="IMatrix4x4"/> that specify the matrix used for drawing the clipped object. /// </param> /// <returns> /// It returns a <see cref="Plane"/> defining the far clipping plane. /// </returns> public static Plane GetFrustumFarPlane(IMatrix4x4 modelViewProjection) { // Compute plane Vertex4d a = new Vertex4d(modelViewProjection.GetRow(3)); Vertex4d b = new Vertex4d(modelViewProjection.GetRow(2)); Plane plane = NormalizePlane(NameFar, a - b); plane.Distance = -plane.Distance; return(plane); }
/// <summary> /// Construct an DefaultVertexArray for disabling vertex attribute, but assigning a default attribute for those /// shader programs using the attribute all the same. /// </summary> /// <param name="defaultAttribValue"> /// A <see cref="ArrayBufferObjectBase"/> which defines a vertex array buffer. /// </param> /// <param name="sectionIndex"> /// A <see cref="UInt32"/> that specify the section of <paramref name="arrayBuffer"/>. /// </param> public DefaultVertexArray(Vertex4d defaultAttribValue) { DefaultValue = defaultAttribValue; }
/// <summary> /// Compute the product of a IMatrix4x4 with a Vertex4d (project a vertex on this matrix). /// </summary> /// <param name="v"> /// A <see cref="Vertex4d"/> that specify the right vector operand. /// </param> /// <returns> /// A <see cref="Vertex4d"/> resulting from the product of this Vertex4d and the vector /// <paramref name="v"/>. This operator is used to transform a vector by a matrix. /// </returns> Vertex4d IMatrix4x4.Multiply(Vertex4d v) { return((Vertex4d)(this * (Vertex4f)v)); }
/// <summary> /// Construct a Matrix3x4d specifying the matrix columns. /// </summary> public Matrix3x4d(Vertex4d c0, Vertex4d c1, Vertex4d c2) { Column0 = c0; Column1 = c1; Column2 = c2; }
/// <summary> /// Construct a Matrix2x4d specifying the matrix columns. /// </summary> public Matrix2x4d(Vertex4d c0, Vertex4d c1) { Column0 = c0; Column1 = c1; }
/// <summary> /// Compute the product of a IMatrix4x4 with a Vertex4d (project a vertex on this matrix). /// </summary> /// <param name="v"> /// A <see cref="Vertex4d"/> that specifies the right vector operand. /// </param> /// <returns> /// A <see cref="Vertex4d"/> resulting from the product of this Vertex4d and the vector /// <paramref name="v"/>. This operator is used to transform a vector by a matrix. /// </returns> Vertex4d IMatrix4x4.Multiply(Vertex4d v) { return ((Vertex4d)(this * (Vertex4f)v)); }
void IShaderUniformContainer.SetUniform(GraphicsContext ctx, string uniformName, Vertex4d v) { throw new NotImplementedException(); }
/// <summary> /// Set an array buffer to a shader attribute. /// </summary> /// <param name="defaultValue"> /// A <see cref="Vertex4d"/> that specify the default value of the attribute. /// </param> /// <param name="semantic"> /// A <see cref="String"/> that specify the attribute semantic. Normally a constant of <see cref="VertexArraySemantic"/>. /// </param> /// <exception cref="ArgumentException"> /// Exception thrown if <paramref name="semantic"/> is null or is not a valid semantic name. /// </exception> public void SetArrayDefault(Vertex4d defaultValue, string semantic) { SetArrayDefault(defaultValue, semantic, SemanticBlockName); }
/// <summary> /// Compute the product of a IMatrix4x4 with a Vertex4d (project a vertex on this matrix). /// </summary> /// <param name="v"> /// A <see cref="Vertex4d"/> that specify the right vector operand. /// </param> /// <returns> /// A <see cref="Vertex4d"/> resulting from the product of this Vertex4d and the vector /// <paramref name="v"/>. This operator is used to transform a vector by a matrix. /// </returns> Vertex4d IMatrix4x4.Multiply(Vertex4d v) { return (this * v); }
/// <summary> /// Compute the product of a IMatrix4x4 with a Vertex4d (project a vertex on this matrix). /// </summary> /// <param name="v"> /// A <see cref="Vertex4d"/> that specify the right vector operand. /// </param> /// <returns> /// A <see cref="Vertex4d"/> resulting from the product of this Vertex4d and the vector /// <paramref name="v"/>. This operator is used to transform a vector by a matrix. /// </returns> Vertex4d IMatrix4x4.Multiply(Vertex4d v) { return(this * v); }
/// <summary> /// Creates a normalized plane. /// </summary> /// <param name="a"> /// A <see cref="Vertex4d"/> that specify the plane components. /// </param> /// <returns> /// It returns the normalized plane. /// </returns> private static Planed NormalizePlane(Vertex4d v) { return(NormalizePlane(v.x, v.y, v.z, v.w)); }
/// <summary> /// Creates a normalized plane. /// </summary> /// <param name="r"> /// A <see cref="Vertex4d"/> that specify the plane parameters. Distance is the last component of <paramref name="r"/>. /// </param> /// <returns> /// It returns the normalized plane. /// </returns> private static Plane NormalizePlane(string name, Vertex4d r) { double module = Math.Sqrt(r.x * r.x + r.y * r.y + r.z * r.z); return(new Plane(name, (float)(r.x / module), (float)(r.y / module), (float)(r.z / module), (float)(r.w / module))); }
/// <summary> /// Set uniform state variable (variant type variable) /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for operations. /// </param> /// <param name="uniformName"> /// A <see cref="String"/> that specify the variable name in the shader source. /// </param> /// <param name="v"> /// A <see cref="Vertex3f"/> holding the uniform variabile data. /// </param> public void SetVariantUniform(GraphicsContext ctx, string uniformName, Vertex4d v) { SetVariantUniform(ctx, uniformName, v.x, v.y, v.z, v.w); }