public MatrixF Translate(CoordinateF translation) { return(new MatrixF(Values[0], Values[1], Values[2], Values[3], Values[4], Values[5], Values[6], Values[7], Values[8], Values[9], Values[10], Values[11], Values[12] + translation.X, Values[13] + translation.Y, Values[14] + translation.Z, Values[15])); }
public bool EquivalentTo(CoordinateF test, float delta = 0.0001f) { var xd = Math.Abs(X - test.X); var yd = Math.Abs(Y - test.Y); var zd = Math.Abs(Z - test.Z); return((xd < delta) && (yd < delta) && (zd < delta)); }
public CoordinateF Cross(CoordinateF that) { var xv = (Y * that.Z) - (Z * that.Y); var yv = (Z * that.X) - (X * that.Z); var zv = (X * that.Y) - (Y * that.X); return(new CoordinateF(xv, yv, zv)); }
public CoordinateF Rotate(CoordinateF coord) { // http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation var q = new QuaternionF(coord.Normalise(), 0); var temp = q * Conjugate(); return((this * temp).Vector); }
public static MatrixF Scale(CoordinateF scale) { var m = Identity; m.Values[0] = scale.X; m.Values[5] = scale.Y; m.Values[10] = scale.Z; return(m); }
public static MatrixF Translation(CoordinateF translation) { var m = Identity; m.Values[12] = translation.X; m.Values[13] = translation.Y; m.Values[14] = translation.Z; return(m); }
public bool Equals(CoordinateF other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(EquivalentTo(other)); }
public static MatrixF Rotation(CoordinateF axis, float angle) { var cos = (float)Math.Cos(-angle); var sin = (float)Math.Sin(-angle); var t = 1f - cos; axis = axis.Normalise(); return(new MatrixF(t * axis.X * axis.X + cos, t * axis.X * axis.Y - sin * axis.Z, t * axis.X * axis.Z + sin * axis.Y, 0, t * axis.X * axis.Y + sin * axis.Z, t * axis.Y * axis.Y + cos, t * axis.Y * axis.Z - sin * axis.X, 0, t * axis.X * axis.Z - sin * axis.Y, t * axis.Y * axis.Z + sin * axis.X, t * axis.Z * axis.Z + cos, 0, 0, 0, 0, 1)); }
public CoordinateF ComponentDivide(CoordinateF c) { if (Math.Abs(c.X - 0) < 0.0001) { c.X = 1; } if (Math.Abs(c.Y - 0) < 0.0001) { c.Y = 1; } if (Math.Abs(c.Z - 0) < 0.0001) { c.Z = 1; } return(new CoordinateF(X / c.X, Y / c.Y, Z / c.Z)); }
public static QuaternionF EulerAngles(CoordinateF angles) { // http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternionF/index.htm angles = angles / 2; var sy = (float)Math.Sin(angles.Z); var sp = (float)Math.Sin(angles.Y); var sr = (float)Math.Sin(angles.X); var cy = (float)Math.Cos(angles.Z); var cp = (float)Math.Cos(angles.Y); var cr = (float)Math.Cos(angles.X); return(new QuaternionF(sr * cp * cy - cr * sp * sy, cr * sp * cy + sr * cp * sy, cr * cp * sy - sr * sp * cy, cr * cp * cy + sr * sp * sy)); }
public float Dot(CoordinateF c) { return((X * c.X) + (Y * c.Y) + (Z * c.Z)); }
public CoordinateF ComponentMultiply(CoordinateF c) { return(new CoordinateF(X * c.X, Y * c.Y, Z * c.Z)); }
public QuaternionF(float x, float y, float z, float w) { Vector = new CoordinateF(x, y, z); Scalar = w; }
public QuaternionF(CoordinateF vector, float scalar) { Vector = vector; Scalar = scalar; }
public static QuaternionF AxisAngle(CoordinateF axis, float angle) { return(Math.Abs(axis.VectorMagnitude()) < 0.0001 ? Identity : new QuaternionF(axis.Normalise() * (float)Math.Sin(angle / 2), (float)Math.Cos(angle / 2)).Normalise()); }