// constructor
        public JSIStandingCard(string name, float width, float height,
                               Vector3 pos, Quaternion rot,
                               List <JSIAppPolyline3D> ptCurve3Ds) : base(name)
        {
            this.mGameObject.transform.localPosition = pos;
            this.mGameObject.transform.localRotation = rot;

            // create the card
            this.mCard = new JSIAppRect3D("Card", width, height,
                                          JSIStandingCard.COLOR_CARD);

            // create the stand
            Vector3    standLocalPos = 0.5f * height * Vector3.down;
            Quaternion standLocalRot = Quaternion.LookRotation(Vector3.up);

            this.mStand = new JSIAppCircle3D("Stand", 0.5f * width,
                                             JSIStandingCard.COLOR_UI_DEFAULT);
            this.mStand.getGameObject().transform.localPosition = standLocalPos;
            this.mStand.getGameObject().transform.localRotation = standLocalRot;

            // create the scale handle
            Vector3 scaleHandleLocalPos = 0.5f * height * Vector3.up;

            this.mScaleHandle = new JSIAppCircle3D("ScaleHandle",
                                                   JSIStandingCard.SCALE_HANDLE_RADIUS,
                                                   JSIStandingCard.COLOR_UI_DEFAULT);
            this.mScaleHandle.getGameObject().transform.localPosition =
                scaleHandleLocalPos;

            //add the card, stand and scale handle
            this.addChild(this.mCard);
            this.addChild(this.mStand);
            this.addChild(this.mScaleHandle);
            this.mStand.getGameObject().SetActive(false);

            // add 3D pt curves to the card
            if (ptCurve3Ds == null)
            {
                return;
            }
            else
            {
                this.mPtCurve3Ds = ptCurve3Ds;
                foreach (JSIAppPolyline3D ptCurve3D in this.mPtCurve3Ds)
                {
                    this.mCard.addChild(ptCurve3D);
                }
            }
        }
        public JSIStandingCard selectStandingCardByScaleHandle()
        {
            JSIApp app = (JSIApp)this.mApp;
            List <JSIStandingCard> hitStandingCards =
                new List <JSIStandingCard>();

            foreach (JSIStandingCard standingCard in
                     app.getStandingCardMgr().getStandingCards())
            {
                if (app.getCursor().hits(standingCard.getScaleHandle()))
                {
                    hitStandingCards.Add(standingCard);
                }
            }

            if (hitStandingCards.Count == 0)
            {
                return(null);
            }

            // find and return the smallest standing card among ths hit ones.
            float           minWidth             = Mathf.Infinity;
            JSIStandingCard smallestStandingCard = null;

            foreach (JSIStandingCard standingCard in
                     hitStandingCards)
            {
                JSIAppRect3D card = standingCard.getCard();
                JSIRect3D    rect = (JSIRect3D)card.getGeom3D();
                if (rect.getWidth() < minWidth)
                {
                    smallestStandingCard = standingCard;
                    minWidth             = rect.getWidth();
                }
            }
            return(smallestStandingCard);
        }
示例#3
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);
        }