当前位置: 首页>>代码示例>>C#>>正文


C# Vector4.ToVector3方法代码示例

本文整理汇总了C#中Vector4.ToVector3方法的典型用法代码示例。如果您正苦于以下问题:C# Vector4.ToVector3方法的具体用法?C# Vector4.ToVector3怎么用?C# Vector4.ToVector3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector4的用法示例。


在下文中一共展示了Vector4.ToVector3方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ComputePrincipleComponent

        public static Vector3 ComputePrincipleComponent(Sym3x3 matrix)
        {
            Vector4 row0 = new Vector4(matrix[0], matrix[1], matrix[2], 0.0f);
            Vector4 row1 = new Vector4(matrix[1], matrix[3], matrix[4], 0.0f);
            Vector4 row2 = new Vector4(matrix[2], matrix[4], matrix[5], 0.0f);
            Vector4 v = new Vector4(1.0f);
            for (int i = 0; i < 8; ++i)
            {
                // matrix multiply
                Vector4 w = row0 * v.SplatX();
                w = Helpers.MultiplyAdd(row1, v.SplatY(), w);
                w = Helpers.MultiplyAdd(row2, v.SplatZ(), w);

                // get max component from xyz in all channels
                Vector4 a = Vector4.Max(w.SplatX(), Vector4.Max(w.SplatY(), w.SplatZ()));

                // divide through and advance
                v = w * Helpers.Reciprocal(a);
            }

            return v.ToVector3();
        }
开发者ID:Mazooma-Interactive-Games,项目名称:LibSquishNet,代码行数:22,代码来源:Maths.cs

示例2: HitTest

        public override bool HitTest(Ray rayWS, ref List<HitTestResult> hits)
        {
            LineGeometry3D lineGeometry3D;
            Viewport3DX viewport;

            if (this.Visibility == Visibility.Collapsed ||
                this.IsHitTestVisible == false ||
                (viewport = FindVisualAncestor<Viewport3DX>(this.renderHost as DependencyObject)) == null ||
                (lineGeometry3D = this.Geometry as LineGeometry3D) == null)
            {
                return false;
            }

            // revert unprojection; probably better: overloaded HitTest() for LineGeometryModel3D?
            var svpm = viewport.GetScreenViewProjectionMatrix();
            var smvpm = this.modelMatrix * svpm;
            var clickPoint4 = new Vector4(rayWS.Position + rayWS.Direction, 1);
            Vector4.Transform(ref clickPoint4, ref svpm, out clickPoint4);
            var clickPoint = clickPoint4.ToVector3();

            var result = new HitTestResult { IsValid = false, Distance = double.MaxValue };
            var maxDist = this.HitTestThickness;
            var lastDist = double.MaxValue;
            var index = 0;

            foreach (var line in lineGeometry3D.Lines)
            {
                var p0 = Vector3.TransformCoordinate(line.P0, smvpm);
                var p1 = Vector3.TransformCoordinate(line.P1, smvpm);
                Vector3 hitPoint;
                float t;

                var dist = LineBuilder.GetPointToLineDistance2D(ref clickPoint, ref p0, ref p1, out hitPoint, out t);
                if (dist < lastDist && dist <= maxDist)
                {
                    lastDist = dist;
                    Vector4 res;
                    var lp0 = line.P0;
                    Vector3.Transform(ref lp0, ref this.modelMatrix, out res);
                    lp0 = res.ToVector3();

                    var lp1 = line.P1;
                    Vector3.Transform(ref lp1, ref this.modelMatrix, out res);
                    lp1 = res.ToVector3();

                    var lv = lp1 - lp0;
                    var hitPointWS = lp0 + lv * t;
                    result.Distance = (rayWS.Position - hitPointWS).Length();
                    result.PointHit = hitPointWS.ToPoint3D();
                    result.ModelHit = this;
                    result.IsValid = true;
                    result.Tag = index; // ToDo: LineHitTag with additional info
                }

                index++;
            }

            if (result.IsValid)
            {
                hits.Add(result);
            }

            return result.IsValid;
        }
开发者ID:johnsonlu,项目名称:helix-toolkit,代码行数:64,代码来源:LineGeometryModel3D.cs

示例3: HitTest

        /// <summary>
        /// Checks if the ray hits the geometry of the model.
        /// If there a more than one hit, result returns the hit which is nearest to the ray origin.
        /// </summary>
        /// <param name="rayWS">Hitring ray from the camera.</param>
        /// <param name="result">results of the hit.</param>
        /// <returns>True if the ray hits one or more times.</returns>
        public override bool HitTest(Ray rayWS, ref List<HitTestResult> hits)
        {
            PointGeometry3D pointGeometry3D;
            Viewport3DX viewport;

            if (this.Visibility == Visibility.Collapsed ||
                this.IsHitTestVisible == false ||
                (viewport = FindVisualAncestor<Viewport3DX>(this.renderHost as DependencyObject)) == null ||
                (pointGeometry3D = this.Geometry as PointGeometry3D) == null)
            {
                return false;
            }

            var svpm = viewport.GetScreenViewProjectionMatrix();
            var smvpm = this.modelMatrix * svpm;

            var clickPoint4 = new Vector4(rayWS.Position + rayWS.Direction, 1);
            var pos4 = new Vector4(rayWS.Position, 1);
            var dir3 = new Vector3();
            Vector4.Transform(ref clickPoint4, ref svpm, out clickPoint4);
            Vector4.Transform(ref pos4, ref svpm, out pos4);
            Vector3.TransformNormal(ref rayWS.Direction, ref svpm, out dir3);
            dir3.Normalize();

            var clickPoint = clickPoint4.ToVector3();

            var result = new HitTestResult { IsValid = false, Distance = double.MaxValue };
            var maxDist = this.HitTestThickness;
            var lastDist = double.MaxValue;
            var index = 0;

            foreach (var point in pointGeometry3D.Points)
            {
                var p0 = Vector3.TransformCoordinate(point.P0, smvpm);
                var pv = p0 - clickPoint;
                var dist = pv.Length();
                if (dist < lastDist && dist <= maxDist)
                {
                    lastDist = dist;
                    Vector4 res;
                    var lp0 = point.P0;
                    Vector3.Transform(ref lp0, ref this.modelMatrix, out res);
                    var pvv = res.ToVector3();
                    var dst = DistanceRayToPoint(rayWS, pvv);
                    result.Distance = dst;
                    result.PointHit = pvv.ToPoint3D();
                    result.ModelHit = this;
                    result.IsValid = true;
                    result.Tag = index;
                }

                index++;
            }

            if (result.IsValid)
            {
                hits.Add(result);
            }

            return result.IsValid;
        }
开发者ID:ando23,项目名称:helix-toolkit,代码行数:68,代码来源:PointGeometryModel3D.cs

示例4: Compress3


//.........这里部分代码省略.........
            {
                // first cluster [0,i) is at the start
                Vector4 part0 = new Vector4(0.0f);
                for (int i = 0; i < count; ++i)
                {
                    // second cluster [i,j) is half along
                    Vector4 part1 = (i == 0) ? m_points_weights[0] : new Vector4(0.0f);
                    int jmin = (i == 0) ? 1 : i;
                    for (int j = jmin; ; )
                    {
                        // last cluster [j,count) is at the end
                        Vector4 part2 = m_xsum_wsum - part1 - part0;

                        // compute least squares terms directly
                        Vector4 alphax_sum = Helpers.MultiplyAdd(part1, half_half2, part0);
                        Vector4 alpha2_sum = alphax_sum.SplatW();

                        Vector4 betax_sum = Helpers.MultiplyAdd(part1, half_half2, part2);
                        Vector4 beta2_sum = betax_sum.SplatW();

                        Vector4 alphabeta_sum = (part1 * half_half2).SplatW();

                        // compute the least-squares optimal points
                        Vector4 factor = Helpers.Reciprocal(Helpers.NegativeMultiplySubtract(alphabeta_sum, alphabeta_sum, alpha2_sum * beta2_sum));
                        Vector4 a = Helpers.NegativeMultiplySubtract(betax_sum, alphabeta_sum, alphax_sum * beta2_sum) * factor;
                        Vector4 b = Helpers.NegativeMultiplySubtract(alphax_sum, alphabeta_sum, betax_sum * alpha2_sum) * factor;

                        // clamp to the grid
                        a = Vector4.Min(one, Vector4.Max(zero, a));
                        b = Vector4.Min(one, Vector4.Max(zero, b));
                        a = Helpers.Truncate(Helpers.MultiplyAdd(grid, a, half)) * gridrcp;
                        b = Helpers.Truncate(Helpers.MultiplyAdd(grid, b, half)) * gridrcp;

                        // compute the error (we skip the constant xxsum)
                        Vector4 e1 = Helpers.MultiplyAdd(a * a, alpha2_sum, b * b * beta2_sum);
                        Vector4 e2 = Helpers.NegativeMultiplySubtract(a, alphax_sum, a * b * alphabeta_sum);
                        Vector4 e3 = Helpers.NegativeMultiplySubtract(b, betax_sum, e2);
                        Vector4 e4 = Helpers.MultiplyAdd( two, e3, e1);

                        // apply the metric to the error term
                        Vector4 e5 = e4 * m_metric;
                        Vector4 error = e5.SplatX() + e5.SplatY() + e5.SplatZ();

                        // keep the solution if it wins
                        if (Helpers.CompareAnyLessThan(error, besterror))
                        {
                            beststart = a;
                            bestend = b;
                            besti = i;
                            bestj = j;
                            besterror = error;
                            bestiteration = iterationIndex;
                        }

                        // advance
                        if (j == count)
                            break;
                        part1 += m_points_weights[j];
                        ++j;
                    }

                    // advance
                    part0 += m_points_weights[i];
                }

                // stop if we didn't improve in this iteration
                if (bestiteration != iterationIndex)
                    break;

                // advance if possible
                ++iterationIndex;
                if (iterationIndex == m_iterationCount)
                    break;

                // stop if a new iteration is an ordering that has already been tried
                Vector3 axis = (bestend - beststart).ToVector3();
                if (!ConstructOrdering(axis, iterationIndex))
                    break;
            }

            // save the block if necessary
            if (Helpers.CompareAnyLessThan(besterror, m_besterror))
            {
                byte[] unordered = new byte[16];
                for (int m = 0; m < besti; ++m)
                    unordered[m_order[(16 * bestiteration) + m]] = 0;
                for (int m = besti; m < bestj; ++m)
                    unordered[m_order[(16 * bestiteration) + m]] = 2;
                for (int m = bestj; m < count; ++m)
                    unordered[m_order[(16 * bestiteration) + m]] = 1;

                m_colours.RemapIndices(unordered, bestindices);

                // save the block
                ColourBlock.WriteColourBlock3(beststart.ToVector3(), bestend.ToVector3(), bestindices, ref block, offset);

                // save the error
                m_besterror = besterror;
            }
        }
开发者ID:Mazooma-Interactive-Games,项目名称:LibSquishNet,代码行数:101,代码来源:ClusterFit.cs


注:本文中的Vector4.ToVector3方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。