Beispiel #1
0
        public bool BeginCapture(MMDModel target, HitResult hit)
        {
            // save local and world frames
            rotateFrameL = target.GetGameObjectFrame(CoordSpace.ObjectCoords);
            rotateFrameW = target.GetGameObjectFrame(CoordSpace.WorldCoords);
            rotateAxisW  = rotateFrameW.GetAxis(nRotationAxis);

            // save angle of hitpos in 2D plane perp to rotateAxis, so we can find delta-angle later
            Vector3f vWorldHitPos = hit.HitPosition;
            Vector3f dv           = vWorldHitPos - rotateFrameW.Origin;
            int      iX           = (nRotationAxis + 1) % 3;
            int      iY           = (nRotationAxis + 2) % 3;
            float    fX           = Vector3f.Dot(dv, rotateFrameW.GetAxis(iX));
            float    fY           = Vector3f.Dot(dv, rotateFrameW.GetAxis(iY));

            fRotateStartAngle = (float)Math.Atan2(fY, fX);

            // construct plane we will ray-intersect with in UpdateCapture()
            raycastFrame = new Frame3f(vWorldHitPos, rotateAxisW);
            if (EnableSnapping)
            {
                //enable_circle_indicator(true);
            }

            return(true);
        }
        public static float AngleBetween(Vector3 a, Vector3 b)
        {
            // // Due to float error the dot / mag can sometimes be ever so slightly over 1, which can cause NaN in acos.
            //return Mathf.Acos(Vector3.Dot(a, b) / (a.magnitude * b.magnitude)) * MathUtil.RAD_TO_DEG;
            double d = (double)Vector3.Dot(a, b) / ((double)a.Length() * (double)b.Length());

            if (d >= 1d)
            {
                return(0f);
            }
            else if (d <= -1d)
            {
                return(180f); //why 180 and not -180??
            }
            return(MathUtil.RadiansToDegrees((float)System.Math.Acos(d)));
        }
Beispiel #3
0
        private void ProcessTranslationDrag()
        {
            if (m_activeAxis == EGizmoAxis.None)
            {
                return;
            }

            if (m_activeAxisList.Count <= 0)
            {
                return;
            }

            Ray pickRay = CreateMouseRay(in m_frameViewInfo);

            if (m_activeAxisList.Count > 1)
            {
                Vector3 planeNormal       = Vector3.Cross(m_activeAxisList[0], m_activeAxisList[1]);
                Plane   intersectionPlane = new Plane(m_startLocation, planeNormal);

                if (intersectionPlane.Intersects(ref pickRay, out Vector3 intersection))
                {
                    m_controlledTransform.SetWorldPosition(intersection - m_clickOffset);
                }
            }
            else
            {
                Vector3 planeTangent      = Vector3.Cross(m_activeAxisList[0], m_frameViewInfo.ViewLocation - m_gizmoLocation);
                Vector3 planeNormal       = Vector3.Cross(m_activeAxisList[0], planeTangent);
                Plane   intersectionPlane = new Plane(m_startLocation, planeNormal);

                if (intersectionPlane.Intersects(ref pickRay, out Vector3 intersection))
                {
                    intersection -= m_originalPosition + m_clickOffset;
                    m_controlledTransform.SetWorldPosition(m_originalPosition + m_activeAxisList[0] * Vector3.Dot(intersection, m_activeAxisList[0]));
                }
            }
        }