Exemple #1
0
        public emVector3 quatRotate(emQuaternion rotation, emVector3 v)
        {
            emQuaternion q = rotation * v;

            q = q * rotation.inverse();
            return(new emVector3(q.x, q.y, q.z));
        }
Exemple #2
0
        public override void finalize(WalkEnding end, ulong _time)
        {
            switch (end)
            {
            case WalkEnding.Identity:
                break;

            case WalkEnding.TargetParentOfSource:
                result_vec  = source_to_top_vec;
                result_quat = source_to_top_quat;
                break;

            case WalkEnding.SourceParentOfTarget:
            {
                emQuaternion inv_target_quat = target_to_top_quat.inverse();
                emVector3    inv_target_vec  = quatRotate(inv_target_quat, -1 * target_to_top_vec);
                result_quat = inv_target_quat;
                result_vec  = inv_target_vec;
            }
            break;

            case WalkEnding.FullPath:
            {
                emQuaternion inv_target_quat = target_to_top_quat.inverse();
                emVector3    inv_target_vec  = quatRotate(inv_target_quat, new emVector3(-target_to_top_vec.x, -target_to_top_vec.y, -target_to_top_vec.z));
                result_vec  = quatRotate(inv_target_quat, source_to_top_vec) + inv_target_vec;
                result_quat = inv_target_quat * source_to_top_quat;
            }
            break;
            }
            time = _time;
        }
Exemple #3
0
 public TransformStorage(emTransform data, uint frame_id, uint child_frame_id)
 {
     rotation            = data.rotation;
     translation         = data.translation;
     stamp               = TimeCache.toLong(data.stamp.data);
     this.frame_id       = frame_id;
     this.child_frame_id = child_frame_id;
 }
Exemple #4
0
        public emTransform(emQuaternion q, emVector3 v, Time t, string fid, string cfi)
        {
            rotation    = q;
            translation = v;
            stamp       = t;

            frame_id       = fid;
            child_frame_id = cfi;
        }
Exemple #5
0
        public double angleShortestPath(emQuaternion q)
        {
            double s = Math.Sqrt(length2() * q.length2());

            if (dot(q) < 0)
            {
                return(Math.Acos(dot(-1 * q) / s) * 2.0);
            }
            return(Math.Acos(dot(q) / s) * 2.0);
        }
Exemple #6
0
        public void setRotation(emQuaternion q)
        {
            double d = q.length2();
            double s = 2.0 / d;
            double xs = q.x * s, ys = q.y * s, zs = q.z * s;
            double wx = q.w * xs, wy = q.w * ys, wz = q.w * zs;
            double xx = q.x * xs, xy = q.x * ys, xz = q.x * zs;
            double yy = q.y * ys, yz = q.y * zs, zz = q.z * zs;

            setValue(1.0 - (yy + zz), xy - wz, xz + wy,
                     xy + wz, 1.0 - (xx + zz), yz - wx,
                     xz - wy, yz + wx, 1.0 - (xx + yy));
        }
Exemple #7
0
 public override void accum(bool source)
 {
     if (source)
     {
         source_to_top_vec  = quatRotate(st.rotation, source_to_top_vec) + st.translation;
         source_to_top_quat = st.rotation * source_to_top_quat;
     }
     else
     {
         target_to_top_vec  = quatRotate(st.rotation, target_to_top_vec) + st.translation;
         target_to_top_quat = st.rotation * target_to_top_quat;
     }
 }
Exemple #8
0
        public emQuaternion slerp(emQuaternion q, double t)
        {
            double theta = angleShortestPath(q);

            if (theta != 0)
            {
                double d  = 1.0 / Math.Sin(theta);
                double s0 = Math.Sin(1.0 - t) * theta;
                double s1 = Math.Sin(t * theta);
                if (dot(q) < 0)
                {
                    return(new emQuaternion((x * s0 + -1 * q.x * s1) * d,
                                            (y * s0 + -1 * q.y * s1) * d,
                                            (z * s0 + -1 * q.z * s1) * d,
                                            (w * s0 + -1 * q.w * s1) * d));
                }
                return(new emQuaternion((x * s0 + q.x * s1) * d,
                                        (y * s0 + q.y * s1) * d,
                                        (z * s0 + q.z * s1) * d,
                                        (w * s0 + q.w * s1) * d));
            }
            return(new emQuaternion(this));
        }
Exemple #9
0
 public emMatrix3x3(emQuaternion q)
 {
     setRotation(q);
 }
Exemple #10
0
        public TransformStorage()
        {
            rotation = new emQuaternion();

            translation = new emVector3();
        }
Exemple #11
0
 private emQuaternion slerp(emQuaternion q1, emQuaternion q2, double rt)
 {
     return(q1.slerp(q2, rt));
 }
Exemple #12
0
 public double dot(emQuaternion q)
 {
     return(x * q.x + y * q.y + z * q.z + w * q.w);
 }
Exemple #13
0
 public emQuaternion(emQuaternion shallow) : this(shallow.x, shallow.y, shallow.z, shallow.w)
 {
 }