コード例 #1
0
        private List <JSIAppPolyline3D> createLocalPtCurve3Ds(
            List <JSIAppPolyline3D> ptCurve3Ds, Vector3 cardCtr,
            Vector3 cardXDir, Vector3 cardYDir, Vector3 cardZDir)
        {
            List <JSIAppPolyline3D> localPtCurve3Ds =
                new List <JSIAppPolyline3D>();

            foreach (JSIAppPolyline3D ptCurve3D in ptCurve3Ds)
            {
                JSIPolyline3D  polyline3D = (JSIPolyline3D)ptCurve3D.getGeom3D();
                List <Vector3> localPt3Ds = new List <Vector3>();
                foreach (Vector3 pt3D in polyline3D.getPts())
                {
                    Vector3 dif       = pt3D - cardCtr;
                    float   x         = Vector3.Dot(dif, cardXDir);
                    float   y         = Vector3.Dot(dif, cardYDir);
                    float   z         = Vector3.Dot(dif, cardZDir);
                    Vector3 localPt3D = new Vector3(x, y, z);
                    localPt3Ds.Add(localPt3D);
                }
                JSIAppPolyline3D localPtCurve3D = new JSIAppPolyline3D(
                    "PtCurve3D", localPt3Ds, 0.01f, Color.black);
                localPtCurve3Ds.Add(localPtCurve3D);
            }
            return(localPtCurve3Ds);
        }
コード例 #2
0
        private Vector3 calcCardCtr(List <JSIAppPolyline3D> ptCurve3Ds,
                                    Vector3 lowestPt3D, Vector3 cardXDir, Vector3 cardYDir,
                                    Vector3 cardZDir)
        {
            List <float> xs = new List <float>();
            List <float> ys = new List <float>();

            foreach (JSIAppPolyline3D ptCurve3D in ptCurve3Ds)
            {
                JSIPolyline3D polyline3D = (JSIPolyline3D)ptCurve3D.getGeom3D();
                foreach (Vector3 pt3D in polyline3D.getPts())
                {
                    float x = Vector3.Dot(pt3D - lowestPt3D, cardXDir);
                    float y = Vector3.Dot(pt3D - lowestPt3D, cardYDir);
                    xs.Add(x);
                    ys.Add(y);
                }
            }
            float   xMin       = Mathf.Min(xs.ToArray());
            float   xMax       = Mathf.Max(xs.ToArray());
            float   yMin       = Mathf.Min(ys.ToArray());
            float   yMax       = Mathf.Max(ys.ToArray());
            float   cardWidth  = xMax - xMin;
            float   cardHeight = yMax - yMin;
            Vector3 cardCtr    = lowestPt3D +
                                 0.5f * (xMin + xMax) * cardXDir +
                                 0.5f * (yMin + yMax) * cardYDir;

            return(cardCtr);
        }
コード例 #3
0
        protected override void refreshCollider()
        {
            JSIPolyline3D polyline = (JSIPolyline3D)this.mGeom;
            Vector3       ctr      = polyline.calcCentroid();
            float         r        = polyline.calcMaxDevFrom(ctr);

            SphereCollider sc =
                this.mGameObject.GetComponent <SphereCollider>();

            sc.center = ctr;
            sc.radius = r;
        }
コード例 #4
0
        protected override void refreshRenderer()
        {
            JSIPolyline3D polyline = (JSIPolyline3D)this.mGeom;
            LineRenderer  lr       = this.mGameObject.GetComponent <LineRenderer>();

            lr.useWorldSpace = false;
            lr.alignment     = LineAlignment.View;
            lr.positionCount = polyline.getPts().Count;
            lr.SetPositions(polyline.getPts().ToArray());
            lr.startWidth     = this.mWidth;
            lr.endWidth       = this.mWidth;
            lr.material       = new Material(Shader.Find("Unlit/Color"));
            lr.material.color = this.mColor;
        }
コード例 #5
0
        private float calcCardHeight(List <JSIAppPolyline3D> ptCurve3Ds)
        {
            float max = float.NegativeInfinity;
            float min = float.PositiveInfinity;

            foreach (JSIAppPolyline3D ptCurve3D in ptCurve3Ds)
            {
                JSIPolyline3D polyline3D = (JSIPolyline3D)ptCurve3D.getGeom3D();
                foreach (Vector3 pt3D in polyline3D.getPts())
                {
                    if (pt3D.y > max)
                    {
                        max = pt3D.y;
                    }
                    if (pt3D.y < min)
                    {
                        min = pt3D.y;
                    }
                }
            }
            float height = max - min;

            return(height);
        }
コード例 #6
0
        private float calcCardWidth(List <JSIAppPolyline3D> ptCurve3Ds)
        {
            float max = float.NegativeInfinity;
            float min = float.PositiveInfinity;

            foreach (JSIAppPolyline3D ptCurve3D in ptCurve3Ds)
            {
                JSIPolyline3D polyline3D = (JSIPolyline3D)ptCurve3D.getGeom3D();
                foreach (Vector3 pt3D in polyline3D.getPts())
                {
                    if (pt3D.x > max)
                    {
                        max = pt3D.x;
                    }
                    if (pt3D.x < min)
                    {
                        min = pt3D.x;
                    }
                }
            }
            float width = max - min;

            return(width);
        }
コード例 #7
0
        protected override bool defineCmd()
        {
            JSIApp app = (JSIApp)this.mApp;
            JSIPerspCameraPerson cp = app.getPerspCameraPerson();

            JSIEditStandingCardScenario scenario =
                JSIEditStandingCardScenario.getSingleton();
            JSIStandingCard standingCardToScale =
                scenario.getSelectedStandingCard();
            JSIAppRect3D   card        = standingCardToScale.getCard();
            JSIAppCircle3D stand       = standingCardToScale.getStand();
            JSIAppCircle3D scaleHandle = standingCardToScale.getScaleHandle();

            List <JSIAppPolyline3D> ptCurve3Ds =
                standingCardToScale.getPtCurve3Ds();

            // create the card plane.
            Plane cardPlane = new Plane(
                standingCardToScale.getGameObject().transform.forward,
                standingCardToScale.getGameObject().transform.position);

            // project the previous screen point to the plane.
            Ray   prevPtRay  = cp.getCamera().ScreenPointToRay(this.mPrevPt);
            float prevPtDist = float.NaN;

            cardPlane.Raycast(prevPtRay, out prevPtDist);
            Vector3 prevPtOnPlane = prevPtRay.GetPoint(prevPtDist);

            // project the previous screen point to the plane.
            Ray   curPtRay  = cp.getCamera().ScreenPointToRay(this.mCurPt);
            float curPtDist = float.NaN;

            cardPlane.Raycast(curPtRay, out curPtDist);
            Vector3 curPtOnPlane = curPtRay.GetPoint(curPtDist);

            // calculate the scale factor.
            float scaleFactor = curPtOnPlane.y / prevPtOnPlane.y;

            // resize the card.
            JSIRect3D rect          = (JSIRect3D)card.getGeom3D();
            float     newCardWidth  = scaleFactor * rect.getWidth();
            float     newCardHeight = scaleFactor * rect.getHeight();

            card.setSize(newCardWidth, newCardHeight);

            // change the position of the standing card and its card.
            Vector3 standingCardPos =
                standingCardToScale.getGameObject().transform.position;
            Vector3 newStandingCardPos =
                new Vector3(standingCardPos.x, standingCardPos.y * scaleFactor,
                            standingCardPos.z);

            standingCardToScale.getGameObject().transform.position =
                newStandingCardPos;

            // change the position of the stand
            Vector3 standLocalPos =
                stand.getGameObject().transform.localPosition;
            Vector3 newStandLocalPos = new Vector3(standLocalPos.x,
                                                   scaleFactor * standLocalPos.y, standLocalPos.z);

            stand.getGameObject().transform.localPosition =
                newStandLocalPos;
            stand.setRadius(newCardWidth / 2.0f);

            // change the position of the scale handle
            Vector3 scaleHandleLocalPos =
                scaleHandle.getGameObject().transform.localPosition;
            Vector3 newScaleHanleLocalPos = new Vector3(
                scaleHandleLocalPos.x, scaleFactor * scaleHandleLocalPos.y,
                scaleHandleLocalPos.z);

            scaleHandle.getGameObject().transform.localPosition =
                newScaleHanleLocalPos;

            // scale 3D points curves.
            if (ptCurve3Ds != null)
            {
                foreach (JSIAppPolyline3D ptCurve3D in ptCurve3Ds)
                {
                    JSIPolyline3D polyline =
                        (JSIPolyline3D)ptCurve3D.getGeom3D();
                    List <Vector3> scalePt3Ds = new List <Vector3>();
                    foreach (Vector3 pt3D in polyline.getPts())
                    {
                        Vector3 scaledPt3D = new Vector3(
                            pt3D.x * scaleFactor,
                            pt3D.y * scaleFactor,
                            pt3D.z);
                        scalePt3Ds.Add(scaledPt3D);
                    }
                    ptCurve3D.setPts(scalePt3Ds);
                }
            }

            return(true);
        }