コード例 #1
0
ファイル: Objects.cs プロジェクト: iulian204/HedgeLib
 public static VPObjectInstance AddObjectInstance(string modelName,
                                                  OpenTK.Vector3 pos, OpenTK.Quaternion rot, OpenTK.Vector3 scale,
                                                  object customData = null)
 {
     return(AddObjectInstance(modelName, new VPObjectInstance(
                                  pos, rot, scale, customData)));
 }
コード例 #2
0
        public override Blocks GenerateBlock2(Vector2i position, Heights macroHeight)
        {
            var rotatedPos = Vector2.Transform((Vector2)position, Quaternion.FromEulerAngles(0, 0, _hillsOrientation));

            return(new Blocks(BlockType.Sand, BlockType.GoldOre,
                              new Heights((float)(_dunesNoise.GetSimplex(rotatedPos.X / 10f, rotatedPos.Y / 30f)) * 2 + macroHeight.Main, macroHeight.Underground, macroHeight.Base))); //Вытянутые дюны
        }
コード例 #3
0
ファイル: Objects.cs プロジェクト: iulian204/HedgeLib
 public static VPObjectInstance AddObjectInstance(VPModel obj,
                                                  OpenTK.Vector3 pos, OpenTK.Quaternion rot, OpenTK.Vector3 scale,
                                                  object customData = null)
 {
     return(AddObjectInstance(obj, new VPObjectInstance(
                                  pos, rot, scale, customData)));
 }
コード例 #4
0
 public unsafe static void SetMotorTarget(this ConeTwistConstraint obj, ref OpenTK.Quaternion q)
 {
     fixed(OpenTK.Quaternion *qPtr = &q)
     {
         obj.SetMotorTarget(ref *(BulletSharp.Math.Quaternion *)qPtr);
     }
 }
コード例 #5
0
 public unsafe static void SetMotorTarget(this HingeConstraint obj, ref OpenTK.Quaternion qAinB, float dt)
 {
     fixed(OpenTK.Quaternion *qAinBPtr = &qAinB)
     {
         obj.SetMotorTarget(ref *(BulletSharp.Math.Quaternion *)qAinBPtr, dt);
     }
 }
コード例 #6
0
        public static OpenTK.Vector3 QuaternionToEuler(OpenTK.Quaternion q1)
        {
            float sqw  = q1.W * q1.W;
            float sqx  = q1.X * q1.X;
            float sqy  = q1.Y * q1.Y;
            float sqz  = q1.Z * q1.Z;
            float unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
            float test = q1.X * q1.W - q1.Y * q1.Z;

            OpenTK.Vector3 v;



            if (test > 0.4995f * unit)
            { // singularity at north pole
                v.Y = 2f * (float)System.Math.Atan2(q1.X, q1.Y);
                v.X = (float)System.Math.PI / 2;
                v.Z = 0;
                return(NormalizeAngles(v * Rad2Deg));
            }
            if (test < -0.4995f * unit)
            { // singularity at south pole
                v.Y = -2f * (float)System.Math.Atan2(q1.Y, q1.X);
                v.X = (float)-System.Math.PI / 2;
                v.Z = 0;
                return(NormalizeAngles(v * Rad2Deg));
            }
            Quaternion q = new Quaternion(q1.W, q1.Z, q1.X, q1.Y);

            v.Y = (float)Math.Atan2(2f * q.X * q.W + 2f * q.Y * q.Z, 1 - 2f * (q.Z * q.Z + q.W * q.W)); // Yaw
            v.X = (float)Math.Asin(2f * (q.X * q.Z - q.W * q.Y));                                       // Pitch
            v.Z = (float)Math.Atan2(2f * q.X * q.Y + 2f * q.Z * q.W, 1 - 2f * (q.Y * q.Y + q.Z * q.Z)); // Roll
            return(NormalizeAngles(v * Rad2Deg));
        }
コード例 #7
0
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.Position    = binaryReader.ReadVector3();
     this.Orientation = binaryReader.ReadQuaternion();
     return(pointerQueue);
 }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="time"></param>
        /// <param name="quatA"></param>
        /// <param name="quatB"></param>
        /// <param name="useShortestPath"></param>
        /// <returns></returns>
        public static OpenTK.Quaternion Slerp(Real time, OpenTK.Quaternion quatA, OpenTK.Quaternion quatB, bool useShortestPath)
        {
            Real cos = quatA.Dot(quatB);

            Real angle = (Real)Utility.ACos(cos);

            if (Utility.Abs(angle) < EPSILON)
            {
                return(quatA);
            }

            Real sin        = Utility.Sin(angle);
            Real inverseSin = 1.0f / sin;
            Real coeff0     = Utility.Sin((1.0f - time) * angle) * inverseSin;
            Real coeff1     = Utility.Sin(time * angle) * inverseSin;

            OpenTK.Quaternion result;

            if (cos < 0.0f && useShortestPath)
            {
                coeff0 = -coeff0;
                // taking the complement requires renormalisation
                OpenTK.Quaternion t = coeff0 * quatA + coeff1 * quatB;
                t.Normalize();
                result = t;
            }
            else
            {
                result = (coeff0 * quatA + coeff1 * quatB);
            }

            return(result);
        }
コード例 #9
0
 public unsafe static void GetOrientation(this RigidBody obj, out OpenTK.Quaternion value)
 {
     fixed(OpenTK.Quaternion *valuePtr = &value)
     {
         *(BulletSharp.Math.Quaternion *)valuePtr = obj.Orientation;
     }
 }
コード例 #10
0
        /// <summary>
        /// Draws the twist constraints accoriding in Unity using Giszmos
        /// </summary>
        /// <param name="b">The bone with its constraints</param>
        /// <param name="refBone">The to be twisted against</param>
        /// <param name="poss">The position of where it should be drawn</param>
        /// <param name="scale">The scale of the constraints</param>
        public static void DrawTwistConstraints(Bone b, Bone refBone, OpenTK.Vector3 poss, float scale)
        {
            if (b.Orientation.Xyz.IsNaN() || refBone.Orientation.Xyz.IsNaN())
            {
                return;
            }
            OpenTK.Vector3 thisY = b.GetYAxis();

            OpenTK.Quaternion referenceRotation = refBone.Orientation * b.ParentPointer;
            OpenTK.Vector3    parentY           = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitY, referenceRotation);
            OpenTK.Vector3    parentZ           = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitZ, referenceRotation);

            OpenTK.Quaternion rot       = QuaternionHelper2.GetRotationBetween(parentY, thisY);
            OpenTK.Vector3    reference = OpenTK.Vector3.Transform(parentZ, rot);
            reference.Normalize();
            Debug.DrawRay(poss.Convert(), (b.GetZAxis() * scale * 2).Convert(), Color.cyan);


            float startTwistLimit = OpenTK.MathHelper.DegreesToRadians(b.StartTwistLimit);

            OpenTK.Vector3 m = OpenTK.Vector3.Transform(reference, OpenTK.Quaternion.FromAxisAngle(thisY, startTwistLimit));
            m.Normalize();
            Debug.DrawRay(poss.Convert(), m.Convert() * scale, Color.yellow);

            float endTwistLimit = OpenTK.MathHelper.DegreesToRadians(b.EndTwistLimit);

            OpenTK.Vector3 m2 = OpenTK.Vector3.Transform(reference, OpenTK.Quaternion.FromAxisAngle(thisY, endTwistLimit));
            m2.Normalize();
            Debug.DrawRay(poss.Convert(), m2.Convert() * scale, Color.magenta);

            Debug.DrawLine((poss + (m * scale)).Convert(), (poss + (m2 * scale)).Convert(), Color.cyan);
        }
コード例 #11
0
ファイル: Extensions.cs プロジェクト: clashbyte/openvice
		/// <summary>
		/// Read ZY-YZ reversed quaternion<para/>
		/// Чтение перевернутого ZY-YZ кватерниона
		/// </summary>
		/// <returns>Correct quaternion<para/>Исправленный кватернион</returns>
		public static OpenTK.Quaternion ReadVCQuaternion(this BinaryReader f) {
			OpenTK.Quaternion q = new OpenTK.Quaternion();
			q.X = -f.ReadSingle();
			q.Z = -f.ReadSingle();
			q.Y = -f.ReadSingle();
			q.W = -f.ReadSingle();
			return q;
		}
コード例 #12
0
ファイル: Extensions.cs プロジェクト: xWhitey/openvice
 /// <summary>
 /// Read ZY-YZ reversed quaternion<para/>
 /// Чтение перевернутого ZY-YZ кватерниона
 /// </summary>
 /// <returns>Correct quaternion<para/>Исправленный кватернион</returns>
 public static OpenTK.Quaternion ReadVCQuaternion(this BinaryReader f)
 {
     OpenTK.Quaternion q = new OpenTK.Quaternion();
     q.X = -f.ReadSingle();
     q.Z = -f.ReadSingle();
     q.Y = -f.ReadSingle();
     q.W = -f.ReadSingle();
     return(q);
 }
コード例 #13
0
 /// <summary>
 /// Using Unity Debug, draws the x,y,z axis of a Quaternion as x red, y green and z blue
 /// </summary>
 /// <param name="rot">The OpenTK Quaterion</param>
 /// <param name="pos">The UnityEngine Vector3 position to be drawn</param>
 /// <param name="scale">The float length of the axis in meter</param>
 public static void DrawRays(OpenTK.Quaternion rot, Vector3 pos, float scale)
 {
     OpenTK.Vector3 right   = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitX, rot);
     OpenTK.Vector3 up      = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitY, rot);
     OpenTK.Vector3 forward = OpenTK.Vector3.Transform(OpenTK.Vector3.UnitZ, rot);
     Debug.DrawRay(pos, up.Convert() * scale, Color.green);
     Debug.DrawRay(pos, right.Convert() * scale, Color.red);
     Debug.DrawRay(pos, forward.Convert() * scale, Color.blue);
 }
コード例 #14
0
ファイル: Enemy.cs プロジェクト: laetemn/BooldozerCore
        public override void Load(jmp data, int entryIndex)
        {
            base.Load(data, entryIndex);

            Position = new OpenTK.Vector3(posX, posY, posZ);
            Rotation = new OpenTK.Quaternion(new OpenTK.Vector3(rotX, rotY, rotZ));
            Scale    = new OpenTK.Vector3(scaleX, scaleY, scaleZ);

            HasRoomNumber = true;
        }
コード例 #15
0
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.NodeName           = binaryReader.ReadStringID();
     this.DefaultRotation    = binaryReader.ReadQuaternion();
     this.DefaultTranslation = binaryReader.ReadVector3();
     this.DefaultScale       = binaryReader.ReadSingle();
     this.MinBounds          = binaryReader.ReadVector3();
     this.MaxBounds          = binaryReader.ReadVector3();
     return(pointerQueue);
 }
コード例 #16
0
        /// <summary>
        ///		Performs spherical quadratic interpolation.
        /// </summary>
        /// <param name="t"></param>
        /// <param name="p"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="q"></param>
        /// <returns></returns>
        public static OpenTK.Quaternion Squad(Real t, OpenTK.Quaternion p, OpenTK.Quaternion a, OpenTK.Quaternion b, OpenTK.Quaternion q, bool useShortestPath)
        {
            Real slerpT = 2.0f * t * (1.0f - t);

            // use spherical linear interpolation
            OpenTK.Quaternion slerpP = Slerp(t, p, q, useShortestPath);
            OpenTK.Quaternion slerpQ = Slerp(t, a, b);

            // run another Slerp on the results of the first 2, and return the results
            return(Slerp(slerpT, slerpP, slerpQ));
        }
コード例 #17
0
        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();
        }
コード例 #18
0
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.RegionIndex      = binaryReader.ReadByte();
     this.PermutationIndex = binaryReader.ReadByte();
     this.NodeIndex        = binaryReader.ReadByte();
     this.fieldpad         = binaryReader.ReadBytes(1);
     this.Translation      = binaryReader.ReadVector3();
     this.Rotation         = binaryReader.ReadQuaternion();
     this.Scale            = binaryReader.ReadSingle();
     return(pointerQueue);
 }
コード例 #19
0
 /// <summary>
 /// Returns the integer associated with the dominant axis about which the rotation moves.
 /// Chooses Z in the two degenerate cases.
 /// x = 0
 /// y = 1
 /// z = 2
 /// Doesn't work.
 /// </summary>
 /// <param name="M">The affine matrix with some rotational componenet to analyse.</param>
 /// <returns></returns>
 public static int getDominantRotationAxis(OpenTK.Matrix4 M)
 {
     OpenTK.Quaternion R = M.ExtractRotation();
     if (System.Math.Abs(R.X) > System.Math.Abs(R.Y) && System.Math.Abs(R.X) > System.Math.Abs(R.Z))
     {
         return(0);
     }
     else if (System.Math.Abs(R.Y) > System.Math.Abs(R.Z))
     {
         return(1);
     }
     return(2);
 }
コード例 #20
0
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.Name               = binaryReader.ReadString32();
     this.Rotation           = binaryReader.ReadQuaternion();
     this.Translation        = binaryReader.ReadVector3();
     this.PaletteIndex       = binaryReader.ReadShortBlockIndex1();
     this.fieldpad           = binaryReader.ReadBytes(2);
     this.UniqueID           = binaryReader.ReadInt32();
     this.ExportedObjectType = binaryReader.ReadTagClass();
     this.ScenarioObjectName = binaryReader.ReadString32();
     return(pointerQueue);
 }
コード例 #21
0
        // http://bugzilla.xamarin.com/show_bug.cgi?id=1415
        // not really part of the bug - but part of the same fix
        public void Bug1415_Linker_XmlAttribute()
        {
            // the typeof ensure we're can't (totally) link away System.ServiceModel.dll
            Type ed = typeof(System.ServiceModel.AuditLevel).Assembly.GetType("System.ServiceModel.EndpointAddress10", false);

            // type is decorated with both [XmlSchemaProvider] and [XmlRoot]
            Assert.NotNull(ed, "EndpointAddress10");

            var q = new OpenTK.Quaternion();

            Assert.Null(q.GetType().GetProperty("XYZ"), "XmlIgnore");
            // should be null if application is linked (won't be if "Don't link" is used)
        }
コード例 #22
0
        // http://bugzilla.xamarin.com/show_bug.cgi?id=1415
        // not really part of the bug - but part of the same fix
        public void Bug1415_Linker_XmlAttribute()
        {
            // the typeof ensure we're can't (totally) link away System.ServiceModel.dll
            Type ed = typeof(System.ServiceModel.AuditLevel).Assembly.GetType("System.ServiceModel.EndpointAddress10", false);

            // type is decorated with both [XmlSchemaProvider] and [XmlRoot]
            Assert.NotNull(ed, "EndpointAddress10");

#if !__WATCHOS__ // FIXME: this needs to use a different type than OpenTK.Quaternion, so that the test can run on WatchOS as wells
            var q = new OpenTK.Quaternion();
            Assert.Null(q.GetType().GetProperty("XYZ"), "XmlIgnore");
            // should be null if application is linked (won't be if "Don't link" is used)
#endif // !__WATCHOS__
        }
コード例 #23
0
ファイル: Maths.cs プロジェクト: brentonhauth/AnarchyEngine
        // !Restructure
        public static OpenTK.Quaternion RotateTowards(OpenTK.Vector3 u, OpenTK.Vector3 v)
        {
            var q = new OpenTK.Quaternion {
                Xyz = Vector3.Cross(u, v)
            };

            var dot = Vector3.Dot(u, v);

            var w = Sqrt(u.LengthSquared * v.LengthSquared);

            q.W = w + dot;


            return(q);
        }
コード例 #24
0
        /// <param name="shortestPath"></param>
        public static OpenTK.Quaternion Nlerp(Real fT, OpenTK.Quaternion rkP, OpenTK.Quaternion rkQ, bool shortestPath)
        {
            OpenTK.Quaternion result;
            Real fCos = rkP.Dot(rkQ);

            if (fCos < 0.0f && shortestPath)
            {
                result = rkP + fT * ((OpenTK.Quaternion.Invert(rkQ)) - rkP);
            }
            else
            {
                result = rkP + fT * (rkQ - rkP);
            }
            result.Normalize();
            return(result);
        }
コード例 #25
0
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.Name                   = binaryReader.ReadStringID();
     this.ParentNode             = binaryReader.ReadShortBlockIndex1();
     this.FirstChildNode         = binaryReader.ReadShortBlockIndex1();
     this.NextSiblingNode        = binaryReader.ReadShortBlockIndex1();
     this.fieldpad               = binaryReader.ReadBytes(2);
     this.DefaultTranslation     = binaryReader.ReadVector3();
     this.DefaultRotation        = binaryReader.ReadQuaternion();
     this.DefaultInverseScale    = binaryReader.ReadSingle();
     this.DefaultInverseForward  = binaryReader.ReadVector3();
     this.DefaultInverseLeft     = binaryReader.ReadVector3();
     this.DefaultInverseUp       = binaryReader.ReadVector3();
     this.DefaultInversePosition = binaryReader.ReadVector3();
     return(pointerQueue);
 }
コード例 #26
0
        public void TestMathProperties()
        {
            AssertEqual(TestReadableVector2D, new OpenTK.Vector2(2.0f, 2.0f), "TestReadableVector2D");
            AssertEqual(TestReadableVector, new OpenTK.Vector3(4.0f, 8.0f, 15.0f), "TestReadableVector");
            AssertEqual(TestReadableVector4, new OpenTK.Vector4(16.0f, 23.0f, 42.0f, 108.0f), "TestReadableVector4");

            AssertEqual(TestReadWriteQuat, new OpenTK.Quaternion(2, 4, 6, 0.1f), "TestReadWriteQuat");
            TestReadWriteQuat = new OpenTK.Quaternion(1, 2, 3, 4);

            AssertEqual(TestReadWriteMatrix, OpenTK.Matrix4.Identity, "TestReadWriteMatrix");
            TestReadWriteMatrix = new OpenTK.Matrix4(
                0, 1, 2, 3,
                4, 5, 6, 7,
                8, 9, 10, 11,
                12, 13, 14, 15);

            AssertEqual(TestReadableRotator, new Rotator(45.0f, 15.0f, 5.0f), "TestReadableRotator");
        }
コード例 #27
0
ファイル: MotionsToolForm.cs プロジェクト: NCC-Lykos/Chisel
        private IUnitTransformation ResetTransform()
        {
            var mov = Matrix.Translation(-_document.Selection.GetSelectionBoundingBox().Center);
            

            OpenTK.Quaternion rev = new OpenTK.Quaternion((float)PrevRotation.X,
                                                          (float)PrevRotation.Y,
                                                          (float)PrevRotation.Z,
                                                          (float)PrevRotation.W);
            rev.Invert();
            var q = new DataStructures.Geometric.Quaternion(0, 0, 0, -1);
            var rot = Matrix.Rotation(q);
            var fin = Matrix.Translation(SolidsOrigin);
            PrevRotation = new DataStructures.Geometric.Quaternion((decimal)rev.X, (decimal)rev.Y,
                                                                   (decimal)rev.Z, (decimal)rev.W);
            var prev = Matrix.Rotation(PrevRotation);
            PrevRotation = q;
            return new UnitMatrixMult(fin * (rot * prev) * mov);
        }
コード例 #28
0
        public void UpdateGizmoTransform()
        {
            OpenTK.Vector3    position      = OpenTK.Vector3.Zero;
            OpenTK.Quaternion localRotation = OpenTK.Quaternion.Identity;

            foreach (var entity in EditorSelection.SelectedObjects)
            {
                position += entity.Transform.Position;
            }

            if (EditorSelection.SelectedObjects.Count > 0)
            {
                position     /= EditorSelection.SelectedObjects.Count;
                localRotation = EditorSelection.SelectedObjects[0].Transform.LocalRotation;
            }

            TransformGizmo.SetPosition(position);
            TransformGizmo.SetLocalRotation(localRotation);
        }
コード例 #29
0
ファイル: ARGUI.cs プロジェクト: erichocean/moveme
        private void SetupMatrices(int gem_num, float aspect_ratio)
        {
            const float yFov = 0.837758041f;           // 48 degrees vertical field-of-view
            const float near = 10, far = 3000;         // 50cm to 3m tracking limits (but reduce near to avoid object clipping)

            OpenTK.Matrix4 projection;
            projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView(yFov, aspect_ratio, near, far);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.LoadMatrix(ref projection);

            float cameraPitchAngle = AR_state.gemStates[gem_num].camera_pitch_angle;

            Console.WriteLine("{0}", cameraPitchAngle);

            OpenTK.Matrix4 rotation, scale, lookat;

            rotation = OpenTK.Matrix4.CreateRotationX(cameraPitchAngle);
            scale    = OpenTK.Matrix4.Scale(-1.0f, 1.0f, 1.0f);

            lookat = OpenTK.Matrix4.LookAt(0, 0, 0,
                                           0, 0, 1,
                                           0, 1, 0);
            OpenTK.Matrix4 view = lookat * (scale * rotation);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.LoadMatrix(ref view);
            OpenTK.Matrix4 mv_mat;
            GL.GetFloat(GetPName.ModelviewMatrix, out mv_mat);
            //Console.WriteLine("{0}", mv_mat);
            OpenTK.Vector3    gem_position = new OpenTK.Vector3(AR_state.gemStates[gem_num].pos.x, AR_state.gemStates[gem_num].pos.y, AR_state.gemStates[gem_num].pos.z);
            OpenTK.Quaternion gem_rotation = new OpenTK.Quaternion(AR_state.gemStates[gem_num].quat.x, AR_state.gemStates[gem_num].quat.y, AR_state.gemStates[gem_num].quat.z, AR_state.gemStates[gem_num].quat.w);
            gem_rotation.Normalize();
            OpenTK.Matrix4 gem_rotation_matrix    = OpenTK.Matrix4.Rotate(gem_rotation);
            OpenTK.Matrix4 gem_translation_matrix = OpenTK.Matrix4.CreateTranslation(gem_position);
            OpenTK.Matrix4 gem_model_matrix       = gem_rotation_matrix;
            gem_model_matrix.M41 = gem_position.X;
            gem_model_matrix.M42 = gem_position.Y;
            gem_model_matrix.M43 = gem_position.Z;
            gem_model_matrix.M44 = 1.0f;
            GL.MultMatrix(ref gem_model_matrix);
        }
コード例 #30
0
        private static GenericSkeleton ReadSkel(string path)
        {
            GenericSkeleton skel = new GenericSkeleton();

            using (DataReader r = new DataReader(path))
            {
                r.BigEndian = false;

                r.Seek(0x10);
                var count  = r.ReadInt16();
                var count2 = r.ReadInt16();
                var count3 = r.ReadInt32();

                var boneInfoOffset       = r.Position + r.ReadUInt32();
                var boneParentInfoOffset = r.Position + r.ReadUInt32();
                var hashOffset           = r.Position + r.ReadUInt32();
                // various hash table offsets

                for (uint i = 0; i < count; i++)
                {
                    GenericBone b = new GenericBone();

                    r.Seek(boneInfoOffset + 48 * i);
                    var rot = new OpenTK.Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle()).Inverted();
                    rot.Normalize();
                    b.QuaternionRotation = rot;
                    b.Position           = new OpenTK.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                    r.ReadSingle();
                    b.Scale = new OpenTK.Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                    r.ReadSingle();

                    r.Seek(boneParentInfoOffset + 2 * i);
                    b.ParentIndex = r.ReadInt16();

                    r.Seek(hashOffset + 4 * i);
                    b.Name = "B_" + r.ReadInt32().ToString("X8");

                    skel.Bones.Add(b);
                }
            }
            return(skel);
        }
コード例 #31
0
ファイル: MotionsToolForm.cs プロジェクト: NCC-Lykos/Chisel
        private IUnitTransformation KeyFrameTransform()
        {
            var mov = Matrix.Translation(-_document.Selection.GetSelectionBoundingBox().Center); // Move to zero
            OpenTK.Quaternion rev = new OpenTK.Quaternion((float)PrevRotation.X, 
                                                          (float)PrevRotation.Y,
                                                          (float)PrevRotation.Z,
                                                          (float)PrevRotation.W);
            rev.Invert();
            PrevRotation = new Quaternion((decimal)rev.X, (decimal)rev.Y,
                                                                   (decimal)rev.Z, (decimal)rev.W);
            var prev = Matrix.Rotation(PrevRotation);

            Quaternion q = GetKeyframeRot();
            
            var rot = Matrix.Rotation(q); // Do rotation
            var fin = Matrix.Translation(SolidsOrigin + GetKeyframeMov()); // Move to final origin
            
            PrevRotation = q;
            return new UnitMatrixMult(fin * (rot * prev) * mov);
        }
コード例 #32
0
ファイル: ARGUI.cs プロジェクト: kumarsmurthy/moveme
        private void SetupMatrices(int gem_num, float aspect_ratio)
        {
            const float yFov = 0.837758041f;                 // 48 degrees vertical field-of-view
            const float near = 10, far = 3000;         // 50cm to 3m tracking limits (but reduce near to avoid object clipping)

            OpenTK.Matrix4 projection;
            projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView(yFov, aspect_ratio, near, far);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.LoadMatrix(ref projection);

            float cameraPitchAngle = AR_state.gemStates[gem_num].camera_pitch_angle;

            Console.WriteLine("{0}", cameraPitchAngle);

            OpenTK.Matrix4 rotation, scale, lookat;

            rotation = OpenTK.Matrix4.CreateRotationX(cameraPitchAngle);
            scale = OpenTK.Matrix4.Scale(-1.0f, 1.0f, 1.0f);

            lookat = OpenTK.Matrix4.LookAt(0, 0, 0,
                                           0, 0, 1,
                                           0, 1, 0);
            OpenTK.Matrix4 view = lookat * (scale * rotation);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.LoadMatrix(ref view);
            OpenTK.Matrix4 mv_mat;
            GL.GetFloat(GetPName.ModelviewMatrix, out mv_mat);
            //Console.WriteLine("{0}", mv_mat);
            OpenTK.Vector3 gem_position = new OpenTK.Vector3(AR_state.gemStates[gem_num].pos.x, AR_state.gemStates[gem_num].pos.y, AR_state.gemStates[gem_num].pos.z);
            OpenTK.Quaternion gem_rotation = new OpenTK.Quaternion(AR_state.gemStates[gem_num].quat.x, AR_state.gemStates[gem_num].quat.y, AR_state.gemStates[gem_num].quat.z, AR_state.gemStates[gem_num].quat.w);
            gem_rotation.Normalize();
            OpenTK.Matrix4 gem_rotation_matrix = OpenTK.Matrix4.Rotate(gem_rotation);
            OpenTK.Matrix4 gem_translation_matrix = OpenTK.Matrix4.CreateTranslation(gem_position);
            OpenTK.Matrix4 gem_model_matrix = gem_rotation_matrix;
            gem_model_matrix.M41 = gem_position.X;
            gem_model_matrix.M42 = gem_position.Y;
            gem_model_matrix.M43 = gem_position.Z;
            gem_model_matrix.M44 = 1.0f;
            GL.MultMatrix(ref gem_model_matrix);
        }
コード例 #33
0
		// http://bugzilla.xamarin.com/show_bug.cgi?id=1415
		// not really part of the bug - but part of the same fix
		public void Bug1415_Linker_XmlAttribute ()
		{
			// the typeof ensure we're can't (totally) link away System.ServiceModel.dll
			Type ed = typeof (System.ServiceModel.AuditLevel).Assembly.GetType ("System.ServiceModel.EndpointAddress10", false);
			// type is decorated with both [XmlSchemaProvider] and [XmlRoot]
			Assert.NotNull (ed, "EndpointAddress10");
			
			var q = new OpenTK.Quaternion ();
			Assert.Null (q.GetType ().GetProperty ("XYZ"), "XmlIgnore");
			// should be null if application is linked (won't be if "Don't link" is used)
		}