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


C# Ray.ClosestPoint方法代码示例

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


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

示例1: BackBufferControl_MouseMove

        public void BackBufferControl_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (didCopy && (W32.Control.ModifierKeys & W32.Keys.Shift) != W32.Keys.Shift)
                didCopy = false;
            int lastSelection = selection;
            dragging = false;
            if (!enabledDragging) return;
            if (e.Button != MB.Left || P.CurrNode == null)
            {
                selection = -1;
                return;
            }
            Matrix m = P.CurrNode.Matrix;
            Vector3 po = P.CurrNode.Position;
            Quaternion q = P.CurrNode.Rotation;
            if (P.CoordSystem == eECoordinateSystem.eECoordinateSystem_Independent)
            {
                m = Matrix.Translation(po);
                q = Quaternion.Identity;
            }
            Vector3 d = ManagedWorld.NodeLibrary.Camera.Unproject(e.X, e.Y, ManagedSettings.FarDepth - 1, P.BackBuffer);
            Ray r1 = new Ray(ManagedWorld.NodeLibrary.Camera.Position_ABS, Vector3.Normalize(d - ManagedWorld.NodeLibrary.Camera.Position_ABS));
            if (selection == -1)
            {
                Vector3 axisx = Vector3.Transform(Vector3.UnitX * scale, q).ToVec3();
                Vector3 axisy = Vector3.Transform(Vector3.UnitY * scale, q).ToVec3();
                Vector3 axisz = Vector3.Transform(Vector3.UnitZ * scale, q).ToVec3();
                Vector2 o = ManagedWorld.NodeLibrary.Camera.Project(Vector3.Transform(Vector3.Zero, m).ToVec3(), P.BackBuffer);
                Vector2 p1 = ManagedWorld.NodeLibrary.Camera.Project(axisx + po, P.BackBuffer);
                Vector2 p2 = ManagedWorld.NodeLibrary.Camera.Project(axisy + po, P.BackBuffer);
                Vector2 p3 = ManagedWorld.NodeLibrary.Camera.Project(axisz + po, P.BackBuffer);
                Vector2 p2_xz = ManagedWorld.NodeLibrary.Camera.Project(po + axisx * s + axisz * s, P.BackBuffer);
                Vector2 p2_yz = ManagedWorld.NodeLibrary.Camera.Project(po + axisy * s + axisz * s, P.BackBuffer);
                Vector2 p2_yx = ManagedWorld.NodeLibrary.Camera.Project(po + axisx * s + axisy * s, P.BackBuffer);

                bool x = isNear(o, p1, e.X, e.Y);
                bool y = isNear(o, p2, e.X, e.Y);
                bool z = isNear(o, p3, e.X, e.Y);
                bool[] bb = CheckAreas(Vector3.Transform(Vector3.Zero, m).ToVec3(), axisx, axisy, axisz, new Vector3(e.X, e.Y, 0), r1);
                if (bb[0] || bb[1] || bb[2])
                    x = y = z = false;
                int SAT = Convert.ToInt32(x) + Convert.ToInt32(y) + Convert.ToInt32(z) + Convert.ToInt32(bb[0]) + Convert.ToInt32(bb[1]) + Convert.ToInt32(bb[2]);
                if(SAT == 0 || SAT > 1)
                    return;
                if (x) selection = 0; if (y) selection = 1; if (z) selection = 2; if (bb[0]) selection = 3; if (bb[1]) selection = 4; if (bb[2]) selection = 5;
            }
            if (selection < 3)
            {
                Vector3 v = new Vector3();
                if (selection == 0) v = Vector3.UnitX; if (selection == 1) v = Vector3.UnitY; if (selection == 2) v = Vector3.UnitZ;
                v = Vector3.Transform(v, q).ToVec3();
                Ray r2 = new Ray(po, v);
                Vector3? hit = r2.ClosestPoint(r1);
                float s0 = (hit.Value - P.CurrNode.Position).Length();
                float fk = calcDist(P.CurrNode.Position, v);
                if (!hit.HasValue || s0 > scale)
                {
                    //selection = -1;
                    return;
                }
                if (lastSelection == -1 && s0 > fk)
                {
                    dragging = true;
                    return;
                }
                float t = (hit.Value[selection] - r2.Position[selection]) / r2.Direction[selection];
                if ((W32.Control.ModifierKeys & W32.Keys.Shift) == W32.Keys.Shift && !didCopy)
                {
                    didCopy = true;
                    P.CurrNode = (ILrentObject)P.CurrNode.Clone(P.GetCopyFile(P.CurrNode.File), P.Device);
                }
                if (s0 < fk)
                    P.CurrNode.Position = hit.Value;
                else P.CurrNode.Position += r2.Direction * fk * (float)Math.Sign(t);
                dragging = true;
            }
            else
            {
                Vector3 n = new Vector3();
                if (selection == 3) n = Vector3.UnitY; if (selection == 4) n = Vector3.UnitX; if (selection == 5) n = Vector3.UnitZ;
                n = Vector3.Transform(n, q).ToVec3();
                Plane p = new Plane(po, n);
                float? fq = r1.Intersects(p);
                if (!fq.HasValue)
                    return;
                Vector3 hit = r1.Position + r1.Direction * fq.Value;
                P.CurrNode.Position = hit;
                dragging = true;
            }
        }
开发者ID:hhergeth,项目名称:RisenEditor,代码行数:90,代码来源:InformationDrawer.cs


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