protected override void OnRotationChanged(Quaternion rotation) { if (m_physicsMesh != null) { Owner.MarkStaticColliderDirty(); } }
private void SetTransform(float a, float b, float c, float d) { if (listBox1.SelectedIndex == -1) { return; } lock (_Frame) { var q = new SharpDX.Quaternion(a, b, c, d); q.Normalize(); _Frame.Transforms[listBox1.SelectedIndex].Rotation = q; } }
public void TrackData(float t, SharpDX.Quaternion quaternion, byte fov) { //double rad2deg = 180 / Math.PI; var v = GraphicTools.QuaternionToYawPitch(quaternion); // angle from quaternion should be always [-4PI, 4PI], no need for while loop double yaw = (Math.PI * 9 + v.X) % (2 * Math.PI) - Math.PI; // => [-PI, +PI] double pitch = -v.Y; // => [-PI/2, PI/2] double yaw01 = yaw / (2 * Math.PI) + 0.5; double pitch01 = pitch / Math.PI + 0.5; TrackData(t, yaw01, pitch01, fov); Bivrost.Log.LoggerManager.Publish("history.t", t); Bivrost.Log.LoggerManager.Publish("history.yaw", yaw * 180f / Math.PI); Bivrost.Log.LoggerManager.Publish("history.pitch", pitch * 180f / Math.PI); Bivrost.Log.LoggerManager.Publish("history.yaw01", yaw01); Bivrost.Log.LoggerManager.Publish("history.pitch01", pitch01); }
public static SharpDX.Vector3 ToEulerAngles(this SharpDX.Quaternion q) { //https://github.com/mrdoob/three.js/blob/dev/src/math/Euler.js //Due to the issue mentioned in EulerToQuaternion, X and Z are negated to compensate. var matrix = SharpDX.Matrix.RotationQuaternion(q); var result = new SharpDX.Vector3(); result.Y = (float)Math.Asin(-Clamp(matrix.M31, -1, 1)); if (Math.Abs(matrix.M31) < 0.9999999) { result.X = -(float)Math.Atan2(matrix.M21, matrix.M11); result.Z = -(float)Math.Atan2(matrix.M32, matrix.M33); } else { result.X = -(float)Math.Atan2(-matrix.M12, matrix.M22); result.Z = 0f; } return(result); }
/// <summary> /// Matrix を、拡大ベクトル・回転行列・平行移動ベクトルに分解する。 /// </summary> /// <remarks> /// 参考: 「その39 知っていると便利?ワールド変換行列から情報を抜き出そう」 /// http://marupeke296.com/DXG_No39_WorldMatrixInformation.html /// </remarks> public static void ToScaleRotationTranslation(this SharpDX.Matrix matrix, out SharpDX.Vector3 scale, out SharpDX.Quaternion rotation, out SharpDX.Vector3 translation) { scale = new SharpDX.Vector3( new SharpDX.Vector3(matrix.M11, matrix.M12, matrix.M13).Length(), new SharpDX.Vector3(matrix.M21, matrix.M22, matrix.M23).Length(), new SharpDX.Vector3(matrix.M31, matrix.M32, matrix.M33).Length()); translation = new SharpDX.Vector3(matrix.M41, matrix.M42, matrix.M43); // matrix を構成する scale と translation が定まれば、rotation も定まる。 // ※参考ページ中段の「WorldMatrix = S・Rx・Ry・Rz・T = ...」の図を参照のこと。 rotation = SharpDX.Quaternion.RotationMatrix( new SharpDX.Matrix { Row1 = (scale.X == 0f) ? SharpDX.Vector4.Zero : new SharpDX.Vector4(matrix.M11 / scale.X, matrix.M12 / scale.X, matrix.M13 / scale.X, 0f), Row2 = (scale.Y == 0f) ? SharpDX.Vector4.Zero : new SharpDX.Vector4(matrix.M21 / scale.Y, matrix.M22 / scale.Y, matrix.M23 / scale.Y, 0f), Row3 = (scale.Z == 0f) ? SharpDX.Vector4.Zero : new SharpDX.Vector4(matrix.M31 / scale.Z, matrix.M32 / scale.Z, matrix.M33 / scale.Z, 0f), Row4 = new SharpDX.Vector4(0f, 0f, 0f, 1f), }); }
protected void ParseDataObjectAnimationKey(AnimBone animBone) { ReadHeadOfDataObject(); // read key type uint keyType = ReadInt(); // read number of keys uint numKeys = ReadInt(); for (uint a = 0; a < numKeys; a++) { // read time uint time = ReadInt(); // read keys switch (keyType) { case 0: { if (ReadInt() != 4) ThrowException("Invalid number of arguments for quaternion key in animation"); var keyValue = new Quaternion(); keyValue.W = ReadFloat(); keyValue.X = ReadFloat(); keyValue.Y = ReadFloat(); keyValue.Z = ReadFloat(); QuatKey key = new QuatKey((double)time, keyValue); animBone.RotKeys.Add(key); CheckForSemicolon(); break; } case 1: // scale vector case 2: // position vector { // read count if (ReadInt() != 3) { ThrowException("Invalid number of arguments for vector key in animation"); } VectorKey key = new VectorKey((double)time, ReadVector3()); if (keyType == 2) { animBone.PosKeys.Add(key); } else { animBone.ScaleKeys.Add(key); } break; } case 3: case 4: { // read count if (ReadInt() != 16) ThrowException("Invalid number of arguments for matrix key in animation"); // read matrix double key = (double)time; Matrix4x4 value = new Matrix4x4(); value.M11 = ReadFloat(); value.M21 = ReadFloat(); value.M31 = ReadFloat(); value.M41 = ReadFloat(); value.M12 = ReadFloat(); value.M22 = ReadFloat(); value.M32 = ReadFloat(); value.M42 = ReadFloat(); value.M13 = ReadFloat(); value.M23 = ReadFloat(); value.M33 = ReadFloat(); value.M43 = ReadFloat(); value.M14 = ReadFloat(); value.M24 = ReadFloat(); value.M34 = ReadFloat(); value.M44 = ReadFloat(); animBone.TrafoKeys.Add(new MatrixKey(key, value)); CheckForSemicolon(); break; } default: ThrowException(string.Format("Unknown key type {0} in animation.", keyType)); break; } CheckForSeparator(); } CheckForClosingBrace(); }
//Stopwatch hpls = new Stopwatch(); private void HandleProvideLook(SharpDX.Vector3 position, SharpDX.Quaternion rotation, float fov) { history?.TrackData((float)MediaTime, rotation, (byte)fov); //Info($"{hpls.ElapsedMilliseconds:0000} {_lastMediaTime:000.0000} + {_mediaTimeDelta.Elapsed.TotalSeconds:000.0000} = {_lastMediaTime + _mediaTimeDelta.Elapsed.TotalSeconds:000.0000}"); //hpls.Restart(); }
private GTA.Quaternion fromSharpDX(SharpDX.Quaternion v) { return(new GTA.Quaternion(v.X, v.Y, v.Z, v.W)); }
public static RealVector4D ToRealVector4D(this SharpDX.Quaternion q) => new RealVector4D(q.X, q.Y, q.Z, q.W);