예제 #1
0
    public void PrimHandleUpdate(CVectorModel Model, ref SGizmoData Gizmo, int SelectedPrimID)
    {
        if (Gizmo.mGizmoHover != EGizmoHandleID.NONE)
        {
            return;
        }

        float   minT          = float.MaxValue;
        Vector3 planeHitPoint = Vector3.zero;
        int     hitPlaneID    = -1;
        bool    planeWasHit   = false;

        for (int i = 0; i < Model.mPlanes.Count; ++i)
        {
            CModelPlane p = Model.mPlanes[i];
            Vector3     hit;
            float       t;
            if (p.IntersectRay(Gizmo.mStartMouseRay, out hit, out t))
            {
                planeWasHit = true;
                if (t < minT)
                {
                    minT          = t;
                    planeHitPoint = hit;
                    hitPlaneID    = i;
                }
            }
        }

        if (planeWasHit)
        {
            Gizmo.mGizmoHover = EGizmoHandleID.PRIMTIVE;
            Gizmo.mHoverID    = hitPlaneID;
        }
    }
예제 #2
0
    public bool IntersectRay(Ray R, Matrix4x4 Transform, out float T)
    {
        T = float.MaxValue;
        Vector3 planeHitPoint = Vector3.zero;
        int     hitPlaneID    = -1;
        bool    hit           = false;

        Ray r = new Ray(Transform.MultiplyPoint(R.origin), Transform.MultiplyVector(R.direction));

        for (int i = 0; i < mPlanes.Count; ++i)
        {
            CModelPlane p = mPlanes[i];
            Vector3     hitPos;
            float       t;
            if (p.IntersectRay(r, out hitPos, out t))
            {
                if (t < T)
                {
                    hit           = true;
                    T             = t;
                    planeHitPoint = hitPos;
                    hitPlaneID    = i;
                }
            }
        }

        return(hit);
    }
예제 #3
0
    public void EdgePaintHandleUpdate(CVectorModel Model, ref SGizmoData Gizmo)
    {
        if (Gizmo.mGizmoHover != EGizmoHandleID.NONE)
        {
            return;
        }

        float   minT          = float.MaxValue;
        Vector3 planeHitPoint = Vector3.zero;
        int     hitPlaneID    = -1;
        bool    planeWasHit   = false;

        for (int i = 0; i < Model.mPlanes.Count; ++i)
        {
            CModelPlane p = Model.mPlanes[i];
            Vector3     hit;
            float       t;
            if (p.IntersectRay(Gizmo.mStartMouseRay, out hit, out t))
            {
                planeWasHit = true;
                if (t < minT)
                {
                    minT          = t;
                    planeHitPoint = hit;
                    hitPlaneID    = i;
                }
            }
        }

        if (planeWasHit)
        {
            CModelPlane p = Model.mPlanes[hitPlaneID];

            // Find closest impact point on plane
            Vector3 projPoint;
            float   d1 = CIntersections.PointVsLine(planeHitPoint, p.c1, p.c2, out projPoint);
            float   d2 = CIntersections.PointVsLine(planeHitPoint, p.c2, p.c3, out projPoint);
            float   d3 = CIntersections.PointVsLine(planeHitPoint, p.c3, p.c4, out projPoint);
            float   d4 = CIntersections.PointVsLine(planeHitPoint, p.c4, p.c1, out projPoint);

            //CDebug.DrawLine(planeHitPoint, planeHitPoint + new Vector3(0, 0.1f, 0), Color.yellow, false);
            //CDebug.DrawLine(projPoint, projPoint + new Vector3(0, 0.1f, 0), Color.magenta, false);

            Gizmo.mGizmoHover = EGizmoHandleID.EDGE;
            Gizmo.mHoverID    = hitPlaneID;

            if (d4 < d2 && d4 < d3 && d4 < d1)
            {
                Gizmo.mCornerID = 3;
                CDebug.DrawLine(p.c4, p.c1, Color.blue, false);
            }
            else if (d2 < d1 && d2 < d3 && d2 < d4)
            {
                Gizmo.mCornerID = 1;
                CDebug.DrawLine(p.c2, p.c3, Color.blue, false);
            }
            else if (d3 < d2 && d3 < d1 && d3 < d4)
            {
                Gizmo.mCornerID = 2;
                CDebug.DrawLine(p.c3, p.c4, Color.blue, false);
            }
            else
            {
                Gizmo.mCornerID = 0;
                CDebug.DrawLine(p.c1, p.c2, Color.blue, false);
            }
        }
    }