/// <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> /// Generoi annetun määrän tähtiä /// </summary> /// <param name="kpl">Tähtien määrä</param> /// <returns></returns> private Kappale[] Generoi(int kpl) { double valovuosi = 63239.7263; Kappale[] kappaleet = new Kappale[kpl]; Random r = new Random(); for (int i = 0; i < kpl; i++) { Vertex3d sijainti; if (checkBox2.Checked) { sijainti = (new Vertex3d(r.NextDouble() * 10 - 5, r.NextDouble() * 10 - 5, r.NextDouble() * 10 - 5)) * valovuosi; } else { sijainti = (new Vertex3d(r.NextDouble() * 10 - 5, r.NextDouble() * 10 - 5, 0)) * valovuosi; } double massa = r.NextDouble() * 10; Vertex3d kiihtyvyys = (new Vertex3d(0, 0, 0)); Vertex3d nopeus = (new Vertex3d(0, 0, 0)); kappaleet[i] = new Kappale(sijainti, massa, kiihtyvyys, nopeus); } return(kappaleet); }
/// <summary> /// Construct a Matrix4x3d specifying the matrix columns. /// </summary> public Matrix4x3d(Vertex3d c0, Vertex3d c1, Vertex3d c2, Vertex3d c3) { Column0 = c0; Column1 = c1; Column2 = c2; Column3 = c3; }
public Kappale(Vertex3d sijainti, double massa, Vertex3d kiihtyvyys, Vertex3d nopeus) { Sijainti = sijainti; Massa = massa; Kiihtyvyys = kiihtyvyys; Nopeus = nopeus; }
/// <summary> /// Construct a plane from a normal and a distance from origin. /// </summary> /// <param name="normal"> /// A <see cref="Vertex3d"/> representing the plane normal. /// </param> /// <param name="d"> /// A <see cref="double"/> representing the distance between the plane and the origin. /// </param> public Planed(Vertex3d normal, double d) { _A = _B = _C = _D = 0.0; Normal = normal; Distance = d; }
public Lehti2D() { OnkoJuuriSolmu = false; OnkoTyhjä = true; Massa = 0; Massakeskipiste = new Vertex3d(0, 0, 0); }
private Planed(double a, double b, double c, double d) { _A = _B = _C = _D = 0.0; Normal = new Vertex3d(a, b, c); Distance = d; }
/// <summary> /// Add a contour to the current polygon. /// </summary> /// <param name="contourVertices"> /// /// </param> public void AddContour(Vertex3d[] contourVertices, Vertex3d normal) { if (contourVertices == null) { throw new ArgumentNullException("contourVertices"); } MemoryLock countourLock = new MemoryLock(contourVertices); // Dispose later _CountourLocks.Add(countourLock); // Set to Vertex3d.Zero to compute automatically Glu.TessNormal(_Tess, normal.x, normal.x, normal.z); IntPtr vLockAddr = countourLock.Address; Glu.TessBeginContour(_Tess); foreach (Vertex3d v in contourVertices) { Glu.TessVertex(_Tess, vLockAddr, vLockAddr); vLockAddr = new IntPtr(vLockAddr.ToInt64() + 24); } Glu.TessEndContour(_Tess); }
public void GenerateSphere(float radius, int rings, int sectors) { Destroy(); float R = 1.0f / (rings - 1); float S = 1.0f / (sectors - 1); Vertices = new Vertex3d[rings * sectors]; int index = 0; for (int r = 0; r < rings; r++) { for (int s = 0; s < sectors; s++) { float x = (float)(Math.Cos(2.0 * Math.PI * s * S) * Math.Sin(Math.PI * r * R)); float y = (float)(Math.Sin(2.0 * Math.PI * s * S) * Math.Sin(Math.PI * r * R)); float z = (float)Math.Cos(Math.PI * r * R); var vertex = new Vertex3d(); vertex.TexCoord.X = s * S; vertex.TexCoord.Y = r * R; vertex.Position.X = x * radius; vertex.Position.Y = y * radius; vertex.Position.Z = z * radius; vertex.Normal.X = x; vertex.Normal.X = y; vertex.Normal.X = z; vertex.Color = new Vector4(1.0f, 0.0f, 0.0f, 1.0f); Vertices[index++] = vertex; } } index = 0; for (int r = 0; r < rings; r++) { for (int s = 0; s < sectors; s++) { Indices.Add((uint)(r * sectors + s)); Indices.Add((uint)(r * sectors + (s + 1))); Indices.Add((uint)((r + 1) * sectors + (s + 1))); Indices.Add((uint)((r + 1) * sectors + s)); } } GL.GenBuffers(1, out VertexBuffer); GL.GenBuffers(1, out IndexBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * Vertex3d.Stride), Vertices, BufferUsageHint.StreamDraw); OpenGlHelper.CheckErrors(); GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(Indices.Count * sizeof(uint)), Indices.ToArray(), BufferUsageHint.DynamicDraw); OpenGlHelper.CheckErrors(); }
/// <summary> /// Construct a plane from a normal and a point. /// </summary> /// <param name="normal"> /// A <see cref="Vertex3d"/> representing the plane normal. /// </param> /// <param name="point"> /// A <see cref="Vertex3d"/> representing the point considered for constructing the plane. /// </param> public Planed(Vertex3d normal, Vertex3d point) { _A = _B = _C = _D = 0.0; Normal = normal; Distance = normal * point; }
/// <summary> /// Apumetodi etäisyyksien laskemiseen. /// </summary> /// <param name="a">Ensimmäinen piste</param> /// <param name="b">Toinen piste</param> /// <returns></returns> private double Etäisyys(Vertex3d a, Vertex3d b) { double x = Math.Pow(b.x - a.x, 2); double y = Math.Pow(b.y - a.y, 2); double z = Math.Pow(b.z - a.z, 2); return(Math.Sqrt(x + y + z)); }
/// <summary> /// Construct a plane from 3 coplanar points. /// </summary> /// <param name="v1"> /// A <see cref="Vertex3d"/> representing one plane coplanar point. /// </param> /// <param name="v2"> /// A <see cref="Vertex3d"/> representing one plane coplanar point. /// </param> /// <param name="v3"> /// A <see cref="Vertex3d"/> representing one plane coplanar point. /// </param> public Planed(Vertex3d v1, Vertex3d v2, Vertex3d v3) { _A = _B = _C = _D = 0.0; Vertex3d edge1 = v2 - v1, edge2 = v3 - v1; Normal = edge1 ^ edge2; Distance = Normal * v1; }
/// <summary> /// Accumulate a translation on this ModelMatrixDouble. /// </summary> /// <param name="p"> /// A <see cref="Vertex3d"/> that specify the translation. /// </param> public void Translate(Vertex3d p) { ModelMatrixDouble translationMatrix = new ModelMatrixDouble(); translationMatrix[3, 0] = p.x; translationMatrix[3, 1] = p.y; translationMatrix[3, 2] = p.z; Set(this * translationMatrix); }
/// <summary> /// Accumulate a scaling to this model matrix. /// </summary> /// <param name="s"> /// A <see cref="Vertex3d"/> holding the scaling factors on three dimensions. /// </param> public void Scale(Vertex3d s) { ModelMatrixDouble scaleModel = new ModelMatrixDouble(); scaleModel[0, 0] = s.x; scaleModel[1, 1] = s.y; scaleModel[2, 2] = s.z; Set(this * scaleModel); }
public void TestUniform3d() { 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 = CreateProgramUniform3d(); try { Vertex3d uniformStruct; double[] uniformValue; int uniformLoc = Gl.GetUniformLocation(program, "uVec"); if (uniformLoc < 0) { throw new InvalidOperationException("no uniform variable"); } // glGetUniformdv uniformValue = Array3(1.0); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array3(0.0), uniformValue); // glGetUniformdv (ref) uniformStruct = new Vertex3d(1.0); Gl.GetUniformd(program, uniformLoc, ref uniformStruct); Assert.AreEqual(Vertex3d.Zero, uniformStruct); // glUniform3d uniformValue = Array3(0.0); Gl.Uniform3(uniformLoc, Array3(1.0)); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array3(1.0), uniformValue); // glUniform3dv uniformValue = Array3(0.0); Gl.Uniform3(uniformLoc, Array3(9.0)); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array3(9.0), uniformValue); // glUniform3dv (ref) uniformValue = Array3(0.0); uniformStruct = new Vertex3d(5.0); Gl.Uniform3d(uniformLoc, 1, ref uniformStruct); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array3(5.0), uniformValue); } finally { Gl.DeleteProgram(program); } } }
/// <summary> /// Quaternion constructor from euler rotation axis and rotation angle. /// </summary> /// <param name="rVector"> /// A <see cref="Vertex3f"/> representing the rotation axis. /// </param> /// <param name="rAngle"> /// A <see cref="System.Single"/> representing the rotation angle (in degrees). /// </param> /// <remarks> /// This constructor is the base implementation for each other constructor. /// </remarks> public Quaternion(Vertex3f rVector, float rAngle) { // Set the default rotation axis mDefaultVector = (Vertex3d)rVector; // Make compiler happy mVector = new Vertex3d(); mCosAngle = 0.0f; // Set quaternion SetEuler(rVector, rAngle); }
/// <summary> /// Quaternion constructor from euler rotation axis and rotation angle. /// </summary> /// <param name="rVector"> /// A <see cref="Vertex3d"/> representing the rotation axis. /// </param> /// <param name="rAngle"> /// A <see cref="float"/> representing the rotation angle (in degrees). /// </param> /// <remarks> /// This constructor is the base implementation for each other constructor. /// </remarks> public Quaternion(Vertex3f rVector, float rAngle) { // Set the default rotation axis _DefaultVector = rVector; // Make compiler happy _Vector = new Vertex3d(); _CosAngle = 0.0f; // Set quaternion SetEuler(rVector, rAngle); }
/// <summary> /// Add a contour to the current polygon. /// </summary> /// <param name="contourVertices"> /// /// </param> public void AddContour(Vertex3f[] contourVertices, Vertex3f normal) { Vertex3d[] fixedVertices = new Vertex3d[contourVertices.Length]; for (int i = 0; i < contourVertices.Length; i++) { fixedVertices[i] = contourVertices[i]; } AddContour(fixedVertices, normal); }
public void ColorBGRD_CastToVertex4() { double r = (double)NextComponent(1.0); double g = (double)NextComponent(1.0); double b = (double)NextComponent(1.0); ColorBGRD v = new ColorBGRD(r, g, b); Vertex3d vArray = v; Assert.AreEqual(b, vArray.x); Assert.AreEqual(g, vArray.y); Assert.AreEqual(r, vArray.z); }
public void ColorRGBD_CastToVertex4() { Random random = new Random(); double r = (double)NextComponent(random, 1.0); double g = (double)NextComponent(random, 1.0); double b = (double)NextComponent(random, 1.0); ColorRGBD v = new ColorRGBD(r, g, b); Vertex3d vArray = v; Assert.AreEqual(r, vArray.x); Assert.AreEqual(g, vArray.y); Assert.AreEqual(b, vArray.z); }
/// <summary> /// Normalize this Quaternion. /// </summary> public void Normalize() { double magnitude = Magnitude; if (magnitude >= float.Epsilon) { double scale = 1.0 / magnitude; _Vector *= scale; _CosAngle *= scale; } else { throw new InvalidOperationException("zero magnitude quaternion"); } }
/// <summary> /// Metodi kappaleiden sijaintien päivittämiseen. /// </summary> /// <param name="kappaleet"></param> public void päivitä(Kappale[] kappaleet) { /* * Ulompi silmukka määrää kappaleen joka päivitetään, sisempi silmukka * on kaikkien muiden kappaleiden läpikäyntiä varten vuorovaikutusten * laskemiseksi. */ for (int i = 0; i < kappaleet.Length; i++) { Vertex3d kiihtyvyys = new Vertex3d(0, 0, 0); for (int j = 0; j < kappaleet.Length; j++) { //Kappale ei vaikuta omaan liikkeeseensä. if (i == j) { continue; } //Pehmennysparametri, poistaa laskennallisen singulariteetin mahdollisuuden. if (Etäisyys(kappaleet[i].Sijainti, kappaleet[j].Sijainti) < valovuosi * 0.01) { continue; } double massa_j = kappaleet[j].Massa; Vertex3d sijainti_i = kappaleet[i].Sijainti; Vertex3d sijainti_j = kappaleet[j].Sijainti; //Lasketaan kappaleeseen kohdistuva kiihtyvyys kappaleesta j, ja summataan se yhteen aiempien kanssa. kiihtyvyys += (sijainti_i - sijainti_j) * massa_j / (Math.Pow(Etäisyys(sijainti_i, sijainti_j), 3)); } //Lopulliseen kiihtyvyyteen otettava huomioon gravitaatiovakio. kappaleet[i].Kiihtyvyys = kiihtyvyys * -gravitaatiovakio; //Lasketaan kappaleen sijainti nopeuden, kiihtyvyyden ja aika-askeleen perusteella. kappaleet[i].Sijainti += kappaleet[i].Nopeus * aika + kappaleet[i].Kiihtyvyys * 0.5 * Math.Pow(aika, 2); //Lasketaan kappaleelle uusi nopeus vanhan nopeuden, kiihtyvyyden ja aika-askeleen perusteella. kappaleet[i].Nopeus = kappaleet[i].Nopeus + kappaleet[i].Kiihtyvyys * aika; } }
/// <summary> /// Setup this matrix to view the universe in a certain direction. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3f"/> that specify the eye position, in local coordinates. /// </param> /// <param name="forwardVector"> /// A <see cref="Vertex3f"/> that specify the direction of the view. It will be normalized. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3f"/> that specify the up vector of the view camera abstraction. It will be normalized /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="forwardVector"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtDirection(Vertex3d eyePosition, Vertex3d forwardVector, Vertex3d upVector) { Vertex3d rightVector; // Normalize forward vector forwardVector.Normalize(); // Normalize up vector (it should already be normalized) upVector.Normalize(); // Compute the right vector (cross-product between forward and up vectors; right is perperndicular to the plane) rightVector = forwardVector ^ upVector; rightVector.Normalize(); // Derive up vector upVector = rightVector ^ forwardVector; // Compute view matrix ModelMatrixDouble lookatMatrix = new ModelMatrixDouble(), positionMatrix = new ModelMatrixDouble(); // Row 0: right vector lookatMatrix[0, 0] = rightVector.x; lookatMatrix[0, 1] = rightVector.y; lookatMatrix[0, 2] = rightVector.z; // Row 1: up vector lookatMatrix[1, 0] = upVector.x; lookatMatrix[1, 1] = upVector.y; lookatMatrix[1, 2] = upVector.z; // Row 2: opposite of forward vector lookatMatrix[2, 0] = -forwardVector.x; lookatMatrix[2, 1] = -forwardVector.y; lookatMatrix[2, 2] = -forwardVector.z; // Eye position positionMatrix.Translate(eyePosition); // Complete look-at matrix Set(positionMatrix * lookatMatrix); }
/// <summary> /// Setup this matrix to view the universe in a certain direction. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3f"/> that specify the eye position, in local coordinates. /// </param> /// <param name="forwardVector"> /// A <see cref="Vertex3f"/> that specify the direction of the view. It will be normalized. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3f"/> that specify the up vector of the view camera abstraction. It will be normalized /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="forwardVector"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtDirection(Vertex3d eyePosition, Vertex3d forwardVector, Vertex3d upVector) { Vertex3d rightVector; forwardVector.Normalize(); upVector.Normalize(); rightVector = forwardVector ^ upVector; rightVector.Normalize(); if (rightVector.Module() <= 0.0f) { rightVector = Vertex3f.UnitX; } upVector = rightVector ^ forwardVector; // Compute view matrix ModelMatrixDouble lookatMatrix = new ModelMatrixDouble(); // Row 0: right vector lookatMatrix[0, 0] = rightVector.x; lookatMatrix[0, 1] = rightVector.y; lookatMatrix[0, 2] = rightVector.z; // Row 1: up vector lookatMatrix[1, 0] = upVector.x; lookatMatrix[1, 1] = upVector.y; lookatMatrix[1, 2] = upVector.z; // Row 2: opposite of forward vector lookatMatrix[2, 0] = -forwardVector.x; lookatMatrix[2, 1] = -forwardVector.y; lookatMatrix[2, 2] = -forwardVector.z; // Eye position lookatMatrix.Translate(eyePosition); // Complete look-at matrix Set(lookatMatrix); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3f"/> that specify the eye position, in local coordinates. /// </param> /// <param name="targetPosition"> /// A <see cref="Vertex3f"/> that specify the eye target position, in local coordinates. /// </param> /// <remarks> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="targetPosition"/> having /// an up direction equal to the current up vector. /// </remarks> public void LookAtTarget(Vertex3d eyePosition, Vertex3d targetPosition) { LookAtTarget(eyePosition, targetPosition, Vertex3d.UnitY); }
/// <summary> /// Compute the product of a IMatrix3x3 with a Vertex3d (project a vertex on this matrix). /// </summary> /// <param name="v"> /// A <see cref="Vertex3d"/> that specify the right vector operand. /// </param> /// <returns> /// A <see cref="Vertex3d"/> 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> public Vertex3d Multiply(Vertex3d v) { return ((Vertex3d)(this * (Vertex3f)v)); }
/// <summary> /// Compute the product of a IMatrix3x3 with a Vertex3d (project a vertex on this matrix). /// </summary> /// <param name="v"> /// A <see cref="Vertex3d"/> that specify the right vector operand. /// </param> /// <returns> /// A <see cref="Vertex3d"/> 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> public Vertex3d Multiply(Vertex3d v) { return (this * v); }
/// <summary> /// Accumulate a translation on this model matrix. /// </summary> /// <param name="p"> /// A <see cref="Vertex3d"/> that specify the translation. /// </param> public void Translate(Vertex3d p) { Translate((float)p.x, (float)p.y, (float)p.z); }
/// <summary> /// Setup this model matrix to view the universe in a certain direction. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3d"/> that specify the eye position, in local coordinates. /// </param> /// <param name="forwardVector"> /// A <see cref="Vertex3d"/> that specify the direction of the view. It will be normalized. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3d"/> that specify the up vector of the view camera abstraction. It will be normalized /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="forwardVector"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtDirection(Vertex3d eyePosition, Vertex3d forwardVector, Vertex3d upVector) { LookAtTarget((Vertex3f)eyePosition, (Vertex3f)forwardVector, (Vertex3f)upVector); }
/// <summary> /// Normalize this Quaternion. /// </summary> public void Normalize() { double magnitude = Magnitude; if (magnitude >= Single.Epsilon) { double scale = 1.0 / Magnitude; mVector *= scale; mCosAngle *= scale; } else throw new InvalidOperationException("zero magnitude quaternion"); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3f"/> that specify the eye position, in local coordinates. /// </param> /// <param name="targetPosition"> /// A <see cref="Vertex3f"/> that specify the eye target position, in local coordinates. /// </param> /// <remarks> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="targetPosition"/> having /// an up direction equal to the current up vector. /// </remarks> public void LookAtTarget(Vertex3d eyePosition, Vertex3d targetPosition) { LookAtTarget(eyePosition, targetPosition, Vertex3d.UnitY); }
/// <summary> /// Conjugate this Quaternion. /// </summary> public void Conjugate() { _Vector = -_Vector; }
/// <summary> /// Setup this model matrix to view the universe in a certain direction. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3d"/> that specify the eye position, in local coordinates. /// </param> /// <param name="forwardVector"> /// A <see cref="Vertex3d"/> that specify the direction of the view. It will be normalized. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3d"/> that specify the up vector of the view camera abstraction. It will be normalized /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="forwardVector"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtDirection(Vertex3d eyePosition, Vertex3d forwardVector, Vertex3d upVector) { LookAtTarget((Vertex3f)eyePosition, (Vertex3f)forwardVector, (Vertex3f)upVector); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3d"/> that specify the eye position, in local coordinates. /// </param> /// <param name="targetPosition"> /// A <see cref="Vertex3d"/> that specify the eye target position, in local coordinates. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3d"/> that specify the up vector of the view camera abstraction. /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="targetPosition"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtTarget(Vertex3d eyePosition, Vertex3d targetPosition, Vertex3d upVector) { LookAtTarget((Vertex3f)eyePosition, (Vertex3f)targetPosition, (Vertex3f)upVector); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3d"/> that specify the eye position, in local coordinates. /// </param> /// <param name="targetPosition"> /// A <see cref="Vertex3d"/> that specify the eye target position, in local coordinates. /// </param> /// <remarks> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="targetPosition"/> having /// an up direction equal to the current up vector. /// </remarks> public void LookAtTarget(Vertex3d eyePosition, Vertex3d targetPosition) { LookAtTarget((Vertex3f)eyePosition, (Vertex3f)targetPosition); }
/// <summary> /// Accumulate a scaling to this model matrix. /// </summary> /// <param name="s"> /// A <see cref="Vertex3d"/> holding the scaling factors on three dimensions. /// </param> public void Scale(Vertex3d s) { Scale((float)s.x, (float)s.y, (float)s.z); }
/// <summary> /// Accumulate a scaling to this model matrix. /// </summary> /// <param name="s"> /// A <see cref="Vertex3d"/> holding the scaling factors on three dimensions. /// </param> public void Scale(Vertex3d s) { ModelMatrixDouble scaleModel = new ModelMatrixDouble(); scaleModel[0, 0] = s.x; scaleModel[1, 1] = s.y; scaleModel[2, 2] = s.z; Set(this * scaleModel); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="targetPosition"> /// A <see cref="Vertex3f"/> that specify the eye target position, in local coordinates. /// </param> /// <remarks> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from current position, looking at <paramref name="targetPosition"/> having /// an up direction equal to the current up vector. /// </remarks> public void LookAtTarget(Vertex3d targetPosition) { LookAtTarget(Position, targetPosition); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="targetPosition"> /// A <see cref="Vertex3f"/> that specify the eye target position, in local coordinates. /// </param> /// <remarks> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from current position, looking at <paramref name="targetPosition"/> having /// an up direction equal to the current up vector. /// </remarks> public void LookAtTarget(Vertex3d targetPosition) { LookAtTarget(Position, targetPosition); }
/// <summary> /// Setup this matrix to view the universe in a certain direction. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3f"/> that specify the eye position, in local coordinates. /// </param> /// <param name="forwardVector"> /// A <see cref="Vertex3f"/> that specify the direction of the view. It will be normalized. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3f"/> that specify the up vector of the view camera abstraction. It will be normalized /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="forwardVector"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtDirection(Vertex3d eyePosition, Vertex3d forwardVector, Vertex3d upVector) { Vertex3d rightVector; // Normalize forward vector forwardVector.Normalize(); // Normalize up vector (it should already be normalized) upVector.Normalize(); // Compute the right vector (cross-product between forward and up vectors; right is perperndicular to the plane) rightVector = forwardVector ^ upVector; rightVector.Normalize(); // Derive up vector upVector = rightVector ^ forwardVector; // Compute view matrix ModelMatrixDouble lookatMatrix = new ModelMatrixDouble(), positionMatrix = new ModelMatrixDouble(); // Row 0: right vector lookatMatrix[0, 0] = rightVector.x; lookatMatrix[0, 1] = rightVector.y; lookatMatrix[0, 2] = rightVector.z; // Row 1: up vector lookatMatrix[1, 0] = upVector.x; lookatMatrix[1, 1] = upVector.y; lookatMatrix[1, 2] = upVector.z; // Row 2: opposite of forward vector lookatMatrix[2, 0] = -forwardVector.x; lookatMatrix[2, 1] = -forwardVector.y; lookatMatrix[2, 2] = -forwardVector.z; // Eye position positionMatrix.Translate(eyePosition); // Complete look-at matrix Set(positionMatrix * lookatMatrix); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3f"/> that specify the eye position, in local coordinates. /// </param> /// <param name="targetPosition"> /// A <see cref="Vertex3f"/> that specify the eye target position, in local coordinates. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3f"/> that specify the up vector of the view camera abstraction. /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="targetPosition"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtTarget(Vertex3d eyePosition, Vertex3d targetPosition, Vertex3d upVector) { LookAtDirection(eyePosition, targetPosition - eyePosition, upVector); }
/// <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="Vertex3d"/> holding the uniform variabile data. /// </param> public void SetVariantUniform(GraphicsContext ctx, string uniformName, Vertex3d v) { SetVariantUniform(ctx, uniformName, v.x, v.y, v.z); }
/// <summary> /// Accumulate a translation on this model matrix. /// </summary> /// <param name="p"> /// A <see cref="Vertex3d"/> that specifies the translation. /// </param> public void Translate(Vertex3d p) { Translate((float)p.x, (float)p.y, (float)p.z); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3d"/> that specify the eye position, in local coordinates. /// </param> /// <param name="targetPosition"> /// A <see cref="Vertex3d"/> that specify the eye target position, in local coordinates. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3d"/> that specify the up vector of the view camera abstraction. /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="targetPosition"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtTarget(Vertex3d eyePosition, Vertex3d targetPosition, Vertex3d upVector) { LookAtTarget((Vertex3f)eyePosition, (Vertex3f)targetPosition, (Vertex3f)upVector); }
/// <summary> /// Accumulate a translation on this ModelMatrixDouble. /// </summary> /// <param name="p"> /// A <see cref="Vertex3d"/> that specifies the translation. /// </param> public void Translate(Vertex3d p) { ModelMatrixDouble translationMatrix = new ModelMatrixDouble(); translationMatrix[3, 0] = p.x; translationMatrix[3, 1] = p.y; translationMatrix[3, 2] = p.z; Set(this * translationMatrix); }
/// <summary> /// Compute a model-view matrix in order to simulate the gluLookAt mithical GLU routine. /// </summary> /// <param name="eyePosition"> /// A <see cref="Vertex3f"/> that specify the eye position, in local coordinates. /// </param> /// <param name="targetPosition"> /// A <see cref="Vertex3f"/> that specify the eye target position, in local coordinates. /// </param> /// <param name="upVector"> /// A <see cref="Vertex3f"/> that specify the up vector of the view camera abstraction. /// </param> /// <returns> /// It returns a view transformation matrix used to transform the world coordinate, in order to view /// the world from <paramref name="eyePosition"/>, looking at <paramref name="targetPosition"/> having /// an up direction equal to <paramref name="upVector"/>. /// </returns> public void LookAtTarget(Vertex3d eyePosition, Vertex3d targetPosition, Vertex3d upVector) { LookAtDirection(eyePosition, targetPosition - eyePosition, upVector); }