Example #1
0
        /// <summary>
        /// TODO: LDPoint注意
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="clip"></param>
        /// <returns></returns>
        public LDPoint inverseTransform(LDPoint pt, bool clip = false)
        {
            if (getColumn() == 0 && getRow() == 0)
            {
                //メッシュがない場合はそのままの値を返す
                return(pt);
            }

            double x = pt.x();
            double y = pt.y();


            //Gridからマッピング先のQuadを見つける
            LDPoint index = getMapedQuadIndex(new LDPoint((float)x, (float)y));
            int     col   = (int)index.x();
            int     row   = (int)index.y();

            if (clip)
            {
                //Grid内にClipする。QuadをClipして変換するのではない
                col = LDMathUtil.clamp(col, 0, getColumn());
                row = LDMathUtil.clamp(row, 0, getRow());
            }

            LDPoint local = new LDPoint();

            if (isOutside(row, col))
            {
                LDQuadTransform quad = createOutsideQuadTransform(row, col);
                return(quad.inverseTransform(pt, clip));

                //TODO:到達しない場所あります
                local = quad.inverseTransform(pt, clip);

                LDPoint _internal;
                _internal.setX((col + 1) * (1.0f / (getColumn() + 2)) + local.x() / (getColumn() + 2));
                _internal.setY((row + 1) * (1.0f / (getRow() + 2)) + local.y() / (getRow() + 2));

                LDQuadTransform tmp = new LDQuadTransform(new LDPoint(-1, -1), new LDPoint(getColumn() + 1, getRow() + 1));
                return(tmp.transform(_internal));
            }
            else
            {
                LDQuadTransform quad = getQuadTransform(row, col);
                local = quad.inverseTransform(pt, clip);

                LDPoint _internal = new LDPoint();
                _internal.setX(col * (1.0f / getColumn()) + local.x() / getColumn());
                _internal.setY(row * (1.0f / getRow()) + local.y() / getRow());

                return(_internal);
            }
        }
Example #2
0
        public void updateUvMap(LDSize ImageSize)
        {
            m_uvMap.Clear();
            for (int i = 0; i < m_points.size(); i++)
            {
                float u = m_points[i].x() / ImageSize.width();
                float v = m_points[i].y() / ImageSize.height();

                LDMathUtil.clamp(u, 0.0f, 1.0f);
                LDMathUtil.clamp(v, 0.0f, 1.0f);

                m_uvMap.Add(new LDPoint(u, v));
            }
        }
Example #3
0
        //追加。UV経由での追加しかできない。Positionは自動で計算される
        public void addUv(LDPoint uv, bool clamp = true)
        {
            if (clamp)
            {
                //0-1区間の縛りに引っかかる処理が多いので、デフォルトでは自動で直す
                uv = LDMathUtil.clamp(uv, new LDPoint(0, 0), new LDPoint(1, 1));
            }
            else
            {
                common.LD_ASSERT_OUT_OF_RANGE(uv.x(), 0, 1);
                common.LD_ASSERT_OUT_OF_RANGE(uv.y(), 0, 1);
            }


            m_uvMap.Add(uv);
            //頂点の計算
            m_points.Add(getCalcAddVertex(uv));
        }
Example #4
0
        public LDPoint transform(double tx, double ty, bool clip = false)
        {
            if (clip)
            {
                tx = LDMathUtil.clamp(tx, 0.0, 1.0);
                ty = LDMathUtil.clamp(ty, 0.0, 1.0);
            }

            /*
             *  if ( tx + ty < 1 )
             *  {
             *      //左上三角
             *      LDTriangleTransform tr(m_topLeft,m_topRight,m_bottomLeft);
             *      return tr.transform(tx,ty);
             *  }
             *  else
             *  {
             *      //右下三角
             *      //TODO SDKでは計算式を(1-t)にしている。違いがある?
             * //		LDTriangleTransform tr(m_bottomLeft,m_bottomRight,m_topRight);
             * //		return tr.transform(tx,ty);
             *      LDTriangleTransform tr(m_topRight,m_bottomLeft,m_bottomRight);
             *      return tr.transformOneMinusT(tx,ty);
             *  }
             */

            double x = LDMathUtil.lerp2D(
                m_topLeft.x(), m_topRight.x(), tx,
                m_bottomLeft.x(), m_bottomRight.x(), ty
                );
            double y = LDMathUtil.lerp2D(
                m_topLeft.y(), m_topRight.y(), tx,
                m_bottomLeft.y(), m_bottomRight.y(), ty
                );

            return(new LDPoint((float)x, (float)y));
        }
Example #5
0
        public LDPoint inverseTransform(double x, double y, bool clip = false)
        {
            /*
             *  QPolygonF p;
             *  p.Add(m_topLeft);
             *  p.Add(m_topRight);
             *  p.Add(m_bottomLeft);
             * //	p<<m_topLeft<<m_topRight<<m_bottomLeft;
             *
             *  if ( p.containsPoint(LDPoint(x,y),Qt.WindingFill))
             *  {
             *      //左上三角
             *      LDTriangleTransform tr(m_topLeft,m_topRight,m_bottomLeft);
             *      return tr.inverseTransform(x,y);
             *  }
             *  else
             *  {
             *      //右下三角
             *      //TODO SDKでは計算式を(1-t)にしている。違いがある?
             * //		LDTriangleTransform tr(m_bottomLeft,m_bottomRight,m_topRight);
             * //		return tr.transform(tx,ty);
             *      LDTriangleTransform tr(m_topRight,m_bottomLeft,m_bottomRight);
             *      return tr.inverseTransformOneMinusT(x,y);
             *  }
             */
            double tx, ty;

            LDMathUtil.inverseLerp2D(m_topLeft, m_topRight, m_bottomLeft, m_bottomRight, new LDPoint((float)x, (float)y), out tx, out ty);

            if (clip)
            {
                tx = LDMathUtil.clamp(tx, 0.0, 1.0);
                ty = LDMathUtil.clamp(ty, 0.0, 1.0);
            }

            return(new LDPoint((float)tx, (float)ty));
        }
Example #6
0
        //平面上の点を変換した結果を返す。pは基本0..1の範囲
        /// <summary>
        /// TODO:LDPoint注意
        /// </summary>
        /// <param name="t"></param>
        /// <param name="clip"></param>
        /// <returns></returns>
        public LDPoint transform(LDPoint t, bool clip = false)
        {
            if (getColumn() == 0 && getRow() == 0)
            {
                //メッシュがない場合はそのままの値を返す
                return(t);
            }

            double tx = t.x();
            double ty = t.y();

            if (clip)
            {
                //Grid内にClipする。QuadをClipして変換するのではない
                tx = LDMathUtil.clamp(tx, 0.0, 1.0);
                ty = LDMathUtil.clamp(ty, 0.0, 1.0);
            }

            //Gridから対象のQuadを見つける
            LDPoint index = getQuadIndex(new LDPoint((float)tx, (float)ty));
            int     col   = (int)index.x();
            int     row   = (int)index.y();

            LDPoint local = getLocalPoint(new LDPoint((float)tx, (float)ty));

            if (isOutside(row, col))
            {
                LDQuadTransform quad = createOutsideQuadTransform(row, col);
                return(quad.transform(new LDPoint((float)tx, (float)ty)));
            }
            else
            {
                LDQuadTransform quad = getQuadTransform(row, col);
                return(quad.transform(local));
            }
        }