/// <summary> /// Aligns the rigid bodies by correcting their orienation /// This should be called after the simulation step /// </summary> private void AlignBones() { // orient the bodies accordingly for (var i = this.BoneInset; i < this.simulatedTransforms.Count - this.BoneInset; i++) { if (!this.simulatedTransforms[i].Dynamic) { continue; } var a = this.simulatedTransforms[i - 1].Position; var b = this.simulatedTransforms[i + 1].Position; // this is the upVector computed for each bone of the rest pose var transform = this.restPoseSpace * this.restPoseTransforms[i]; // todo: direction of multiply? var y = SimdExtensions.CreateQuaternion(transform).Act(new SCNVector3(0f, 1f, 0f)); var x = SCNVector3.Normalize(b - a); var z = SCNVector3.Normalize(SCNVector3.Cross(x, y)); y = SCNVector3.Normalize(SCNVector3.Cross(z, x)); var rot = new OpenTK.Matrix3(x.X, y.X, z.X, x.Y, y.Y, z.Y, x.Z, y.Z, z.Z); this.simulatedTransforms[i].Orientation = new SCNQuaternion(rot.ToQuaternion()); } }
public static Assimp.Matrix3x3 ToAssimp(this OpenTK.Matrix3 matrix) { var m = matrix; m.Transpose(); return(new Assimp.Matrix3x3(m.M11, m.M12, m.M13, m.M21, m.M22, m.M23, m.M31, m.M32, m.M33)); }
//TODO: Maybe rewrite and document? /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <param name="input"></param> public void SetAttribute <T>(String name, T input) { Int32 program = GL.GetUniformLocation(this.address, name); switch (typeof(T).Name) //hmm { case nameof(Int16): { Int16 output = (Int16)(Object)input; GL.Uniform1(program, output); break; } case nameof(Int32): { Int32 output = (Int32)(Object)input; GL.Uniform1(program, output); break; } case nameof(Int64): { Int64 output = (Int64)(Object)input; GL.Uniform1(program, output); break; } case nameof(Single): { Single output = (Single)(Object)input; GL.Uniform1(program, output); break; } case nameof(Double): { Double output = (Double)(Object)input; GL.Uniform1(program, output); break; } case nameof(OpenTK.Vector2): { OpenTK.Vector2 output = (OpenTK.Vector2)(Object) input; GL.Uniform2(program, ref output); break; } case nameof(OpenTK.Vector3): { OpenTK.Vector3 output = (OpenTK.Vector3)(Object) input; GL.Uniform3(program, ref output); break; } case nameof(OpenTK.Vector4): { OpenTK.Vector4 output = (OpenTK.Vector4)(Object) input; GL.Uniform4(program, ref output); break; } case nameof(OpenTK.Matrix2): { OpenTK.Matrix2 output = (OpenTK.Matrix2)(Object) input; GL.UniformMatrix2(program, false, ref output); break; } case nameof(OpenTK.Matrix3): { OpenTK.Matrix3 output = (OpenTK.Matrix3)(Object) input; GL.UniformMatrix3(program, false, ref output); break; } case nameof(OpenTK.Matrix4): { OpenTK.Matrix4 output = (OpenTK.Matrix4)(Object) input; GL.UniformMatrix4(program, false, ref output); break; } default: throw new Exception("Bad type providen"); } }
public static OpenTK.Vector3 Transform(this OpenTK.Vector3 left, OpenTK.Matrix3 right) { OpenTK.Vector3 product = new OpenTK.Vector3(); product.X = right.M11 * left.X + right.M12 * left.Y + right.M13 * left.Z; product.Y = right.M21 * left.X + right.M22 * left.Y + right.M23 * left.Z; product.Z = right.M31 * left.X + right.M32 * left.Y + right.M33 * left.Z; return(product); }
public void LookAt(OpenTK.Vector3 at, OpenTK.Vector3 up) { var zaxis = (at - Position).Normalized(); var xaxis = OpenTK.Vector3.Cross(up, zaxis).Normalized(); var yaxis = OpenTK.Vector3.Cross(zaxis, xaxis); var mat = new OpenTK.Matrix3(xaxis, yaxis, zaxis); Rotation = mat.ExtractRotation(); }
public void Apply(int location, ref int textures) { var mat = new OpenTK.Matrix3(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { mat[i, j] = (float)matrix[i, j]; } } GL.UniformMatrix3(location, false, ref mat); }
/// <summary> /// Returns the interpolated transform at a given length (l from 0.0 to totalLength) /// </summary> public SCNMatrix4 Transform(float l) { var position = this.Position(l); var x = this.Tangent(l); var y = SCNVector3.Normalize(this.UpVector); var z = SCNVector3.Normalize(SCNVector3.Cross(x, y)); y = SCNVector3.Normalize(SCNVector3.Cross(z, x)); var rot = new OpenTK.Matrix3(x.X, y.X, z.X, x.Y, y.Y, z.Y, x.Z, y.Z, z.Z); var matrix = SCNMatrix4.Rotate(rot.ToQuaternion()); return(matrix.SetTranslation((OpenTK.Vector3)position)); }
public static OpenTK.Matrix4 ToMatrix4(this OpenTK.Matrix3 left) { OpenTK.Matrix4 result = OpenTK.Matrix4.Identity; result.M11 = left.M11; result.M12 = left.M12; result.M13 = left.M13; result.M21 = left.M21; result.M22 = left.M22; result.M23 = left.M23; result.M31 = left.M31; result.M32 = left.M32; result.M33 = left.M33; return(result); }
public static GenericBone ToBone(byte[] data) { if (data.Length == 0) { return(null); } GenericBone bone = new GenericBone(); using (DataReader r = new DataReader(new System.IO.MemoryStream(data))) { bone.ID = r.ReadInt32(); bone.ParentIndex = r.ReadInt32(); r.Skip(4); r.Seek(0xC); bone.Position = new OpenTK.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); var rot = new OpenTK.Matrix3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); bone.QuaternionRotation = rot.ExtractRotation().Inverted(); bone.Scale = new OpenTK.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); } return(bone); }
/// <summary> /// Reorder matrix to VC quaternion<para/> /// Пересчёт матрицы в VC-кватернион /// </summary> /// <returns>Correct quaternion<para/>Исправленный кватернион</returns> public static OpenTK.Quaternion ToVCQuaternion(this OpenTK.Matrix3 rotation) { OpenTK.Quaternion q = OpenTK.Quaternion.FromMatrix(rotation); return(new OpenTK.Quaternion(-q.X, -q.Z, -q.Y, -q.W)); }
/// <summary> /// Set data in the uniform at the location /// </summary> /// <param name="name">The uniform name</param> /// <param name="value"></param> public void Uniform(string name, ref OpenTK.Matrix3 value) { Bind(); GL.UniformMatrix3(GetUniformLocation(name), false, ref value); }
/// <summary> /// Set data in the uniform at the location /// </summary> /// <param name="location">The uniform location</param> /// <param name="value"></param> /// <returns>Uniform location</returns> public void Uniform(int location, ref OpenTK.Matrix3 value) { Bind(); GL.UniformMatrix3(location, false, ref value); }
public static SSBHLib.Formats.Matrix3x3 ToSsbh(this OpenTK.Matrix3 matrix) { return(new SSBHLib.Formats.Matrix3x3(matrix.Row0.ToSsbh(), matrix.Row1.ToSsbh(), matrix.Row2.ToSsbh())); }
/// <summary> /// /// </summary> /// <param name="m"></param> /// <param name="v"></param> public Transformation(OpenTK.Matrix3 m, OpenTK.Vector3 v) { _rotation = m; _translation = v; }
public static LDDModder.Simple3D.Matrix3 ToLDD(this OpenTK.Matrix3 matrix) { return(new Simple3D.Matrix3(matrix.Row0.ToLDD(), matrix.Row1.ToLDD(), matrix.Row2.ToLDD())); }
public static OpenTK.Vector2 Transform(this OpenTK.Vector2 position, OpenTK.Matrix3 matrix) { return(position.Transform(matrix.ToMatrix4())); }