コード例 #1
0
        Vector2f propagate_uv(Vector3f pos, Vector2f nbrUV, ref Frame3f fNbr, ref Frame3f fSeed)
        {
            Vector2f local_uv = compute_local_uv(ref fNbr, pos);

            Frame3f fSeedToLocal = fSeed;

            fSeedToLocal.AlignAxis(2, fNbr.Z);

            Vector3f vAlignedSeedX = fSeedToLocal.X;
            Vector3f vLocalX       = fNbr.X;

            float fCosTheta = vLocalX.Dot(vAlignedSeedX);

            // compute rotated min-dist vector for this particle
            float fTmp = 1 - fCosTheta * fCosTheta;

            if (fTmp < 0)
            {
                fTmp = 0;     // need to clamp so that sqrt works...
            }
            float    fSinTheta = (float)Math.Sqrt(fTmp);
            Vector3f vCross    = vLocalX.Cross(vAlignedSeedX);

            if (vCross.Dot(fNbr.Z) < 0)    // get the right sign...
            {
                fSinTheta = -fSinTheta;
            }


            Matrix2f mFrameRotate = new Matrix2f(fCosTheta, fSinTheta, -fSinTheta, fCosTheta);

            return(nbrUV + mFrameRotate * local_uv);
        }
コード例 #2
0
        public override MeshGenerator Generate()
        {
            int N = (PointIndicesCount == -1) ? PointIndices.Count() : PointIndicesCount;

            vertices  = new VectorArray3d(N * 3);
            uv        = null;
            normals   = new VectorArray3f(vertices.Count);
            triangles = new IndexArray3i(N);

            Matrix2f matRot = new Matrix2f(120 * MathUtil.Deg2Radf);
            Vector2f uva    = new Vector2f(0, Radius);
            Vector2f uvb    = matRot * uva;
            Vector2f uvc    = matRot * uvb;

            int vi = 0;
            int ti = 0;

            foreach (int pid in PointIndices)
            {
                Vector3d v = PointF(pid);
                Vector3d n = NormalF(pid);
                Frame3f  f = new Frame3f(v, n);
                triangles.Set(ti++, vi, vi + 1, vi + 2, Clockwise);
                vertices[vi++] = f.FromPlaneUV(uva, 2);
                vertices[vi++] = f.FromPlaneUV(uvb, 2);
                vertices[vi++] = f.FromPlaneUV(uvc, 2);
            }

            return(this);
        }
コード例 #3
0
ファイル: Matrix2f.cs プロジェクト: larsbrubaker/agg-sharp
        public void EigenDecomposition(ref Matrix2f rot, ref Matrix2f diag)
        {
            float sum = Math.Abs(m00) + Math.Abs(m11);

            if (Math.Abs(m01) + sum == sum)
            {
                // The matrix M is diagonal (within numerical round-off).
                rot.m00  = (float)1;
                rot.m01  = (float)0;
                rot.m10  = (float)0;
                rot.m11  = (float)1;
                diag.m00 = m00;
                diag.m01 = (float)0;
                diag.m10 = (float)0;
                diag.m11 = m11;
                return;
            }

            float trace   = m00 + m11;
            float diff    = m00 - m11;
            float discr   = (float)Math.Sqrt(diff * diff + ((float)4) * m01 * m01);
            float eigVal0 = 0.5f * (trace - discr);
            float eigVal1 = 0.5f * (trace + discr);

            diag.SetToDiagonal(eigVal0, eigVal1);

            float cs, sn;

            if (diff >= 0.0)
            {
                cs = m01;
                sn = eigVal0 - m00;
            }
            else
            {
                cs = eigVal0 - m11;
                sn = m01;
            }
            float invLength = 1.0f / (float)Math.Sqrt(cs * cs + sn * sn);

            cs *= invLength;
            sn *= invLength;

            rot.m00 = cs;
            rot.m01 = -sn;
            rot.m10 = sn;
            rot.m11 = cs;
        }