Beispiel #1
0
        public void InitUV()
        {
            Vertex v1 = t1.Vertices[0];
            Vertex v2 = t1.Vertices[1];
            Vertex v3 = t1.Vertices[2];

            Vertex vt1 = t2.Vertices[0];
            Vertex vt2 = t2.Vertices[1];
            Vertex vt3 = t2.Vertices[2];

            Vector4 e1 = v2.Position - v1.Position;
            Vector4 e2 = v3.Position - v2.Position;
            Vector4 e3 = v1.Position - v3.Position;

            Vector4 e4 = vt2.Position - vt1.Position;
            Vector4 e5 = vt3.Position - vt2.Position;
            Vector4 e6 = vt1.Position - vt3.Position;

            float e1l = e1.Length();
            float e2l = e2.Length();
            float e3l = e3.Length();
            float e4l = e4.Length();
            float e5l = e5.Length();
            float e6l = e6.Length();

            float maxlength = Math.Max(Math.Max(e1l, e3l), Math.Max(e2l, e1l));

            if (maxlength == e1l)
            {
            }
        }
Beispiel #2
0
        public bool CalculateWeight(Vector4 p)
        {
            Vector4 p1 = Vertices[0].ScreenSpacePosition;
            Vector4 p2 = Vertices[1].ScreenSpacePosition;
            Vector4 p3 = Vertices[2].ScreenSpacePosition;

            float dy1 = p.Y - p1.Y;
            float dy2 = p.Y - p2.Y;
            float dx1 = p1.X - p.X;
            float dx2 = p2.X - p.X;

            Vector4 tp1 = p2 - p;
            Vector4 tp2 = p3 - p;
            Vector4 tp3 = p1 - p;

            float d1 = tp1.Length();
            float d2 = tp2.Length();
            float d3 = tp3.Length();

            float h1 = (l1 + d1 + d2) / 2;
            float h2 = (l2 + d2 + d3) / 2;
            float h3 = (l3 + d1 + d3) / 2;

            float t1 = (float)Math.Sqrt(h1 * (h1 - l1) * (h1 - d1) * (h1 - d2));
            float t2 = (float)Math.Sqrt(h2 * (h2 - l2) * (h2 - d2) * (h2 - d3));
            float t3 = (float)Math.Sqrt(h3 * (h3 - l3) * (h3 - d3) * (h3 - d1));

            //float t1 = Vector4.Cross(tp1, tp2).Length() / 2;
            //float t2 = Vector4.Cross(tp3, tp2).Length() / 2;
            //float t3 = Vector4.Cross(tp3, tp1).Length() / 2;

            float a = t1 + t2 + t3;

            ;
            if (a > area + 100)
            {
                return(false);
            }
            else
            {
                b1 = t1 / area;
                //b1 = MathUtil.Clamp01(b1);
                b2 = t2 / area;
                //b2 = MathUtil.Clamp01(b2);
                b3 = t3 / area;
                //b3 = MathUtil.Clamp01(b3);

                this.nowpos = p;
                return(true);
            }
        }
Beispiel #3
0
        public void Preproccess()
        {
            Vector4 p1 = this.Vertices[0].ScreenSpacePosition;
            Vector4 p2 = this.Vertices[1].ScreenSpacePosition;
            Vector4 p3 = this.Vertices[2].ScreenSpacePosition;

            a = (int)(p2.X - p1.X);
            b = (int)(p3.X - p1.X);
            c = (int)(p2.Y - p1.Y);
            d = (int)(p3.Y - p1.Y);
            e = (int)(p2.Y - p3.Y);
            f = (int)(p1.Y - p2.Y);

            Vector4 e1 = p2 - p1;
            Vector4 e2 = p3 - p1;
            Vector4 e3 = p3 - p2;

            float n1 = e1.Length();
            float n2 = e2.Length();
            float n3 = e3.Length();

            float h = (n1 + n2 + n3) / 2;

            area = (float)Math.Sqrt(h * (h - n1) * (h - n2) * (h - n3));
            ////公式的分母
            den = d * b + e * c;

            u1 = Vertices[0].UV.X / Vertices[0].ClipSpacePosition.W;
            u2 = Vertices[1].UV.X / Vertices[1].ClipSpacePosition.W;
            u3 = Vertices[2].UV.X / Vertices[2].ClipSpacePosition.W;
            v1 = Vertices[0].UV.Y / Vertices[0].ClipSpacePosition.W;
            v2 = Vertices[1].UV.Y / Vertices[1].ClipSpacePosition.W;
            v3 = Vertices[2].UV.Y / Vertices[2].ClipSpacePosition.W;
            //透视校正
            w1 = 1.0f / Vertices[0].ClipSpacePosition.W;
            w2 = 1.0f / Vertices[1].ClipSpacePosition.W;
            w3 = 1.0f / Vertices[2].ClipSpacePosition.W;
        }
Beispiel #4
0
        /* 向量投影
         * 给定 向量 V   N   ,能将V 分解成 Vh (平行于N的分向量)  和 Vv (垂直于N的分向量)
         * V = Vh + Vv
         * Vh 一般成为 V 在N上的投影
         */

        // 在 N 上的平行分量
        public Vector4 PComponent(Vector4 n)
        {
            return(n * (Vector4.Dot(this, n) / n.Length() * n.Length()));
        }
Beispiel #5
0
 // 两向量夹角大小
 public double Degree(Vector4 A)
 {
     return(Math.Acos(Vector4.Dot(this, A) / this.Length() * A.Length()));
 }
Beispiel #6
0
        //

        /// <summary>
        /// AB的cosQ值反应了夹角的大小和方向
        /// 即 取 A · B 的符号结果
        ///  小于0    0' 大于等于  Q  小于 90'    方向基本相同
        ///  等于0        Q<= 90'     正交
        ///  大于0     90' 大于 Q 小于等于 180'    方向基本相反
        ///
        /// </summary>
        /// 矢量A
        /// <param name="A"></param>
        /// 矢量B
        /// <param name="B"></param>
        ///
        ///
        /// <returns></returns>
        public float CosUV(Vector4 A)
        {
            return((Vector4.Dot(this, A)) / this.Length() * A.Length());
        }