public static Matrix4 Rotate(Quaternion q) { Vector3 axis; float angle; q.ToAxisAngle(out axis, out angle); return(Matrix4.CreateFromAxisAngle(axis, angle)); }
/// <summary> /// Build a rotation matrix from the specified quaternion. /// </summary> /// <param name="q">Quaternion to translate.</param> /// <param name="result">Matrix result.</param> public static void CreateFromQuaternion(ref Quaternion q, out Matrix3 result) { Vector3 axis; float angle; q.ToAxisAngle(out axis, out angle); CreateFromAxisAngle(axis, angle, out result); }
public static void DrawObject(DrawingContext ctx, uint[] indeices, VertexPositionNormalTexture[] array, tkVector3 position, tkQuaternion orientation, object tag, bool selected = false) { GL.Translate(position.X, position.Y, position.Z); OpenTK.Quaternion q = orientation; OpenTK.Vector3 r; float angle = 0; q.ToAxisAngle(out r, out angle); GL.Rotate((float)(angle * 180.0f / Math.PI), r); if (selected) { //DrawBoundingBox(array.Select(z => z.Position).Select(x => new BEPUutilities.Vector3(x.X, x.Y, x.Z)).ToArray()); } else { GL.Color3(255, 255, 255); } //GL.Scale(10,10,10); List <tkVector3> vv = new List <tkVector3>(); List <tkVector3> nv = new List <tkVector3>(); for (int i = 0; i < indeices.Count(); i += 3) { for (int j = 0; j < 3; j++) { vv.Add(array[indeices[i + j]].Position); nv.Add(array[indeices[i + j]].Normal); } } if (ctx.Solid) { GL.Color3(Color.Gray); GL.Begin(PrimitiveType.Triangles); GL.Disable(EnableCap.ColorMaterial); int index = 0; if (tag != null && tag is EntityTagInfo) { var info = tag as EntityTagInfo; if (info.UseOneColor) { GL.Color3(info.Color); } } for (int j = 0; j < vv.Count; j += 3) { index++; for (int i = 0; i < 3; i++) { var vector3 = vv[j + i]; var n3 = nv[j + i]; var v = vector3; GL.Normal3(n3.X, n3.Y, n3.Z); GL.Vertex3(v.X, v.Y, v.Z); } } GL.End(); } //triangl if (ctx.Wireframe) { GL.Disable(EnableCap.Lighting); GL.Enable(EnableCap.ColorMaterial); GL.LineWidth(ctx.WireframeLineWidth); for (int j = 0; j < vv.Count; j += 3) { GL.Color3(255, 0, 0); GL.Begin(PrimitiveType.LineLoop); for (int i = 0; i < 3; i++) { var vector3 = vv[j + i]; var n3 = nv[j + i]; var v = vector3; GL.Vertex3(v.X, v.Y, v.Z); } GL.End(); } } }