Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
 public void Rotate(float x, float y, float z)
 {
     Rotation *= OpenTK.Quaternion.FromEulerAngles(x, y, z);
     Rotation.Normalize();
 }