Beispiel #1
0
    Matrix4x4 CalculateTransform()
    {
        if (u == null)
        {
            transformDirty = false;
            return(Matrix4x4.identity);
        }
        var ud = u.GetDirectionInPlane(null).Eval().normalized;
        var vd = v.GetDirectionInPlane(null).Eval();
        var nd = Vector3.Cross(ud, vd).normalized;

        vd             = Vector3.Cross(nd, ud).normalized;
        transformDirty = false;
        return(UnityExt.Basis(ud, vd, nd, p.points.First().Eval()));
    }
Beispiel #2
0
    protected Matrix4x4 getPointsDistanceBasis(Vector3 app, Vector3 bpp, IPlane plane)
    {
        if (plane == null)
        {
            return(Matrix4x4.Translate((app + bpp) / 2f));
        }
        Vector3 z  = plane.n;
        Vector3 ap = plane.projectVectorInto(app);
        Vector3 bp = plane.projectVectorInto(bpp);
        Vector3 x  = normalize(bp - ap);
        Vector3 y  = normalize(Vector3.Cross(x, z));
        Vector3 p  = (ap + bp) * 0.5f;

        return(UnityExt.Basis(x, y, z, p));
    }
Beispiel #3
0
    protected Matrix4x4 getPointLineDistanceBasis(Vector3 lip0_, Vector3 lip1_, Vector3 ap_, IPlane plane)
    {
        Vector3 lip0 = lip0_;
        Vector3 lip1 = lip1_;
        Vector3 ap   = ap_;

        if (plane != null)
        {
            lip0 = plane.projectVectorInto(lip0);
            lip1 = plane.projectVectorInto(lip1);
            ap   = plane.projectVectorInto(ap);
        }

        Vector3 lid = normalize(lip1 - lip0);
        Vector3 bp  = lip0 + lid * Vector3.Dot(ap - lip0, lid);
        Vector3 x   = normalize(bp - ap);
        Vector3 y   = lid;
        Vector3 z   = normalize(Vector3.Cross(x, y));
        Vector3 p   = (ap + bp) * 0.5f;

        return(UnityExt.Basis(x, y, z, p));
    }
Beispiel #4
0
    protected void drawPointsDistance(Vector3 pp0, Vector3 pp1, LineCanvas renderer, Camera camera, bool label, bool arrow0 = true, bool arrow1 = true, int style = 0)
    {
        float pix = getPixelSize();

        Vector3 p0 = drawPointProjection(renderer, pp0, R_DASH * pix);
        Vector3 p1 = drawPointProjection(renderer, pp1, R_DASH * pix);

        Matrix4x4 basis;

        if (getPlane() == null)
        {
            Vector3 p = getLabelOffset();
            Vector3 x = normalize(p1 - p0);
            Vector3 y;
            y = p - projectPointLine(p, p0, p1);
            if (length(y) < EPSILON)
            {
                y = Vector3.Cross(camera.transform.forward, x);
            }
            y = normalize(y);
            Vector3 z = Vector3.Cross(x, y);
            basis = UnityExt.Basis(x, y, z, (p0 + p1) * 0.5f);
        }
        else
        {
            basis = getPointsDistanceBasis(p0, p1, getPlane());
        }

        Vector3 vx = basis.GetColumn(0);
        Vector3 vy = basis.GetColumn(1);
        Vector3 vp = basis.GetColumn(3);

        Vector3 label_offset = getLabelOffset();
        Vector3 offset       = Vector3.zero;

        offset.x = Vector3.Dot(label_offset - vp, vx);
        offset.y = Vector3.Dot(label_offset - vp, vy);

        // sgn label y
        float sy = ((offset.y > EPSILON) ? 1f : 0f) - ((offset.y < -EPSILON) ? 1f : 0f);

        offset.y = sy * Mathf.Max(15f * pix, Mathf.Abs(offset.y));

        // distance line points
        Vector3 lp0 = p0 + vy * offset.y;
        Vector3 lp1 = p1 + vy * offset.y;

        // vertical lines
        if (Mathf.Abs(sy) > EPSILON)
        {
            Vector3 salient = vy * 8f * pix * sy;
            if (style == 0)
            {
                renderer.DrawLine(p0, lp0 + salient);
                renderer.DrawLine(p1, lp1 + salient);
            }
            else
            {
                renderer.DrawLine(lp0 - salient, lp0 + salient);
                renderer.DrawLine(lp1 - salient, lp1 + salient);
            }
        }

        // distance line
        renderer.DrawLine(lp0, lp1);

        // sgn arrow x
        float sx = 1f;

        // half distance
        float half_dist = length(p0 - p1) * 0.5f;

        // if label ouside
        if (Mathf.Abs(offset.x) > half_dist)
        {
            sx = -1f;
        }

        // if label ourside distance area or sceren distance not too small, draw arrows
        if ((sx < 0f || length(lp0 - lp1) > (R_ARROW_W * 2f + 1f) * pix) && style != 1)
        {
            // arrow lp0
            if (arrow0)
            {
                renderer.DrawLine(lp0, lp0 - vy * R_ARROW_H * pix + vx * R_ARROW_W * pix * sx);
                renderer.DrawLine(lp0, lp0 + vy * R_ARROW_H * pix + vx * R_ARROW_W * pix * sx);
            }

            // arrow lp1
            if (arrow1)
            {
                renderer.DrawLine(lp1, lp1 - vy * R_ARROW_H * pix - vx * R_ARROW_W * pix * sx);
                renderer.DrawLine(lp1, lp1 + vy * R_ARROW_H * pix - vx * R_ARROW_W * pix * sx);
            }
        }
        else
        {
            // stroke lp0
            renderer.DrawLine(lp0 - vy * R_ARROW_H * pix + vx * R_ARROW_H * pix, lp0 + vy * R_ARROW_H * pix - vx * R_ARROW_H * pix);

            // stroke lp1
            renderer.DrawLine(lp1 - vy * R_ARROW_H * pix + vx * R_ARROW_H * pix, lp1 + vy * R_ARROW_H * pix - vx * R_ARROW_H * pix);
        }

        Vector3 lv0 = lp0;
        Vector3 lv1 = lp1;
        bool    da1 = arrow1;

        // if label lays from other side
        if (offset.x > half_dist)
        {
            lv0 = lp1;
            lv1 = lp0;
            da1 = arrow0;
        }

        // if label is ouside
        if (Mathf.Abs(offset.x) > half_dist)
        {
            Vector3 dir = vp + vy * offset.y + vx * offset.x - lv0;
            float   len = Mathf.Max(length(dir), 21f * pix);

            // line to the label
            renderer.DrawLine(lv0, lv0 + normalize(dir) * len);

            // opposite arrow line
            if (da1)
            {
                renderer.DrawLine(lv1, lv1 - normalize(dir) * 21f * pix);
            }
            setRefPoint(lv0 + normalize(dir) * (len + 16f * pix));
        }
        else
        {
            setRefPoint(basis.MultiplyPoint(offset) + vy * sy * 13f * pix);
        }

        //drawCameraCircle(renderer, camera, getLabelOffset(), 3f * pix);
        //if(label) drawLabel(renderer, camera);
    }